Skip to content

Commit 92cf6c2

Browse files
Merge branch 'main' into feat/native-websocket-plugin
2 parents 4f27c2b + a07877a commit 92cf6c2

7 files changed

Lines changed: 127 additions & 3 deletions

File tree

.github/workflows/close-inactive-issues.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ jobs:
1212
steps:
1313
- uses: actions/stale@v9
1414
with:
15-
days-before-issue-stale: 30
15+
days-before-issue-stale: 60
1616
days-before-issue-close: 14
1717
stale-issue-label: "stale"
18-
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment(i.e Bump!) or this will be closed in 14 days."
18+
stale-issue-message: >
19+
Hi there! 👋
20+
21+
We're working to clean up our issue tracker by closing older issues that might not be relevant anymore. If you are able to reproduce this issue in the latest version of Acode, please let us know by commenting on this issue(i.e Bump!), and we will keep it open. If you can't reproduce it, feel free to close the issue yourself. Otherwise, we'll close it in 14 days.
22+
23+
Thanks for your help!
1924
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
2025
days-before-pr-stale: -1
2126
days-before-pr-close: -1
27+
exempt-issue-labels: "new plugin idea, todo"
28+
operations-per-run: 100
2229
repo-token: ${{ secrets.GITHUB_TOKEN }}
2330

package-lock.json

Lines changed: 11 additions & 0 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"cordova-plugin-advanced-http": {
3737
"ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
3838
},
39-
"cordova-plugin-websocket": {}
39+
"cordova-plugin-websocket": {},
40+
"com.foxdebug.acode.exec": {}
4041
},
4142
"platforms": [
4243
"android"
@@ -62,6 +63,7 @@
6263
"@types/url-parse": "^1.4.11",
6364
"autoprefixer": "^10.4.19",
6465
"babel-loader": "^9.1.3",
66+
"com.foxdebug.acode.exec": "file:src/plugins/Executor",
6567
"cordova-android": "^13.0.0",
6668
"cordova-clipboard": "^1.3.0",
6769
"cordova-plugin-advanced-http": "^3.3.1",

src/plugins/Executor/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function exec(cmd,success,failure) {
2+
const ACTION = 'exec';
3+
cordova.exec(success, failure, 'Executor', ACTION, [cmd]);
4+
}
5+
6+
export default {
7+
exec,
8+
};

src/plugins/Executor/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "com.foxdebug.acode.exec",
3+
"version": "1.0.0",
4+
"description": "Execute linux commands",
5+
"cordova": {
6+
"id": "com.foxdebug.acode.exec",
7+
"platforms": [
8+
"android"
9+
]
10+
},
11+
"keywords": [
12+
"ecosystem:cordova",
13+
"cordova-android"
14+
],
15+
"author": "",
16+
"license": "ISC"
17+
}

src/plugins/Executor/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<plugin id="com.foxdebug.acode.exec" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"><name>Executor</name><js-module name="Executor" src="www/Executor.js"><clobbers target="cordova.plugins.Executor" /></js-module><platform name="android"><config-file parent="/*" target="res/xml/config.xml"><feature name="Executor"><param name="android-package" value="com.foxdebug.acode.exec.Executor" /></feature></config-file><config-file parent="/*" target="AndroidManifest.xml"></config-file><source-file src="src/android/Executor.java" target-dir="src/com/foxdebug/acode/exec/Executor" /></platform></plugin>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.foxdebug.acode.exec;
2+
3+
import org.apache.cordova.CordovaPlugin;
4+
import org.apache.cordova.CallbackContext;
5+
6+
import org.json.JSONArray;
7+
import org.json.JSONException;
8+
9+
import java.io.BufferedReader;
10+
import java.io.InputStreamReader;
11+
12+
public class Executor extends CordovaPlugin {
13+
14+
@Override
15+
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
16+
cordova.getThreadPool().execute(new Runnable() {
17+
@Override
18+
public void run() {
19+
if ("exec".equals(action)) {
20+
try {
21+
String cmd = args.getString(0);
22+
exec(cmd, callbackContext);
23+
} catch (JSONException e) {
24+
callbackContext.error("Invalid arguments");
25+
}
26+
} else {
27+
callbackContext.error("Unknown action");
28+
}
29+
}
30+
});
31+
32+
return true;
33+
}
34+
35+
private void exec(String cmd, CallbackContext callbackContext) {
36+
try {
37+
if (cmd != null && !cmd.isEmpty()) {
38+
Process process = Runtime.getRuntime().exec(cmd);
39+
40+
// Capture stdout
41+
BufferedReader stdOutReader = new BufferedReader(
42+
new InputStreamReader(process.getInputStream()));
43+
StringBuilder stdOut = new StringBuilder();
44+
String line;
45+
while ((line = stdOutReader.readLine()) != null) {
46+
stdOut.append(line).append("\n");
47+
}
48+
49+
// Capture stderr
50+
BufferedReader stdErrReader = new BufferedReader(
51+
new InputStreamReader(process.getErrorStream()));
52+
StringBuilder stdErr = new StringBuilder();
53+
while ((line = stdErrReader.readLine()) != null) {
54+
stdErr.append(line).append("\n");
55+
}
56+
57+
int exitCode = process.waitFor();
58+
if (exitCode == 0) {
59+
callbackContext.success(stdOut.toString().trim());
60+
} else {
61+
// Return stderr if command fails
62+
String errorOutput = stdErr.toString().trim();
63+
if (errorOutput.isEmpty()) {
64+
errorOutput = "Command exited with code: " + exitCode;
65+
}
66+
callbackContext.error(errorOutput);
67+
}
68+
} else {
69+
callbackContext.error("Expected one non-empty string argument.");
70+
}
71+
} catch (Exception e) {
72+
e.printStackTrace();
73+
callbackContext.error("Exception: " + e.getMessage());
74+
}
75+
}
76+
77+
}

0 commit comments

Comments
 (0)