Skip to content

Commit 4aeb7e8

Browse files
feat. added helper functions
1 parent dfeef29 commit 4aeb7e8

File tree

9 files changed

+174
-30
lines changed

9 files changed

+174
-30
lines changed

package-lock.json

Lines changed: 43 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
"cordova-plugin-sdcard": {},
3232
"cordova-plugin-browser": {},
3333
"cordova-plugin-iap": {},
34-
"cordova-plugin-system": {},
3534
"cordova-plugin-advanced-http": {
3635
"ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
3736
},
3837
"cordova-plugin-websocket": {},
3938
"com.foxdebug.acode.rk.exec.terminal": {},
40-
"cordova-plugin-buildinfo": {}
39+
"cordova-plugin-buildinfo": {},
40+
"cordova-plugin-system": {}
4141
},
4242
"platforms": [
4343
"android"
@@ -64,7 +64,7 @@
6464
"autoprefixer": "^10.4.19",
6565
"babel-loader": "^9.1.3",
6666
"com.foxdebug.acode.rk.exec.terminal": "file:src/plugins/terminal",
67-
"cordova-android": "^13.0.0",
67+
"cordova-android": "^14.0.1",
6868
"cordova-clipboard": "^1.3.0",
6969
"cordova-plugin-advanced-http": "^3.3.1",
7070
"cordova-plugin-browser": "file:src/plugins/browser",

src/lib/checkFiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default async function checkFiles() {
4747
* @returns {Promise<void>}
4848
*/
4949
async function checkFile(file) {
50-
if (file.isUnsaved || !file.loaded || file.loading) return;
50+
if (file === undefined || file.isUnsaved || !file.loaded || file.loading) return;
5151

5252
if (file.uri) {
5353
const fs = fsOperation(file.uri);

src/lib/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import NotificationManager from "lib/notificationManager";
5454
import { addedFolder } from "lib/openFolder";
5555
import { getEncoding, initEncodings } from "utils/encodings";
5656
import auth, { loginEvents } from "./auth";
57-
import constants from "./constants";
5857

5958
const previousVersionCode = Number.parseInt(localStorage.versionCode, 10);
6059

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,30 @@ public void run() {
156156
}
157157
);
158158
return true;
159+
case "fileExists":
160+
callbackContext.success(fileExists(args.getString(0)) ? 1 : 0);
161+
return true;
162+
163+
case "createSymlink":
164+
boolean success = createSymlink(args.getString(0), args.getString(1));
165+
callbackContext.success(success ? 1 : 0);
166+
return true;
167+
168+
case "getNativeLibraryPath":
169+
callbackContext.success(getNativeLibraryPath());
170+
return true;
171+
172+
case "getFilesDir":
173+
callbackContext.success(getFilesDir());
174+
return true;
175+
176+
case "getParentPath":
177+
callbackContext.success(getParentPath(args.getString(0)));
178+
return true;
179+
180+
case "listChildren":
181+
callbackContext.success(listChildren(args.getString(0)));
182+
return true;
159183
default:
160184
return false;
161185
}
@@ -399,6 +423,48 @@ private void hasPermission(String permission, CallbackContext callback) {
399423
callback.error("No permission passed to check.");
400424
}
401425

426+
public boolean fileExists(String path) {
427+
return new File(path).exists();
428+
}
429+
430+
public boolean createSymlink(String target, String linkPath) {
431+
try {
432+
Process process = Runtime.getRuntime().exec(new String[]{"ln", "-s", target, linkPath});
433+
return process.waitFor() == 0;
434+
} catch (Exception e) {
435+
return false;
436+
}
437+
}
438+
439+
public String getNativeLibraryPath() {
440+
ApplicationInfo appInfo = context.getApplicationInfo();
441+
return appInfo.nativeLibraryDir;
442+
}
443+
444+
public String getFilesDir() {
445+
return context.getFilesDir().getAbsolutePath();
446+
}
447+
448+
public String getParentPath(String path) {
449+
File file = new File(path);
450+
File parent = file.getParentFile();
451+
return parent != null ? parent.getAbsolutePath() : null;
452+
}
453+
454+
public JSONArray listChildren(String path) throws JSONException {
455+
File dir = new File(path);
456+
JSONArray result = new JSONArray();
457+
if (dir.exists() && dir.isDirectory()) {
458+
File[] files = dir.listFiles();
459+
if (files != null) {
460+
for (File file : files) {
461+
result.put(file.getAbsolutePath());
462+
}
463+
}
464+
}
465+
return result;
466+
}
467+
402468
public void onRequestPermissionResult(
403469
int code,
404470
String[] permissions,

src/plugins/system/www/plugin.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
module.exports = {
2+
fileExists: function (path, success, error) {
3+
cordova.exec(success, error, 'System', 'fileExists', [path]);
4+
},
5+
6+
createSymlink: function (target, linkPath, success, error) {
7+
cordova.exec(success, error, 'System', 'createSymlink', [target, linkPath]);
8+
},
9+
10+
getNativeLibraryPath: function (success, error) {
11+
cordova.exec(success, error, 'System', 'getNativeLibraryPath', []);
12+
},
13+
14+
getFilesDir: function (success, error) {
15+
cordova.exec(success, error, 'System', 'getFilesDir', []);
16+
},
17+
18+
getParentPath: function (path, success, error) {
19+
cordova.exec(success, error, 'System', 'getParentPath', [path]);
20+
},
21+
22+
listChildren: function (path, success, error) {
23+
cordova.exec(success, error, 'System', 'listChildren', [path]);
24+
},
225
clearCache: function (success, fail) {
326
return cordova.exec(success, fail, "System", "clearCache", []);
427
},

src/plugins/terminal/plugin.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="com.foxdebug.acode.rk.exec.terminal" version="1.0.0">
33
<name>Terminal</name>
4+
5+
<js-module name="Terminal" src="www/Terminal.js">
6+
<clobbers target="window.Terminal" />
7+
</js-module>
48

59
<!-- executor api -->
610
<js-module name="Executor" src="www/Executor.js">
7-
<clobbers target="cordova.plugins.Executor" />
11+
<clobbers target="window.Executor" />
812
</js-module>
913

10-
1114
<platform name="android">
1215
<config-file parent="/*" target="res/xml/config.xml">
16+
<feature name="Executor">
17+
<param name="android-package" value="com.foxdebug.acode.rk.exec.terminal" />
18+
</feature>
1319
<feature name="Terminal">
1420
<param name="android-package" value="com.foxdebug.acode.rk.exec.terminal" />
1521
</feature>
1622
</config-file>
1723
<config-file parent="/*" target="AndroidManifest.xml" />
1824
<source-file src="src/android/Executor.java" target-dir="src/com/foxdebug/acode/rk/exec/terminal" />
19-
25+
2026
<!-- Use flavors if F-Droid complains about native libs -->
2127
<source-file src="libs/libproot-aarch64.so" target-dir="libs/arm64-v8a" />
2228
<source-file src="libs/libproot32-aarch64.so" target-dir="libs/arm64-v8a" />

src/plugins/terminal/www/Executor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Executor = {
2828
* Executor.stop(pid);
2929
* });
3030
*/
31-
start(command, onData) {
31+
start(command, onData,alpine = false) {
3232
return new Promise((resolve, reject) => {
3333
exec(
3434
(message) => {
@@ -81,7 +81,7 @@ const Executor = {
8181
* Executes a shell command and waits for it to finish.
8282
* Unlike `start()`, this is a one-time execution and does not stream real-time output.
8383
*
84-
* @param {string} cmd - The command to execute.
84+
* @param {string} command - The command to execute.
8585
* @returns {Promise<string>} Resolves with stdout if the command succeeds, rejects with stderr or error message if it fails.
8686
*
8787
* @example
@@ -91,9 +91,9 @@ const Executor = {
9191
* console.error(error);
9292
* });
9393
*/
94-
execute(cmd) {
94+
execute(command,alpine = false) {
9595
return new Promise((resolve, reject) => {
96-
exec(resolve, reject, "Executor", "exec", [cmd]);
96+
exec(resolve, reject, "Executor", "exec", [command]);
9797
});
9898
}
9999
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
const Terminal = {
4+
startAxs(){
5+
6+
},
7+
8+
stopAxs(){
9+
10+
},
11+
12+
isAxsRunning(){
13+
14+
},
15+
16+
startInstallation(){
17+
18+
},
19+
20+
isInstalled(){
21+
22+
},
23+
}
24+
25+
module.exports = Terminal

0 commit comments

Comments
 (0)