Skip to content

Commit

Permalink
make workarounds for install scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Sep 16, 2024
1 parent e93772b commit f44ff46
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
27 changes: 23 additions & 4 deletions src/activitys/InstallTerminalV2Activity/hooks/useLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useModFS } from "@Hooks/useModFS";
import { useStrings } from "@Hooks/useStrings";
import Button from "@mui/material/Button";
import { Shell } from "@Native/Shell";
import { SuFile } from "@Native/SuFile";
import { path } from "@Util/path";
import { useConfirm } from "material-ui-confirm";
import ModFS from "modfs";
import React from "react";
Expand Down Expand Up @@ -69,7 +71,7 @@ interface LinesProviderProps extends React.PropsWithChildren {}

const LinesProvider = (props: LinesProviderProps) => {
const { strings } = useStrings();
const { modFS } = useModFS();
const { modFS, modFSParse } = useModFS();
const [useInt, setUseInt] = React.useState(false);
const [lines, setLines] = React.useState<any[]>([]);
const confirm = useConfirm();
Expand Down Expand Up @@ -201,13 +203,30 @@ const LinesProvider = (props: LinesProviderProps) => {
}, []);

const getInstallCLI = React.useCallback((adds?: Record<string, any>) => {
const __adds = {
...adds,
findBinary(binaryNames: string, args: string) {
const folders = ["/system/bin", "<ADB>/ksu/bin", "<ADB>/ap/bin", "<ADB>/magisk"];
const _binaryNames = binaryNames.split(",");
for (const binaryName of _binaryNames) {
for (const folder of folders) {
const binaryPath = path.join(folder, binaryName);
if (SuFile.exist(binaryPath)) {
return `${binaryPath} ${args}`;
}
}
}
return null;
},
};

switch (Shell.getRootManager()) {
case "Magisk":
return modFS("MSUINI", adds);
return modFS("MSUINI", __adds);
case "KernelSU":
return modFS("KSUINI", adds);
return modFS("KSUINI", __adds);
case "APatchSU":
return modFS("ASUINI", adds);
return modFS("ASUINI", __adds);
default:
return `exit ${Shell.M_DWL_FAILURE}`;
}
Expand Down
11 changes: 7 additions & 4 deletions src/hooks/useModFS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export interface ModFS {

export const INITIAL_MOD_CONF: ModFS = {
//cli
MSUINI: 'command -v <ADB>/magisk/magisk64 && <ADB>/magisk/magisk64 --install-module "<ZIPFILE>" || <ADB>/magisk/magisk32 --install-module "<ZIPFILE>"',
KSUINI: '<ADB>/ksu/bin/ksud module install "<ZIPFILE>"',
ASUINI: '<ADB>/ap/bin/apd module install "<ZIPFILE>"',
MSUINI: '<findBinary=(magisk,magisk64,magisk32|--install-module "<ZIPFILE>")>',
KSUINI: '<findBinary=(ksud|module install "<ZIPFILE>")>',
ASUINI: '<findBinary=(apd|module install "<ZIPFILE>")>',

// default paths
ADB: "/data/adb",
Expand Down Expand Up @@ -99,12 +99,14 @@ export interface ModConfContext {
_modFS: ModFS;
__modFS: ModFS;
modFS<K extends keyof ModFS>(key: K, adds?: Record<string, any>): ModFS[K];
modFSParse: (text: string, adds?: ModFS | object) => string;
setModFS<K extends keyof ModFS>(key: K, state: SetStateAction<ModFS[K]>): void;
}

export const ModConfContext = createContext<ModConfContext>({
_modFS: INITIAL_MOD_CONF,
__modFS: INITIAL_MOD_CONF,
modFSParse: (text: string, adds?: ModFS | object) => "",
modFS<K extends keyof ModFS>(key: K, adds?: Record<string, any>) {
return key;
},
Expand All @@ -116,14 +118,15 @@ export const useModFS = () => {
};

export const ModFSProvider = (props: React.PropsWithChildren) => {
const [modFS, setModFS] = useNativeFileStorage("/data/adb/mmrl/modfs.v6.json", INITIAL_MOD_CONF, { loader: "json" });
const [modFS, setModFS] = useNativeFileStorage("/data/adb/mmrl/modfs.v8.json", INITIAL_MOD_CONF, { loader: "json" });

const pmodFS = React.useMemo(() => new PModFS(defaultComposer(INITIAL_MOD_CONF, modFS)), [modFS]);

const contextValue = React.useMemo(
() => ({
_modFS: defaultComposer(INITIAL_MOD_CONF, modFS),
__modFS: pmodFS.formatEntries(),
modFSParse: (text: string, adds?: ModFS | object) => PModFS.format(text, { ...modFS, ...adds }),
modFS<K extends keyof ModFS>(key: K, adds: ModFS | object): ModFS[K] {
return PModFS.format(pmodFS.get(key)!, { ...modFS, ...adds });
},
Expand Down

0 comments on commit f44ff46

Please sign in to comment.