diff --git a/src/app.ts b/src/app.ts index 0e536d1..7cb25ef 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,6 +4,7 @@ import AppPatch from "@patches/apppatch"; import Discord from "@patches/discord"; import Firefox from "@patches/firefox"; import FirefoxDev from "@patches/firefox-dev"; +import {PatchType} from "@src/types"; export default class App { path: string; @@ -21,12 +22,17 @@ export default class App { new FirefoxDev(path), ]; } - patch = async () => this.appPatches.forEach(patch => patch.supported() && patch.patch()); + async patch() { + for(const app of this.appPatches){ + if(!app.supported()) continue; + await app.patch() + } + } supported = () => this.appPatches.some(patch => patch.supported()); patched = () => { for(const pch of this.appPatches){ if(pch.supported()) return pch.patched(); } - return -1; + return PatchType.UNDETECTED; } } diff --git a/src/commandline.ts b/src/commandline.ts index 9a37c55..56a3f25 100644 --- a/src/commandline.ts +++ b/src/commandline.ts @@ -26,7 +26,7 @@ export default class CommandLine { // @ts-ignore const answers = await inquirer.prompt([{ type: "input", name: "option", message: "Select option: " }]); - this.selectOption(answers.option); + await this.selectOption(answers.option); } async selectOption(value: string){ clear(); @@ -37,7 +37,7 @@ export default class CommandLine { process.exit(); break; case "a": - this.patchAllApps(); + await this.patchAllApps(); break; default: const val = parseInt(value); @@ -49,8 +49,10 @@ export default class CommandLine { const cli = new CommandLine(); await cli.start(); } - patchAllApps(){ - this.supportedApps.forEach(app => app.patch()); + async patchAllApps(){ + for(const app of this.supportedApps){ + await app.patch(); + } } logSupportedApps(){ this.supportedApps.forEach((app, i) => { diff --git a/src/patches/apppatch.ts b/src/patches/apppatch.ts index 193fc53..8dc6e7f 100644 --- a/src/patches/apppatch.ts +++ b/src/patches/apppatch.ts @@ -11,7 +11,7 @@ export default class AppPatch { patched(): PatchType { throw new Error(`Method "patched" must be implemented on class ${this.constructor.name}`); } - patch() { + async patch() { throw new Error(`Method "patch" must be implemented on class ${this.constructor.name}`); } supported(): boolean { diff --git a/src/patches/chromium.ts b/src/patches/chromium.ts index dddd960..55bf543 100644 --- a/src/patches/chromium.ts +++ b/src/patches/chromium.ts @@ -55,7 +55,7 @@ export default class Chromium extends AppPatch { this.config.browser.enabled_labs_experiments.includes(this.patchValue)) ? PatchType.PATCHED : PatchType.UNPATCHED; } - patch(){ + async patch(){ if(this.configPath == undefined || this.config == undefined){ console.error(`Can't apply patch to ${this.appName}! Config not found.`) return; diff --git a/src/patches/firefox.ts b/src/patches/firefox.ts index 11991f3..9043a75 100644 --- a/src/patches/firefox.ts +++ b/src/patches/firefox.ts @@ -31,7 +31,7 @@ export default class Firefox extends AppPatch { let pref = fs.readFileSync(this.prefPath, "utf8"); return pref.includes("user_pref(\"layers.acceleration.disabled\", true);") ? PatchType.PATCHED : PatchType.UNPATCHED; } - patch() { + async patch() { if(this.patched() === PatchType.PATCHED) return console.log(`${this.appName} already patched. Ignoring...`); let pref = fs.readFileSync(this.prefPath, "utf8"); pref += "\n" + patchCode;