diff --git a/package-lock.json b/package-lock.json index e4198e049..f2d00d40d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,7 @@ "@types/url-parse": "^1.4.11", "autoprefixer": "^10.4.21", "babel-loader": "^10.0.0", + "com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot", "com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal", "cordova-android": "^14.0.1", "cordova-clipboard": "^1.3.0", @@ -4334,6 +4335,10 @@ "dev": true, "license": "MIT" }, + "node_modules/com.foxdebug.acode.rk.exec.proot": { + "resolved": "src/plugins/proot", + "link": true + }, "node_modules/com.foxdebug.acode.rk.exec.terminal": { "resolved": "src/plugins/terminal", "link": true @@ -11202,7 +11207,7 @@ "src/plugins/proot": { "name": "com.foxdebug.acode.rk.exec.proot", "version": "1.0.0", - "extraneous": true, + "dev": true, "license": "MIT" }, "src/plugins/sdcard": { diff --git a/package.json b/package.json index d6ef79942..2ab7735fb 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "cordova-plugin-browser": {}, "cordova-plugin-sftp": {}, "cordova-plugin-system": {}, - "com.foxdebug.acode.rk.exec.terminal": {} + "com.foxdebug.acode.rk.exec.terminal": {}, + "com.foxdebug.acode.rk.exec.proot": {} }, "platforms": [ "android" @@ -62,6 +63,7 @@ "@types/url-parse": "^1.4.11", "autoprefixer": "^10.4.21", "babel-loader": "^10.0.0", + "com.foxdebug.acode.rk.exec.proot": "file:src/plugins/proot", "com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal", "cordova-android": "^14.0.1", "cordova-clipboard": "^1.3.0", diff --git a/src/components/terminal/terminalManager.js b/src/components/terminal/terminalManager.js index 3c117928f..110c6c470 100644 --- a/src/components/terminal/terminalManager.js +++ b/src/components/terminal/terminalManager.js @@ -17,12 +17,15 @@ class TerminalManager { this.terminalCounter = 0; } - getPersistedSessions() { + async getPersistedSessions() { try { const stored = helpers.parseJSON( localStorage.getItem(TERMINAL_SESSION_STORAGE_KEY), ); if (!Array.isArray(stored)) return []; + if (!(await Terminal.isAxsRunning())) { + return []; + } return stored .map((entry) => { if (!entry) return null; @@ -56,11 +59,11 @@ class TerminalManager { } } - persistTerminalSession(pid, name) { + async persistTerminalSession(pid, name) { if (!pid) return; const pidStr = String(pid); - const sessions = this.getPersistedSessions(); + const sessions = await this.getPersistedSessions(); const existingIndex = sessions.findIndex( (session) => session.pid === pidStr, ); @@ -81,11 +84,11 @@ class TerminalManager { this.savePersistedSessions(sessions); } - removePersistedSession(pid) { + async removePersistedSession(pid) { if (!pid) return; const pidStr = String(pid); - const sessions = this.getPersistedSessions(); + const sessions = await this.getPersistedSessions(); const nextSessions = sessions.filter((session) => session.pid !== pidStr); if (nextSessions.length !== sessions.length) { @@ -94,7 +97,7 @@ class TerminalManager { } async restorePersistedSessions() { - const sessions = this.getPersistedSessions(); + const sessions = await this.getPersistedSessions(); if (!sessions.length) return; const manager = window.editorManager; @@ -183,7 +186,7 @@ class TerminalManager { }); // Wait for tab creation and setup - const terminalInstance = await new Promise((resolve, reject) => { + return await new Promise((resolve, reject) => { setTimeout(async () => { try { // Mount terminal component @@ -220,7 +223,10 @@ class TerminalManager { this.terminals.set(uniqueId, instance); if (terminalComponent.serverMode && terminalComponent.pid) { - this.persistTerminalSession(terminalComponent.pid, terminalName); + await this.persistTerminalSession( + terminalComponent.pid, + terminalName, + ); } resolve(instance); } catch (error) { @@ -229,8 +235,6 @@ class TerminalManager { } }, 100); }); - - return terminalInstance; } catch (error) { console.error("Failed to create terminal:", error); throw error; @@ -334,7 +338,7 @@ class TerminalManager { }); // Wait for tab creation and setup - const terminalInstance = await new Promise((resolve, reject) => { + return await new Promise((resolve, reject) => { setTimeout(async () => { try { // Mount terminal component @@ -374,8 +378,6 @@ class TerminalManager { } }, 100); }); - - return terminalInstance; } /** @@ -384,7 +386,7 @@ class TerminalManager { * @param {TerminalComponent} terminalComponent - Terminal component * @param {string} terminalId - Terminal ID */ - setupTerminalHandlers(terminalFile, terminalComponent, terminalId) { + async setupTerminalHandlers(terminalFile, terminalComponent, terminalId) { // Handle tab focus/blur terminalFile.onfocus = () => { // Guarded fit on focus: only fit if cols/rows would change, then focus @@ -486,14 +488,17 @@ class TerminalManager { this.closeTerminal(terminalId); }; - terminalComponent.onTitleChange = (title) => { + terminalComponent.onTitleChange = async (title) => { if (title) { // Format terminal title as "Terminal ! - title" const formattedTitle = `Terminal ${this.terminalCounter} - ${title}`; terminalFile.filename = formattedTitle; if (terminalComponent.serverMode && terminalComponent.pid) { - this.persistTerminalSession(terminalComponent.pid, formattedTitle); + await this.persistTerminalSession( + terminalComponent.pid, + formattedTitle, + ); } // Refresh the header subtitle if this terminal is active