From e068cbc289517f680aa85d6543c46dc05e9e58b4 Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sat, 25 Oct 2025 16:42:28 +0530 Subject: [PATCH 1/2] fix: do not restore terminals if axs is dead --- package-lock.json | 7 +- package.json | 4 +- src/components/terminal/terminalManager.js | 233 ++++++++++----------- 3 files changed, 125 insertions(+), 119 deletions(-) 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..ba4d264e6 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,54 +186,52 @@ class TerminalManager { }); // Wait for tab creation and setup - const terminalInstance = await new Promise((resolve, reject) => { - setTimeout(async () => { - try { - // Mount terminal component - terminalComponent.mount(terminalContainer); - - // Connect to session if in server mode - if (terminalComponent.serverMode) { - await terminalComponent.connectToSession(terminalOptions.pid); - } else { - // For local mode, just write a welcome message - terminalComponent.write( - "Local terminal mode - ready for output\r\n", - ); - } - - // Use PID as unique ID if available, otherwise fall back to terminalId - const uniqueId = terminalComponent.pid || terminalId; - - // Setup event handlers - this.setupTerminalHandlers( - terminalFile, - terminalComponent, - uniqueId, - ); - - const instance = { - id: uniqueId, - name: terminalName, - component: terminalComponent, - file: terminalFile, - container: terminalContainer, - }; - - this.terminals.set(uniqueId, instance); - - if (terminalComponent.serverMode && terminalComponent.pid) { - this.persistTerminalSession(terminalComponent.pid, terminalName); - } - resolve(instance); - } catch (error) { - console.error("Failed to initialize terminal:", error); - reject(error); - } - }, 100); - }); - - return terminalInstance; + return await new Promise((resolve, reject) => { + setTimeout(async () => { + try { + // Mount terminal component + terminalComponent.mount(terminalContainer); + + // Connect to session if in server mode + if (terminalComponent.serverMode) { + await terminalComponent.connectToSession(terminalOptions.pid); + } else { + // For local mode, just write a welcome message + terminalComponent.write( + "Local terminal mode - ready for output\r\n", + ); + } + + // Use PID as unique ID if available, otherwise fall back to terminalId + const uniqueId = terminalComponent.pid || terminalId; + + // Setup event handlers + this.setupTerminalHandlers( + terminalFile, + terminalComponent, + uniqueId, + ); + + const instance = { + id: uniqueId, + name: terminalName, + component: terminalComponent, + file: terminalFile, + container: terminalContainer, + }; + + this.terminals.set(uniqueId, instance); + + if (terminalComponent.serverMode && terminalComponent.pid) { + await this.persistTerminalSession(terminalComponent.pid, terminalName); + } + resolve(instance); + } catch (error) { + console.error("Failed to initialize terminal:", error); + reject(error); + } + }, 100); + }); } catch (error) { console.error("Failed to create terminal:", error); throw error; @@ -334,48 +335,46 @@ class TerminalManager { }); // Wait for tab creation and setup - const terminalInstance = await new Promise((resolve, reject) => { - setTimeout(async () => { - try { - // Mount terminal component - terminalComponent.mount(terminalContainer); - - // Write initial message - terminalComponent.write("🚀 Installing Terminal Environment...\r\n"); - terminalComponent.write( - "This may take a few minutes depending on your connection.\r\n\r\n", - ); - - // Setup event handlers - this.setupTerminalHandlers( - terminalFile, - terminalComponent, - terminalId, - ); - - // Set up custom title for installation terminal - terminalFile.setCustomTitle( - () => "Installing Terminal Environment...", - ); - - const instance = { - id: terminalId, - name: terminalName, - component: terminalComponent, - file: terminalFile, - container: terminalContainer, - }; - - this.terminals.set(terminalId, instance); - resolve(instance); - } catch (error) { - console.error("Failed to create installation terminal:", error); - reject(error); - } - }, 100); - }); - - return terminalInstance; + return await new Promise((resolve, reject) => { + setTimeout(async () => { + try { + // Mount terminal component + terminalComponent.mount(terminalContainer); + + // Write initial message + terminalComponent.write("🚀 Installing Terminal Environment...\r\n"); + terminalComponent.write( + "This may take a few minutes depending on your connection.\r\n\r\n", + ); + + // Setup event handlers + this.setupTerminalHandlers( + terminalFile, + terminalComponent, + terminalId, + ); + + // Set up custom title for installation terminal + terminalFile.setCustomTitle( + () => "Installing Terminal Environment...", + ); + + const instance = { + id: terminalId, + name: terminalName, + component: terminalComponent, + file: terminalFile, + container: terminalContainer, + }; + + this.terminals.set(terminalId, instance); + resolve(instance); + } catch (error) { + console.error("Failed to create installation terminal:", error); + reject(error); + } + }, 100); + }); } /** @@ -384,7 +383,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,26 +485,26 @@ class TerminalManager { this.closeTerminal(terminalId); }; - terminalComponent.onTitleChange = (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); - } - - // Refresh the header subtitle if this terminal is active - if ( - editorManager.activeFile && - editorManager.activeFile.id === terminalFile.id - ) { - // Force refresh of the header subtitle - terminalFile.setCustomTitle(getTerminalTitle); - } - } - }; + 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) { + await this.persistTerminalSession(terminalComponent.pid, formattedTitle); + } + + // Refresh the header subtitle if this terminal is active + if ( + editorManager.activeFile && + editorManager.activeFile.id === terminalFile.id + ) { + // Force refresh of the header subtitle + terminalFile.setCustomTitle(getTerminalTitle); + } + } + }; terminalComponent.onProcessExit = (exitData) => { // Format exit message based on exit code and signal From 9ce58645d62a8e853611ebe94865be9493338e1a Mon Sep 17 00:00:00 2001 From: RohitKushvaha01 Date: Sat, 25 Oct 2025 16:45:40 +0530 Subject: [PATCH 2/2] format --- src/components/terminal/terminalManager.js | 222 +++++++++++---------- 1 file changed, 114 insertions(+), 108 deletions(-) diff --git a/src/components/terminal/terminalManager.js b/src/components/terminal/terminalManager.js index ba4d264e6..110c6c470 100644 --- a/src/components/terminal/terminalManager.js +++ b/src/components/terminal/terminalManager.js @@ -23,9 +23,9 @@ class TerminalManager { localStorage.getItem(TERMINAL_SESSION_STORAGE_KEY), ); if (!Array.isArray(stored)) return []; - if (!await Terminal.isAxsRunning()){ - return []; - } + if (!(await Terminal.isAxsRunning())) { + return []; + } return stored .map((entry) => { if (!entry) return null; @@ -186,52 +186,55 @@ class TerminalManager { }); // Wait for tab creation and setup - return await new Promise((resolve, reject) => { - setTimeout(async () => { - try { - // Mount terminal component - terminalComponent.mount(terminalContainer); - - // Connect to session if in server mode - if (terminalComponent.serverMode) { - await terminalComponent.connectToSession(terminalOptions.pid); - } else { - // For local mode, just write a welcome message - terminalComponent.write( - "Local terminal mode - ready for output\r\n", - ); - } - - // Use PID as unique ID if available, otherwise fall back to terminalId - const uniqueId = terminalComponent.pid || terminalId; - - // Setup event handlers - this.setupTerminalHandlers( - terminalFile, - terminalComponent, - uniqueId, - ); - - const instance = { - id: uniqueId, - name: terminalName, - component: terminalComponent, - file: terminalFile, - container: terminalContainer, - }; - - this.terminals.set(uniqueId, instance); - - if (terminalComponent.serverMode && terminalComponent.pid) { - await this.persistTerminalSession(terminalComponent.pid, terminalName); - } - resolve(instance); - } catch (error) { - console.error("Failed to initialize terminal:", error); - reject(error); - } - }, 100); - }); + return await new Promise((resolve, reject) => { + setTimeout(async () => { + try { + // Mount terminal component + terminalComponent.mount(terminalContainer); + + // Connect to session if in server mode + if (terminalComponent.serverMode) { + await terminalComponent.connectToSession(terminalOptions.pid); + } else { + // For local mode, just write a welcome message + terminalComponent.write( + "Local terminal mode - ready for output\r\n", + ); + } + + // Use PID as unique ID if available, otherwise fall back to terminalId + const uniqueId = terminalComponent.pid || terminalId; + + // Setup event handlers + this.setupTerminalHandlers( + terminalFile, + terminalComponent, + uniqueId, + ); + + const instance = { + id: uniqueId, + name: terminalName, + component: terminalComponent, + file: terminalFile, + container: terminalContainer, + }; + + this.terminals.set(uniqueId, instance); + + if (terminalComponent.serverMode && terminalComponent.pid) { + await this.persistTerminalSession( + terminalComponent.pid, + terminalName, + ); + } + resolve(instance); + } catch (error) { + console.error("Failed to initialize terminal:", error); + reject(error); + } + }, 100); + }); } catch (error) { console.error("Failed to create terminal:", error); throw error; @@ -335,46 +338,46 @@ class TerminalManager { }); // Wait for tab creation and setup - return await new Promise((resolve, reject) => { - setTimeout(async () => { - try { - // Mount terminal component - terminalComponent.mount(terminalContainer); - - // Write initial message - terminalComponent.write("🚀 Installing Terminal Environment...\r\n"); - terminalComponent.write( - "This may take a few minutes depending on your connection.\r\n\r\n", - ); - - // Setup event handlers - this.setupTerminalHandlers( - terminalFile, - terminalComponent, - terminalId, - ); - - // Set up custom title for installation terminal - terminalFile.setCustomTitle( - () => "Installing Terminal Environment...", - ); - - const instance = { - id: terminalId, - name: terminalName, - component: terminalComponent, - file: terminalFile, - container: terminalContainer, - }; - - this.terminals.set(terminalId, instance); - resolve(instance); - } catch (error) { - console.error("Failed to create installation terminal:", error); - reject(error); - } - }, 100); - }); + return await new Promise((resolve, reject) => { + setTimeout(async () => { + try { + // Mount terminal component + terminalComponent.mount(terminalContainer); + + // Write initial message + terminalComponent.write("🚀 Installing Terminal Environment...\r\n"); + terminalComponent.write( + "This may take a few minutes depending on your connection.\r\n\r\n", + ); + + // Setup event handlers + this.setupTerminalHandlers( + terminalFile, + terminalComponent, + terminalId, + ); + + // Set up custom title for installation terminal + terminalFile.setCustomTitle( + () => "Installing Terminal Environment...", + ); + + const instance = { + id: terminalId, + name: terminalName, + component: terminalComponent, + file: terminalFile, + container: terminalContainer, + }; + + this.terminals.set(terminalId, instance); + resolve(instance); + } catch (error) { + console.error("Failed to create installation terminal:", error); + reject(error); + } + }, 100); + }); } /** @@ -486,25 +489,28 @@ class TerminalManager { }; 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) { - await this.persistTerminalSession(terminalComponent.pid, formattedTitle); - } - - // Refresh the header subtitle if this terminal is active - if ( - editorManager.activeFile && - editorManager.activeFile.id === terminalFile.id - ) { - // Force refresh of the header subtitle - terminalFile.setCustomTitle(getTerminalTitle); - } - } - }; + if (title) { + // Format terminal title as "Terminal ! - title" + const formattedTitle = `Terminal ${this.terminalCounter} - ${title}`; + terminalFile.filename = formattedTitle; + + if (terminalComponent.serverMode && terminalComponent.pid) { + await this.persistTerminalSession( + terminalComponent.pid, + formattedTitle, + ); + } + + // Refresh the header subtitle if this terminal is active + if ( + editorManager.activeFile && + editorManager.activeFile.id === terminalFile.id + ) { + // Force refresh of the header subtitle + terminalFile.setCustomTitle(getTerminalTitle); + } + } + }; terminalComponent.onProcessExit = (exitData) => { // Format exit message based on exit code and signal