Skip to content

Commit

Permalink
finish multi module install
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Sep 7, 2024
1 parent 07b9970 commit 2b51273
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 157 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/dergoogler/mmrl/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public void onGlobalLayout() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
switch (consoleMessage.messageLevel()) {
case TIP -> Log.i("MMRLWebViewClient", consoleMessage.message());
case LOG -> Log.d("MMRLWebViewClient", consoleMessage.message());
case LOG -> Log.i("MMRLWebViewClient", consoleMessage.message());
case DEBUG -> 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());
Expand Down
132 changes: 75 additions & 57 deletions src/activitys/InstallTerminalV2Activity/hooks/useExploreInstall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,33 @@ import { useSettings } from "@Hooks/useSettings";
import { Terminal } from "@Native/Terminal";
import { BuildConfig } from "@Native/BuildConfig";
import { Shell } from "@Native/Shell";
import { Add, Remove, CodeRounded, ArrowBackIosRounded, RestartAlt } from "@mui/icons-material";
import { RestartAlt } from "@mui/icons-material";
import { SuFile } from "@Native/SuFile";

const useExploreInstall = (): [() => void, number] => {
const TMPDIR = "/data/local/tmp";
type ExploreInstall = {
url: string;
printExit?: boolean;
};

const useExploreInstall = (): [(options: ExploreInstall) => Promise<void>, number] => {
const TMPDIR = "/data/local/tmp";
const { extra } = useActivity<TerminalActivityExtra>();
const [downloadProgress, setDownloadProgress] = React.useState(0);
const [printTerminalError] = useSettings("print_terminal_error");

const { addText, addButton, setLastLine, rebootDevice, getInstallCLI } = useLines();
const { source, issues } = extra;

const { modSource, source, issues } = extra;

return [
() => {
const url = modSource[0];
// const urls = modSource;

const exploreInstaller = async (options: ExploreInstall): Promise<void> => {
return new Promise<void>((resolve, reject) => {
const url = options.url;
const printExit = options.printExit ?? true;
const modPath = `${TMPDIR}/${uuidv1()}.zip`;

console.debug(modPath);

const dl = new Download(url, modPath);

// Handle download progress
dl.onChange = (obj) => {
switch (obj.type) {
case "downloading":
Expand All @@ -52,6 +57,7 @@ const useExploreInstall = (): [() => void, number] => {
ROOTMANAGER: Shell.getRootManager(),
};

// Add terminal line output
explore_install.onLine = (line) => {
addText(line);
};
Expand All @@ -63,67 +69,79 @@ const useExploreInstall = (): [() => void, number] => {
}

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`);
}
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`);
}
break;
case Shell.TERM_INTR_ERR:
addText("! \x1b[31mInternal error!\x1b[0m");
break;
default:
addText("? Unknown code returned");
break;
SuFile.deleteRecursive(modPath);

if (printExit) {
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 belong not to \x1b[35;4mMMRL\x1b[0;2m!\nPlease report these issues to their support page\x1b[2m"
);
if (issues) {
addText(`> \x1b[32mIssues: \x1b[33m${issues}\x1b[0m`);
}
if (source) {
addText(`> \x1b[32mSource: \x1b[33m${source}\x1b[0m`);
}
break;
case Shell.M_INS_FAILURE:
addText(" ");
addText(
"\x1b[2mModules that cause issues after installing belong not to \x1b[35;4mMMRL\x1b[0;2m!\nPlease report these issues to their support page\x1b[2m"
);
if (issues) {
addText(`> \x1b[32mIssues: \x1b[33m${issues}\x1b[0m`);
}
if (source) {
addText(`> \x1b[32mSource: \x1b[33m${source}\x1b[0m`);
}
break;
case Shell.TERM_INTR_ERR:
addText("! \x1b[31mInternal error!\x1b[0m");
break;
default:
addText("? Unknown code returned");
break;
}
}

resolve(); // Resolve the promise once the terminal exits
};

explore_install.exec(
getInstallCLI({
ZIPFILE: modPath,
})
);
try {
// Execute the command but don't expect a return value
explore_install.exec(getInstallCLI({ ZIPFILE: modPath }));
} catch (err) {
addText(`! \x1b[31mExecution error: ${err}\x1b[0m`);
reject(err); // Reject the promise on execution error
}

break;
}
};

// Handle download errors
dl.onError = (err) => {
setDownloadProgress(0);
addText("! \x1b[31mUnable to download the module\x1b[0m");
addText("! \x1b[31mERR: " + err + "\x1b[0m");
reject(err); // Reject the promise on download error
};

// Start the download
dl.start();
},
downloadProgress,
];
});
};

return [exploreInstaller, downloadProgress];
};

export { useExploreInstall };
9 changes: 8 additions & 1 deletion src/activitys/InstallTerminalV2Activity/hooks/useLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface LinesContext {
setLastLine: (text: string, props?: object) => void;
rebootDevice: (reason?: string) => void;
getInstallCLI: (adds?: Record<string, any>) => string;
clearTerminal: () => void;
}

const LinesContext = React.createContext<LinesContext>({
Expand All @@ -30,6 +31,7 @@ const LinesContext = React.createContext<LinesContext>({
getInstallCLI(adds) {
return "exit " + Shell.TERM_INTR_ERR;
},
clearTerminal() {},
});

type IntrCommand = (args: string[], options: Record<string, string>, add: any) => void;
Expand Down Expand Up @@ -212,6 +214,10 @@ const LinesProvider = (props: LinesProviderProps) => {
}
}, []);

const clearTerminal = () => {
setLines([]);
};

const value = React.useMemo(
() => ({
processCommand: processCommand,
Expand All @@ -222,8 +228,9 @@ const LinesProvider = (props: LinesProviderProps) => {
setLastLine: setLastLine,
rebootDevice,
getInstallCLI,
clearTerminal,
}),
[processCommand, lines, setLines, useInt, setUseInt, addButton, addText, setLastLine, rebootDevice, getInstallCLI]
[processCommand, lines, setLines, useInt, setUseInt, addButton, addText, setLastLine, rebootDevice, getInstallCLI, clearTerminal]
);

return <LinesContext.Provider value={value} children={children} />;
Expand Down
Loading

0 comments on commit 2b51273

Please sign in to comment.