Skip to content

Commit

Permalink
drop module requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Aug 18, 2024
1 parent ac5dea6 commit 68065bb
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 205 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/dergoogler/plugin/ChooserPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public static String getDisplayName(ContentResolver contentResolver, Uri uri) {
private CallbackContext callback;
private Boolean includeData;

public void chooseFile(CallbackContext callbackContext, String accept, Boolean includeData) {
public void chooseFile(CallbackContext callbackContext, String accept, Boolean includeData, boolean allowMulti) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
if (!accept.equals("*/*")) {
intent.putExtra(Intent.EXTRA_MIME_TYPES, accept.split(","));
}
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMulti);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
this.includeData = includeData;

Expand All @@ -103,7 +103,7 @@ public boolean execute(
) {
try {
if (action.equals(ChooserPlugin.ACTION_OPEN)) {
this.chooseFile(callbackContext, args.getString(0), args.getBoolean(1));
this.chooseFile(callbackContext, args.getString(0), args.getBoolean(1),args.getBoolean(2));
return true;
}
} catch (JSONException err) {
Expand Down
8 changes: 7 additions & 1 deletion docs/ModFS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

**ModFS** is a core component that provides a flexible and customizable filesystem for managing modules on Android devices. It's designed to streamline module installation, updates, and removal while offering granular control over module structure.

<!--
TODO: REWORK
## Workarounds
Here are some samples to avoid some configs
Expand Down Expand Up @@ -32,7 +36,9 @@ Based on your selected root method
FILE="/data/local/tmp/<MODID>.zip"; <MSUBSU> wget "<URL>" -O $FILE; <MSUCLI> --install-module $FILE;
```
# Add a local cover to your module
-->

## Add a local cover to your module

> [!IMPORTANT]
> Do not hardcode your cover path
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"reflect-metadata": "^0.2.2",
"underscore": "^1.13.6",
"usehooks-ts": "^3.1.0",
"uuid": "^10.0.0",
"yaml": "^2.3.4"
},
"devDependencies": {
Expand Down
202 changes: 129 additions & 73 deletions src/activitys/InstallTerminalV2Activity.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Add, Remove, CodeRounded, ArrowBackIosRounded, RestartAlt } from "@mui/icons-material";
import { Stack, Box, Slider, Button, Typography, TextField, alpha } from "@mui/material";
import { Stack, Box, Slider, Button, Typography, TextField, alpha, LinearProgress } from "@mui/material";
import FlatList from "flatlist-react";
import { Ansi } from "@Components/Ansi";
import { useTheme } from "@Hooks/useTheme";
Expand All @@ -17,6 +17,8 @@ import { useModFS } from "@Hooks/useModFS";
import { formatString } from "@Util/stringFormat";
import { Terminal } from "@Native/Terminal";
import { Image } from "@Components/dapi/Image";
import { Download } from "@Native/Download";
import { v1 as uuidv1 } from "uuid";

type IntrCommand = (args: string[], options: Record<string, string>, add: any) => void;

Expand Down Expand Up @@ -82,6 +84,11 @@ const useLines = (cmds: Record<string, IntrCommand>) => {
}
};

const setLastLine = (text: string, props?: object) => {
setLines((p) => p.slice(0, -1));
addText(text, props);
};

const addImage = (data: string, props?: object) => {
if (typeof data === "string") {
setLines((lines) => [
Expand Down Expand Up @@ -206,9 +213,12 @@ const useLines = (cmds: Record<string, IntrCommand>) => {
setUseInt: setUseInt,
addButton: addButton,
addText: addText,
setLastLine: setLastLine,
};
};

const TMPDIR = "/data/local/tmp";

export const InstallTerminalV2Activity = () => {
const { context, extra } = useActivity<TerminalActivityExtra>();
const { theme } = useTheme();
Expand All @@ -220,7 +230,7 @@ export const InstallTerminalV2Activity = () => {
const termEndRef = React.useRef<HTMLDivElement>(null);

const [active, setActive] = React.useState<bool>(true);
const { lines, addText, addButton } = useLines({
const { lines, addText, addButton, setLastLine } = useLines({
color: (args, _, add) => {
add.addText(formatString(args[0], colors));
},
Expand Down Expand Up @@ -288,91 +298,128 @@ export const InstallTerminalV2Activity = () => {
});
}, []);

const getInstallCLI = React.useCallback((adds?: Record<string, any>) => {
switch (Shell.getRootManager()) {
case "Magisk":
return modFS("MSUINI", adds);
case "KernelSU":
return modFS("KSUINI", adds);
case "APatchSU":
return modFS("ASUINI", adds);
default:
return `exit ${Shell.M_DWL_FAILURE}`;
}
}, []);

const [downloadProgress, setDownloadProgress] = React.useState(0);

const install = () => {
const { exploreInstall, modSource, id, source, issues } = extra;

if (exploreInstall) {
const url = modSource[0];
const urls = modSource;
// const urls = modSource;

const explore_install = new Terminal({
cwd: "/data/local/tmp",
printError: settings.print_terminal_error,
});
const modPath = `${TMPDIR}/${uuidv1()}.zip`;

explore_install.env = {
ASH_STANDALONE: "1",
MMRL: "true",
MMRL_INTR: "true",
MMRL_VER: BuildConfig.VERSION_CODE.toString(),
NAME: id,
ROOTMANAGER: Shell.getRootManager(),
...__modFS,
};
const dl = new Download(url, modPath);

explore_install.onLine = (line) => {
addText(line);
};
dl.onChange = (obj) => {
switch (obj.type) {
case "downloading":
setDownloadProgress(obj.state);
setLastLine(`- Downlaoding module progress: ${obj.state}%`);
break;
case "finished":
setDownloadProgress(0);

explore_install.onExit = (code) => {
switch (code) {
case Shell.M_INS_SUCCESS:
addText(" ");
addText(
"\x1b[93mYou can press the \x1b[33;4mbutton\x1b[93;0m\x1b[93m below to \x1b[33;4mreboot\x1b[93;0m\x1b[93m your device\x1b[0m"
);
addButton("Reboot", {
startIcon: <RestartAlt />,
onClick: rebootDevice,
const explore_install = new Terminal({
cwd: TMPDIR,
printError: settings.print_terminal_error,
});
addText(
"\x1b[2mModules that causes issues after installing belog not to \x1b[35;4mMMRL\x1b[0;2m!\nPlease report these issues to thier support page\x1b[2m"
);
if (issues) {
addText(`> \x1b[32mIssues: \x1b[33m${issues}\x1b[0m`);
}
if (source) {
addText(`> \x1b[32mSource: \x1b[33m${source}\x1b[0m`);
}
setActive(false);
break;
case Shell.M_INS_FAILURE:
addText(" ");
addText(
"\x1b[2mModules that causes issues after installing belog not to \x1b[35;4mMMRL\x1b[0;2m!\nPlease report these issues to thier support page\x1b[2m"

explore_install.env = {
ASH_STANDALONE: "1",
MMRL: "true",
MMRL_INTR: "true",
MMRL_VER: BuildConfig.VERSION_CODE.toString(),
ROOTMANAGER: Shell.getRootManager(),
};

explore_install.onLine = (line) => {
addText(line);
};

explore_install.onExit = (code) => {
switch (code) {
case Shell.M_INS_SUCCESS:
addText(" ");
addText(
"\x1b[93mYou can press the \x1b[33;4mbutton\x1b[93;0m\x1b[93m below to \x1b[33;4mreboot\x1b[93;0m\x1b[93m your device\x1b[0m"
);
addButton("Reboot", {
startIcon: <RestartAlt />,
onClick: rebootDevice,
});
addText(
"\x1b[2mModules that causes issues after installing belog not to \x1b[35;4mMMRL\x1b[0;2m!\nPlease report these issues to thier support page\x1b[2m"
);
if (issues) {
addText(`> \x1b[32mIssues: \x1b[33m${issues}\x1b[0m`);
}
if (source) {
addText(`> \x1b[32mSource: \x1b[33m${source}\x1b[0m`);
}
setActive(false);
break;
case Shell.M_INS_FAILURE:
addText(" ");
addText(
"\x1b[2mModules that causes issues after installing belog not to \x1b[35;4mMMRL\x1b[0;2m!\nPlease report these issues to thier support page\x1b[2m"
);
if (issues) {
addText(`> \x1b[32mIssues: \x1b[33m${issues}\x1b[0m`);
}
if (source) {
addText(`> \x1b[32mSource: \x1b[33m${source}\x1b[0m`);
}
setActive(false);
break;
case Shell.TERM_INTR_ERR:
addText("! \x1b[31mInternal error!\x1b[0m");
setActive(false);
break;
default:
addText("? Unknown code returned");
setActive(false);
break;
}
};

explore_install.exec(
getInstallCLI({
ZIPFILE: modPath,
})
);
if (issues) {
addText(`> \x1b[32mIssues: \x1b[33m${issues}\x1b[0m`);
}
if (source) {
addText(`> \x1b[32mSource: \x1b[33m${source}\x1b[0m`);
}
setActive(false);
break;
case Shell.TERM_INTR_ERR:
addText("! \x1b[31mInternal error!\x1b[0m");
setActive(false);
break;
default:
addText("? Unknown code returned");
setActive(false);

break;
}
};

explore_install.exec(
modFS("EXPLORE_INSTALL", {
URL: url,
URLS: urls,
MODID: id,
})
);
dl.onError = (err) => {
setDownloadProgress(0);
addText("! \x1b[31mUnable to download the module\x1b[0m");
addText("! \x1b[31mERR: " + err + "\x1b[0m");
setActive(false);
};

dl.start();
} else {
const zipfile = modSource[0];
const zipfiles = modSource;
// const zipfiles = modSource;

const local_install = new Terminal({
cwd: "/data/local/tmp",
cwd: TMPDIR,
printError: settings.print_terminal_error,
});

Expand All @@ -381,9 +428,7 @@ export const InstallTerminalV2Activity = () => {
MMRL: "true",
MMRL_INTR: "true",
MMRL_VER: BuildConfig.VERSION_CODE.toString(),
NAME: id,
ROOTMANAGER: Shell.getRootManager(),
...__modFS,
};

local_install.onLine = (line) => {
Expand Down Expand Up @@ -434,19 +479,30 @@ export const InstallTerminalV2Activity = () => {
};

local_install.exec(
modFS("LOCAL_INSTALL", {
getInstallCLI({
ZIPFILE: zipfile,
ZIPFILES: zipfiles,
})
);
}
};

const renderToolbar = () => {
return (
<Toolbar modifier="noshadow">
<Toolbar
modifier="noshadow"
sx={{
position: "relative !important",
}}
>
<Toolbar.Left>{!active && <Toolbar.BackButton onClick={context.popPage} />}</Toolbar.Left>
<Toolbar.Center>Install</Toolbar.Center>
{downloadProgress !== 0 && (
<LinearProgress
sx={{ width: "100%", left: 0, right: 0, position: "absolute", bottom: 0 }}
variant="determinate"
value={downloadProgress}
/>
)}
</Toolbar>
);
};
Expand Down
Loading

0 comments on commit 68065bb

Please sign in to comment.