Skip to content

Commit fe9d32a

Browse files
committed
improve the installation of terminal
- show clear log in terminal without stdout,stderr prefix - start a new terminal sesion after installation completes with "exit 0"
1 parent 1b0a5e1 commit fe9d32a

File tree

4 files changed

+75
-31
lines changed

4 files changed

+75
-31
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"cordova-plugin-websocket": {},
3838
"cordova-plugin-buildinfo": {},
3939
"cordova-plugin-system": {},
40-
"com.foxdebug.acode.rk.exec.terminal": {},
41-
"com.foxdebug.acode.rk.exec.proot": {}
40+
"com.foxdebug.acode.rk.exec.proot": {},
41+
"com.foxdebug.acode.rk.exec.terminal": {}
4242
},
4343
"platforms": [
4444
"android"

src/components/terminal/terminalManager.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,31 @@ class TerminalManager {
134134
const installTerminal = await this.createInstallationTerminal();
135135

136136
// Install terminal with progress logging
137-
await Terminal.install(
137+
const installResult = await Terminal.install(
138138
(message) => {
139-
installTerminal.component.write(`${message}\r\n`);
139+
// Remove stdout/stderr prefix for
140+
const cleanMessage = message.replace(/^(stdout|stderr)\s+/, "");
141+
installTerminal.component.write(`${cleanMessage}\r\n`);
140142
},
141143
(error) => {
142-
installTerminal.component.write(`\x1b[31mError: ${error}\x1b[0m\r\n`);
144+
// Remove stdout/stderr prefix
145+
const cleanError = error.replace(/^(stdout|stderr)\s+/, "");
146+
installTerminal.component.write(
147+
`\x1b[31mError: ${cleanError}\x1b[0m\r\n`,
148+
);
143149
},
144150
);
145-
return { success: true };
151+
152+
// Only return success if Terminal.install() indicates success (exit code 0)
153+
if (installResult === true) {
154+
return { success: true };
155+
} else {
156+
return {
157+
success: false,
158+
error:
159+
"Terminal installation failed - process did not exit with code 0",
160+
};
161+
}
146162
} catch (error) {
147163
console.error("Terminal installation failed:", error);
148164
return {

src/plugins/terminal/www/Terminal.js

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,52 @@ const Terminal = {
1212
* @param {boolean} [installing=false] - Whether AXS is being started during installation.
1313
* @param {Function} [logger=console.log] - Function to log standard output.
1414
* @param {Function} [err_logger=console.error] - Function to log errors.
15-
* @returns {Promise<void>}
15+
* @returns {Promise<boolean>} - Returns true if installation completes with exit code 0, void if not installing
1616
*/
1717
async startAxs(installing = false, logger = console.log, err_logger = console.error) {
1818
const filesDir = await new Promise((resolve, reject) => {
1919
system.getFilesDir(resolve, reject);
2020
});
2121

22-
readAsset("init-alpine.sh", async (content) => {
23-
system.writeText(`${filesDir}/init-alpine.sh`, content, logger, err_logger);
24-
});
22+
if (installing) {
23+
return new Promise((resolve, reject) => {
24+
readAsset("init-alpine.sh", async (content) => {
25+
system.writeText(`${filesDir}/init-alpine.sh`, content, logger, err_logger);
26+
});
27+
28+
readAsset("init-sandbox.sh", (content) => {
29+
system.writeText(`${filesDir}/init-sandbox.sh`, content, logger, err_logger);
30+
31+
Executor.start("sh", (type, data) => {
32+
logger(`${type} ${data}`);
33+
34+
// Check for exit code during installation
35+
if (type === "exit") {
36+
resolve(data === "0");
37+
}
38+
}).then(async (uuid) => {
39+
await Executor.write(uuid, `source ${filesDir}/init-sandbox.sh ${installing ? "--installing" : ""}; exit`);
40+
}).catch((error) => {
41+
err_logger("Failed to start AXS:", error);
42+
resolve(false);
43+
});
44+
});
45+
});
46+
} else {
47+
readAsset("init-alpine.sh", async (content) => {
48+
system.writeText(`${filesDir}/init-alpine.sh`, content, logger, err_logger);
49+
});
2550

26-
readAsset("init-sandbox.sh", (content) => {
27-
system.writeText(`${filesDir}/init-sandbox.sh`, content, logger, err_logger);
51+
readAsset("init-sandbox.sh", (content) => {
52+
system.writeText(`${filesDir}/init-sandbox.sh`, content, logger, err_logger);
2853

29-
Executor.start("sh", (type, data) => {
30-
logger(`${type} ${data}`);
31-
}).then(async (uuid) => {
32-
await Executor.write(uuid, `source ${filesDir}/init-sandbox.sh ${installing ? "--installing" : ""}; exit`);
54+
Executor.start("sh", (type, data) => {
55+
logger(`${type} ${data}`);
56+
}).then(async (uuid) => {
57+
await Executor.write(uuid, `source ${filesDir}/init-sandbox.sh ${installing ? "--installing" : ""}; exit`);
58+
});
3359
});
34-
});
60+
}
3561
},
3662

3763
/**
@@ -68,11 +94,11 @@ const Terminal = {
6894
* Also sets up additional dependencies for F-Droid variant.
6995
* @param {Function} [logger=console.log] - Function to log standard output.
7096
* @param {Function} [err_logger=console.error] - Function to log errors.
71-
* @returns {Promise<void>}
97+
* @returns {Promise<boolean>} - Returns true if installation completes with exit code 0
7298
*/
7399
async install(logger = console.log, err_logger = console.error) {
74-
if (await this.isInstalled()) return;
75-
if (!(await this.isSupported())) return;
100+
if (await this.isInstalled()) return true;
101+
if (!(await this.isSupported())) return false;
76102

77103
const filesDir = await new Promise((resolve, reject) => {
78104
system.getFilesDir(resolve, reject);
@@ -168,10 +194,12 @@ const Terminal = {
168194
system.mkdirs(`${filesDir}/.extracted`, resolve, reject);
169195
});
170196

171-
this.startAxs(true, logger, err_logger);
197+
const installResult = await this.startAxs(true, logger, err_logger);
198+
return installResult;
172199

173200
} catch (e) {
174201
err_logger("Installation failed:", e);
202+
return false;
175203
}
176204
},
177205

@@ -227,14 +255,14 @@ const Terminal = {
227255
}
228256
const cmd = `
229257
set -e
230-
258+
231259
INCLUDE_FILES="$PREFIX/alpine $PREFIX/.downloaded $PREFIX/.extracted $PREFIX/axs"
232260
233261
if [ "$FDROID" = "true" ]; then
234262
INCLUDE_FILES="$INCLUDE_FILES $PREFIX/libtalloc.so.2 $PREFIX/libproot-xed.so"
235263
fi
236264
237-
265+
238266
tar -cf $PREFIX/aterm_backup.tar $INCLUDE_FILES
239267
echo "ok"
240268
`
@@ -255,7 +283,7 @@ const Terminal = {
255283
set -e
256284
257285
if [ -f "$PREFIX/aterm_backup.tar" ]; then
258-
286+
259287
else
260288
echo "Backup File does not exist"
261289
fi
@@ -271,7 +299,7 @@ const Terminal = {
271299
rm -rf -- "$item"
272300
done
273301
274-
302+
275303
tar -xf $PREFIX/aterm_backup.tar -C $PREFIX
276304
echo "ok"
277305
`
@@ -291,7 +319,7 @@ const Terminal = {
291319

292320
const cmd = `
293321
set -e
294-
322+
295323
INCLUDE_FILES="$PREFIX/alpine $PREFIX/.downloaded $PREFIX/.extracted $PREFIX/axs"
296324
297325
if [ "$FDROID" = "true" ]; then

www/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@
165165

166166
<title>Acode</title>
167167
<!--styles-->
168+
<link rel="stylesheet" href="./css/build/218.css">
169+
<link rel="stylesheet" href="./css/build/32.css">
170+
<link rel="stylesheet" href="./css/build/383.css">
171+
<link rel="stylesheet" href="./css/build/53.css">
172+
<link rel="stylesheet" href="./css/build/609.css">
168173
<link rel="stylesheet" href="./css/build/about.css">
169174
<link rel="stylesheet" href="./css/build/customTheme.css">
170175
<link rel="stylesheet" href="./css/build/donate.css">
171176
<link rel="stylesheet" href="./css/build/fileBrowser.css">
172177
<link rel="stylesheet" href="./css/build/main.css">
173178
<link rel="stylesheet" href="./css/build/plugins.css">
174-
<link rel="stylesheet" href="./css/build/src_pages_quickTools_quickTools_js.css">
175-
<link rel="stylesheet" href="./css/build/src_sidebarApps_extensions_index_js.css">
176-
<link rel="stylesheet" href="./css/build/src_sidebarApps_files_index_js.css">
177-
<link rel="stylesheet" href="./css/build/src_sidebarApps_notification_index_js.css">
178-
<link rel="stylesheet" href="./css/build/src_sidebarApps_searchInFiles_index_js.css">
179179
<link rel="stylesheet" href="./css/build/themeSetting.css">
180180
<!--styles_end-->
181181
</head>

0 commit comments

Comments
 (0)