Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
37 changes: 21 additions & 16 deletions src/components/terminal/terminalManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -229,8 +235,6 @@ class TerminalManager {
}
}, 100);
});

return terminalInstance;
} catch (error) {
console.error("Failed to create terminal:", error);
throw error;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -374,8 +378,6 @@ class TerminalManager {
}
}, 100);
});

return terminalInstance;
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down