Skip to content

Commit a40515f

Browse files
committed
pos. fix #154
1 parent 68921c6 commit a40515f

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

Android/app/src/main/java/com/dergoogler/plugin/TerminalPlugin.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class TerminalPlugin extends CordovaPlugin {
2424
private static final String LOG_TAG = "TerminalPlugin";
2525
private CallbackContext terminalCallbackContext = null;
2626

27-
private int ProcessCode = 1;
27+
private int ProcessCode = 1000;
2828

2929
@Override
3030
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
@@ -33,17 +33,23 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
3333
String cmd = data.getString(0);
3434
JSONObject envp = data.getJSONObject(1);
3535
String cwd = data.getString(2);
36+
boolean printError = data.getBoolean(3);
3637

3738
this.terminalCallbackContext = callbackContext;
3839
String[] commands = {"su", "-p", "-c", cmd};
3940

41+
4042
cordova.getThreadPool().execute(() -> {
4143
try {
42-
run(envp, cwd, commands);
43-
callbackContext.error(ProcessCode);
44+
if (run(envp, cwd, commands)) {
45+
callbackContext.error(ProcessCode);
46+
}
4447
} catch (IOException | JSONException e) {
45-
callbackContext.error(500);
4648
e.printStackTrace();
49+
if (printError) {
50+
updateTerminal(e.toString());
51+
}
52+
callbackContext.error(500);
4753
}
4854
});
4955
return true;
@@ -58,7 +64,7 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
5864

5965
}
6066

61-
public void run(JSONObject envp, String cwd, String... command) throws IOException, JSONException {
67+
public boolean run(JSONObject envp, String cwd, String... command) throws IOException, JSONException {
6268
ProcessBuilder pb = new ProcessBuilder(command).redirectErrorStream(true);
6369
if (envp != null) {
6470
Map<String, String> m = pb.environment();
@@ -77,6 +83,8 @@ public void run(JSONObject envp, String cwd, String... command) throws IOExcepti
7783
} catch (Exception e) {
7884
ProcessCode = 500;
7985
}
86+
87+
return !process.isAlive();
8088
}
8189

8290
private void updateTerminal(String line) {

Website/src/activitys/TerminalActivity.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { useModFS } from "@Hooks/useModFS";
1313
import { INCLUDE_CORE } from "@Util/INCLUDE_CORE";
1414
import { view } from "@Native/View";
1515
import { useConfirm } from "material-ui-confirm";
16+
import { ReplacementObject, useStrings } from "@Hooks/useStrings";
17+
import { StringDeclaration } from "./../locales/declaration";
1618

1719
export interface TerminalActivityExtra {
1820
exploreInstall: boolean;
@@ -25,6 +27,7 @@ export interface TerminalActivityExtra {
2527
const TerminalActivity = () => {
2628
const { context, extra } = useActivity<TerminalActivityExtra>();
2729
const { settings } = useSettings();
30+
const { strings } = useStrings();
2831
const { modFS, __modFS } = useModFS();
2932
const [active, setActive] = React.useState<bool>(true);
3033

@@ -106,9 +109,10 @@ const TerminalActivity = () => {
106109
const rebootDevice = React.useCallback(() => {
107110
const reason = "";
108111
confirm({
109-
title: "Reboot device?",
110-
description: "Are you sure to reboot your device?",
111-
confirmationText: "Yes",
112+
title: strings("reboot_device"),
113+
description: strings("reboot_device_desc"),
114+
confirmationText: strings("yes"),
115+
cancellationText: strings("cancel"),
112116
}).then(() => {
113117
Shell.cmd(`/system/bin/svc power reboot ${reason} || /system/bin/reboot ${reason}`).exec();
114118
});
@@ -211,8 +215,6 @@ const TerminalActivity = () => {
211215
setActive(false);
212216
break;
213217
}
214-
215-
addText({ children: String(code) });
216218
},
217219
});
218220
} else {
@@ -333,7 +335,7 @@ const TerminalActivity = () => {
333335
))}
334336
</Stack>
335337
</div>
336-
<div style={{ height: view.getWindowBottomInsets() }} ref={termEndRef} />
338+
<div ref={termEndRef} />
337339
</Page>
338340
);
339341
};

Website/src/hooks/useStrings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SetValue, useNativeStorage } from "./useNativeStorage";
44
import { StringDeclaration, Strs, useLanguageMap } from "./../locales/declaration";
55
import { useSettings } from "./useSettings";
66

7-
type ReplacementObject = {
7+
export type ReplacementObject = {
88
[key: string]: React.ReactNode;
99
};
1010

Website/src/locales/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,8 @@ export const en = {
147147
unverified_host_text:
148148
"You're accessing MMRL from {url} which isn't a verified host. Only use MMRL from it's origial source and not from thrid-party sources.",
149149
unverified_host_text_help: "Noticed any issues or you know that the accessed host safe for use is? Then report it under our {issues}",
150+
151+
// terminal activity
152+
reboot_device: "Reboot device?",
153+
reboot_device_desc: "Are you sure to reboot your device?",
150154
};

Website/src/typings/global.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,19 @@ declare global {
9898
namespace Terminal {
9999
export type Exec = {
100100
command: string;
101+
/**
102+
* Environment variables that should be used in your command execution
103+
*/
101104
env?: Record<string, string>;
105+
/**
106+
* Working directory
107+
*/
102108
cwd?: string;
109+
/**
110+
* Prints the error to the console or the `onLine` argument
111+
* @default true
112+
*/
113+
printError?: boolean;
103114
onLine: (line: string) => void;
104115
onExit: (code: number) => void;
105116
};

www/plugins/com.dergoogler.plugin/www/terminal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cordova.define(
99
opt.command,
1010
opt.env || { HOME: "/" },
1111
opt.cwd || "/",
12+
opt.printError || true,
1213
]);
1314
},
1415
test: function (msg, successCallback, errorCallback) {

0 commit comments

Comments
 (0)