Skip to content

Commit

Permalink
Changes to Shell Class
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Jul 18, 2023
1 parent 48b8f92 commit e4c08b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Website/src/components/DeviceModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const DeviceModule = (props: Props) => {

React.useEffect(() => {
const readProps = SuFile.read(`/data/adb/modules/${module}/module.prop`);
setModuleProps(new Properties(readProps).toObject());
setModuleProps(new Properties(readProps).toObject());
}, []);

React.useEffect(() => {
Expand Down
28 changes: 2 additions & 26 deletions Website/src/native/Magisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class MagiskClass extends Native {
*/
public get VERSION_CODE(): number {
if (this.isAndroid) {
return parseInt(Shell.result("magisk -V"));
return parseInt(Shell.cmd("magisk -V").result());
} else {
return 0;
}
}

public get VERSION_NAME(): string {
if (this.isAndroid) {
return Shell.result("magisk -v");
return Shell.cmd("magisk -v").result();
} else {
return "0:MAGISKSU";
}
Expand All @@ -34,30 +34,6 @@ class MagiskClass extends Native {
return parseInt(version.substring(0, i)) * 1000 + parseInt(version.substring(i + 1)) * 100;
}
}

/**
* Installs an Magisk module from path
* @param path Directory path
*/
public INSTALL_MODULE(path: string): void {
if (this.isAndroid) {
Shell.exec(`magisk --install-module ${path}`);
} else {
console.error("Error installing Magisk module.");
}
}

/**
* Removes all Magisk modules and reboot
* @warn Dangerus usage, keep it private!
*/
private REMOVE_MODULES(): void {
if (this.isAndroid) {
Shell.exec(`magisk --remove-modules`);
} else {
console.error("Error removing Magisk modules.");
}
}
}

export const Magisk: MagiskClass = new MagiskClass();
32 changes: 19 additions & 13 deletions Website/src/native/Shell.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Native } from "./Native";

interface IShell {
interface NativeShell {
/**
* Executes an command without result
*/
Expand All @@ -15,33 +15,39 @@ interface IShell {
isAppGrantedRoot(): boolean;
}

interface IShell {
exec(): void;
result(): string;
}

/**
* Run Shell commands native on Android
*/

class ShellClass extends Native<IShell> {
class ShellClass extends Native<NativeShell> {
private _command: string;
public constructor() {
super();
this._command = "";
this.interfaceName = "__shell__";
}

public exec(cmds: string | string[]): void {
public cmd(cmd: string): this {
this._command = cmd;
return this;
}

public exec(): void {
if (this.isAndroid) {
if (cmds instanceof Array) {
cmds.forEach((cmd) => {
this.getInterface.exec(cmd);
});
} else {
this.getInterface.exec(cmds);
}
this.getInterface.exec(this._command);
}
}

public result(cmd: string): string {
public result(): string {
if (this.isAndroid) {
return this.getInterface.result(cmd);
return this.getInterface.result(this._command);
} else {
return cmd;
return this._command;
}
}

Expand Down

0 comments on commit e4c08b4

Please sign in to comment.