diff --git a/src/activitys/InstallTerminalV2Activity/hooks/useLines.tsx b/src/activitys/InstallTerminalV2Activity/hooks/useLines.tsx index 82bf7cd1..335ea1ad 100644 --- a/src/activitys/InstallTerminalV2Activity/hooks/useLines.tsx +++ b/src/activitys/InstallTerminalV2Activity/hooks/useLines.tsx @@ -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"; @@ -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([]); const confirm = useConfirm(); @@ -201,13 +203,30 @@ const LinesProvider = (props: LinesProviderProps) => { }, []); const getInstallCLI = React.useCallback((adds?: Record) => { + const __adds = { + ...adds, + findBinary(binaryNames: string, args: string) { + const folders = ["/system/bin", "/ksu/bin", "/ap/bin", "/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}`; } diff --git a/src/hooks/useModFS.tsx b/src/hooks/useModFS.tsx index da6ce057..402f37ba 100644 --- a/src/hooks/useModFS.tsx +++ b/src/hooks/useModFS.tsx @@ -52,9 +52,9 @@ export interface ModFS { export const INITIAL_MOD_CONF: ModFS = { //cli - MSUINI: 'command -v /magisk/magisk64 && /magisk/magisk64 --install-module "" || /magisk/magisk32 --install-module ""', - KSUINI: '/ksu/bin/ksud module install ""', - ASUINI: '/ap/bin/apd module install ""', + MSUINI: '")>', + KSUINI: '")>', + ASUINI: '")>', // default paths ADB: "/data/adb", @@ -99,12 +99,14 @@ export interface ModConfContext { _modFS: ModFS; __modFS: ModFS; modFS(key: K, adds?: Record): ModFS[K]; + modFSParse: (text: string, adds?: ModFS | object) => string; setModFS(key: K, state: SetStateAction): void; } export const ModConfContext = createContext({ _modFS: INITIAL_MOD_CONF, __modFS: INITIAL_MOD_CONF, + modFSParse: (text: string, adds?: ModFS | object) => "", modFS(key: K, adds?: Record) { return key; }, @@ -116,7 +118,7 @@ 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]); @@ -124,6 +126,7 @@ export const ModFSProvider = (props: React.PropsWithChildren) => { () => ({ _modFS: defaultComposer(INITIAL_MOD_CONF, modFS), __modFS: pmodFS.formatEntries(), + modFSParse: (text: string, adds?: ModFS | object) => PModFS.format(text, { ...modFS, ...adds }), modFS(key: K, adds: ModFS | object): ModFS[K] { return PModFS.format(pmodFS.get(key)!, { ...modFS, ...adds }); },