Skip to content

Commit

Permalink
fix async patch
Browse files Browse the repository at this point in the history
  • Loading branch information
alvindimas05 committed Aug 25, 2024
1 parent 65def7b commit de9ff3f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
10 changes: 6 additions & 4 deletions src/commandline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -37,7 +37,7 @@ export default class CommandLine {
process.exit();
break;
case "a":
this.patchAllApps();
await this.patchAllApps();
break;
default:
const val = parseInt(value);
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/patches/apppatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/patches/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/patches/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de9ff3f

Please sign in to comment.