Skip to content

Commit

Permalink
terminal improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed May 21, 2024
1 parent 920dae6 commit 0bac179
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_14
targetCompatibility JavaVersion.VERSION_14
}
packagingOptions {
resources {
Expand Down
21 changes: 21 additions & 0 deletions Android/app/src/main/java/com/dergoogler/mmrl/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.core.view.WindowCompat;

Expand All @@ -20,6 +24,8 @@
import com.dergoogler.core.NativeView;

import org.apache.cordova.*;
import org.apache.cordova.engine.SystemWebChromeClient;
import org.apache.cordova.engine.SystemWebViewEngine;

public class MainActivity extends CordovaActivity {
@Override
Expand All @@ -36,6 +42,7 @@ public void onCreate(Bundle savedInstanceState) {
}

WebView wv = (WebView) appView.getEngine().getView();
CordovaWebViewEngine wve = appView.getEngine();


NativeStorage ns = new NativeStorage(this);
Expand Down Expand Up @@ -75,6 +82,20 @@ public void onCreate(Bundle savedInstanceState) {
wv.addJavascriptInterface(ns, "__nativeStorage__");
wv.addJavascriptInterface(new NativeLog(), "__log__");


wv.setWebChromeClient(new SystemWebChromeClient((SystemWebViewEngine) wve) {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
switch (consoleMessage.messageLevel()) {
case TIP -> Log.i("MMRLWebViewClient", consoleMessage.message());
case LOG -> Log.d("MMRLWebViewClient", consoleMessage.message());
case WARNING -> Log.w("MMRLWebViewClient", consoleMessage.message());
case ERROR -> Log.e("MMRLWebViewClient", consoleMessage.message());
default -> Log.v("MMRLWebViewClient", consoleMessage.message());
}
return true;
}
});
}

private String mmrlUserAgent() {
Expand Down
16 changes: 8 additions & 8 deletions Android/app/src/main/java/com/dergoogler/plugin/FetchPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ public boolean execute(final String action, final JSONArray data, final Callback

try {
String method = data.getString(0);
Log.v(LOG_TAG, "execute: method = " + method.toString());
// Log.v(LOG_TAG, "execute: method = " + method.toString());

String urlString = data.getString(1);
Log.v(LOG_TAG, "execute: urlString = " + urlString.toString());
// Log.v(LOG_TAG, "execute: urlString = " + urlString.toString());

String postBody = data.getString(2);
Log.v(LOG_TAG, "execute: postBody = " + postBody.toString());
// Log.v(LOG_TAG, "execute: postBody = " + postBody.toString());

JSONObject headers = data.getJSONObject(3);
if (headers.has("map") && headers.getJSONObject("map") != null) {
headers = headers.getJSONObject("map");
}

Log.v(LOG_TAG, "execute: headers = " + headers.toString());
// Log.v(LOG_TAG, "execute: headers = " + headers.toString());

Request.Builder requestBuilder = new Request.Builder();

Expand Down Expand Up @@ -83,7 +83,7 @@ public boolean execute(final String action, final JSONArray data, final Callback

if (headerValues.length() > 0) {
String headerValue = headerValues.getString(0);
Log.v(LOG_TAG, "key = " + headerName + " value = " + headerValue);
// Log.v(LOG_TAG, "key = " + headerName + " value = " + headerValue);
requestBuilder.addHeader(headerName, headerValue);
}
}
Expand Down Expand Up @@ -135,8 +135,8 @@ public void onResponse(Call call, Response response) throws IOException {
e.printStackTrace();
}

Log.v(LOG_TAG, "HTTP code: " + response.code());
Log.v(LOG_TAG, "returning: " + result.toString());
// Log.v(LOG_TAG, "HTTP code: " + response.code());
// Log.v(LOG_TAG, "returning: " + result.toString());

callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
}
Expand All @@ -159,7 +159,7 @@ public void onResponse(Call call, Response response) throws IOException {
}

private void setTimeout(long seconds) {
Log.v(LOG_TAG, "setTimeout: " + seconds);
// Log.v(LOG_TAG, "setTimeout: " + seconds);

mClient = mClient.newBuilder()
.connectTimeout(seconds, TimeUnit.SECONDS)
Expand Down
42 changes: 26 additions & 16 deletions Android/app/src/main/java/com/dergoogler/plugin/TerminalPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
boolean printError = data.getBoolean(3);

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


cordova.getThreadPool().execute(() -> {
try {
if (run(envp, cwd, commands)) {
callbackContext.error(ProcessCode);
}
run(envp, cwd, commands);
} catch (IOException | JSONException e) {
e.printStackTrace();
if (printError) {
updateTerminal(e.toString());
updateTerminalLine(e.toString());
}
callbackContext.error(500);
updateTerminalExit(500);
}
});
return true;
Expand All @@ -64,37 +62,49 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo

}

public boolean run(JSONObject envp, String cwd, String... command) throws IOException, JSONException {
public void run(JSONObject envp, String cwd, String... command) throws IOException, JSONException {
ProcessBuilder pb = new ProcessBuilder(command).redirectErrorStream(true);
if (envp != null) {
Map<String, String> m = pb.environment();
m.putAll(toMap(envp));
}

pb.directory(new SuFile(cwd));
Process process = pb.start();
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
while (true) {
String line = in.readLine();
if (line == null)
break;
updateTerminal(line);
updateTerminalLine(line);
}
ProcessCode = process.exitValue();
updateTerminalExit(process.exitValue());
} catch (Exception e) {
ProcessCode = 500;
updateTerminalExit(500);
}
}

return !process.isAlive();
private void updateTerminalLine(String line) {
sendUpdate(PluginResult.Status.OK, line);
}

private void updateTerminal(String line) {
sendUpdate(line, true);
private void updateTerminalExit(int code) {
sendUpdate(PluginResult.Status.ERROR, code);
}

private void sendUpdate(String line, boolean keepCallback) {
private void sendUpdate(PluginResult.Status status, int line) {
if (this.terminalCallbackContext != null) {
PluginResult result = new PluginResult(status, line);
result.setKeepCallback(true);
this.terminalCallbackContext.sendPluginResult(result);
}
}


private void sendUpdate(PluginResult.Status status, String line) {
if (this.terminalCallbackContext != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, line);
result.setKeepCallback(keepCallback);
PluginResult result = new PluginResult(status, line);
result.setKeepCallback(true);
this.terminalCallbackContext.sendPluginResult(result);
}
}
Expand Down
18 changes: 7 additions & 11 deletions Website/src/activitys/TerminalActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useStrings } from "@Hooks/useStrings";
import { BuildConfig } from "@Native/BuildConfig";
import { Shell } from "@Native/Shell";
import { view } from "@Native/View";
import { INCLUDE_CORE } from "@Util/INCLUDE_CORE";
import RestartAltIcon from "@mui/icons-material/RestartAlt";
import { Button } from "@mui/material";
import Box from "@mui/material/Box";
Expand Down Expand Up @@ -82,7 +81,6 @@ const TerminalActivity = () => {
component: Ansi,
props: {
linkify: true,

...props,
},
},
Expand Down Expand Up @@ -134,7 +132,6 @@ const TerminalActivity = () => {

Terminal.exec({
command: modFS("EXPLORE_INSTALL", {
INCLUDECORE: INCLUDE_CORE,
URL: path,
MODID: id,
}),
Expand Down Expand Up @@ -231,7 +228,6 @@ const TerminalActivity = () => {

Terminal.exec({
command: modFS("LOCAL_INSTALL", {
INCLUDECORE: INCLUDE_CORE,
ZIPFILE: path,
}),
env: envp_local,
Expand Down Expand Up @@ -311,36 +307,35 @@ const TerminalActivity = () => {
}
}}
sx={{
pl: 1,
pr: 1,
// removing bottom window insets
pb: "0px !important",
}}
onShow={install}
modifier="noshadow"
renderToolbar={renderToolbar}
>
<Box
component={GestureDetector}
{/* <GestureDetector
onPinch={(e: any) => {
setFontSize((init) => {
const newFontSize = init * (1 + (e.gesture.scale - 1) * 0.5);
return Math.min(Math.max(newFontSize, 12), 100);
});
}}
> */}
<Box
sx={{
display: "flex",
flexWrap: "wrap",
height: "100%",
}}
>
<Stack
sx={{
pl: 1,
pr: 1,
whiteSpace: "pre",
flex: "0 0 100%",
color: "white",
height: "100%",
fontSize: fontSize,
// fontSize: fontSize,
}}
direction="column"
justifyContent="flex-start"
Expand All @@ -353,6 +348,7 @@ const TerminalActivity = () => {
</Stack>
</Box>
<Box sx={{ height: view.getWindowBottomInsets() }} ref={termEndRef} />
{/* </GestureDetector> */}
</Page>
);
};
Expand Down
4 changes: 2 additions & 2 deletions Website/src/hooks/useModFS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export const INITIAL_MOD_CONF: ModFS = {

// others
MMRLINI: "<MODULES>/mmrl_install_tools",
EXPLORE_INSTALL: "<MMRLINI>/system/usr/share/mmrl/bin/mmrl_explore_install_v6",
LOCAL_INSTALL: "<MMRLINI>/system/usr/share/mmrl/bin/mmrl_local_install_v6",
EXPLORE_INSTALL: "sh <MMRLINI>/system/usr/share/mmrl/bin/mmrl_explore_install_v8.sh",
LOCAL_INSTALL: "sh <MMRLINI>/system/usr/share/mmrl/bin/mmrl_local_install_v8.sh",
};

export interface ModConfContext {
Expand Down
10 changes: 5 additions & 5 deletions Website/src/util/licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"author": null,
"license": "MIT",
"description": "Standalone build of Babel for use in non-Node.js environments.",
"version": "7.23.8",
"version": "7.24.0",
"source": "https://www.npmjs.com/package/@babel/standalone"
},
{
Expand Down Expand Up @@ -81,7 +81,7 @@
"author": null,
"license": "MIT",
"description": "A scalable set of icons handcrafted with <3 by GitHub.",
"version": "19.8.0",
"version": "19.9.0",
"source": "https://www.npmjs.com/package/@primer/octicons-react"
},
{
Expand Down Expand Up @@ -208,16 +208,16 @@
"name": "material-ui-confirm",
"author": null,
"license": "MIT",
"description": "Higher order component for straightforward use of @material-ui/core confirmation dialogs.",
"version": "3.0.10",
"description": "Simple confirmation dialogs built on top of @mui/material",
"version": "3.0.11",
"source": "https://www.npmjs.com/package/material-ui-confirm"
},
{
"name": "monaco-editor",
"author": null,
"license": "MIT",
"description": "A browser based code editor",
"version": "0.45.0",
"version": "0.48.0",
"source": "https://www.npmjs.com/package/monaco-editor"
},
{
Expand Down

0 comments on commit 0bac179

Please sign in to comment.