From bdbe506857ae4636ba6ae2dde63f641cd66966b3 Mon Sep 17 00:00:00 2001 From: Alvin Dimas Praditya Date: Fri, 16 Aug 2024 15:15:21 +0700 Subject: [PATCH] firefox support --- src/app.ts | 6 +++++- src/patches/firefox-dev.ts | 31 +++++++++++++++++++++++++++++++ src/patches/firefox.ts | 31 +++++++++++++++++++++++++++++++ src/update.ts | 3 ++- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/patches/firefox-dev.ts create mode 100644 src/patches/firefox.ts diff --git a/src/app.ts b/src/app.ts index 63f7855..0e536d1 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,6 +2,8 @@ import Chromium from "@patches/chromium"; import Amdfriend from "@patches/amdfriend"; import AppPatch from "@patches/apppatch"; import Discord from "@patches/discord"; +import Firefox from "@patches/firefox"; +import FirefoxDev from "@patches/firefox-dev"; export default class App { path: string; @@ -15,6 +17,8 @@ export default class App { new Chromium(path), new Amdfriend(path), new Discord(path), + new Firefox(path), + new FirefoxDev(path), ]; } patch = async () => this.appPatches.forEach(patch => patch.supported() && patch.patch()); @@ -25,4 +29,4 @@ export default class App { } return -1; } -} \ No newline at end of file +} diff --git a/src/patches/firefox-dev.ts b/src/patches/firefox-dev.ts new file mode 100644 index 0000000..5b02bbe --- /dev/null +++ b/src/patches/firefox-dev.ts @@ -0,0 +1,31 @@ +import AppPatch from "@patches/apppatch"; +import path from "path"; +import {homedir} from "os"; +import fs from "fs"; + +const firefoxPath = path.join(homedir(), "Library", "Application Support", "Firefox", "Profiles") +const patchCode = "user_pref(\"layers.acceleration.disabled\", true);" +export default class FirefoxDev extends AppPatch { + prefPath: string + constructor(appName: string) { + super(appName); + fs.readdirSync(firefoxPath).forEach(dir => { + if(dir.endsWith(".dev-edition-default")){ + this.prefPath = path.join(firefoxPath, dir, "prefs.js"); + } + }); + } + supported(): boolean { + return this.appName === "Firefox Developer Edition"; + } + patched() { + let pref = fs.readFileSync(this.prefPath, "utf8"); + return pref.includes(patchCode) ? 1 : 0; + } + patch() { + if(this.patched() === 1) return console.log(`${this.appName} already patched. Ignoring...`); + let pref = fs.readFileSync(this.prefPath, "utf8"); + pref += "\n" + patchCode; + fs.writeFileSync(this.prefPath, pref); + } +} diff --git a/src/patches/firefox.ts b/src/patches/firefox.ts new file mode 100644 index 0000000..969c59f --- /dev/null +++ b/src/patches/firefox.ts @@ -0,0 +1,31 @@ +import AppPatch from "@patches/apppatch"; +import path from "path"; +import {homedir} from "os"; +import fs from "fs"; + +const firefoxPath = path.join(homedir(), "Library", "Application Support", "Firefox", "Profiles") +const patchCode = "user_pref(\"layers.acceleration.disabled\", true);" +export default class Firefox extends AppPatch { + prefPath: string + constructor(appName: string) { + super(appName); + fs.readdirSync(firefoxPath).forEach(dir => { + if(dir.endsWith(".default-release")){ + this.prefPath = path.join(firefoxPath, dir, "prefs.js"); + } + }); + } + supported(): boolean { + return this.appName === "Firefox"; + } + patched() { + let pref = fs.readFileSync(this.prefPath, "utf8"); + return pref.includes("user_pref(\"layers.acceleration.disabled\", true);") ? 1 : 0; + } + patch() { + if(this.patched() === 1) return console.log(`${this.appName} already patched. Ignoring...`); + let pref = fs.readFileSync(this.prefPath, "utf8"); + pref += "\n" + patchCode; + fs.writeFileSync(this.prefPath, pref); + } +} diff --git a/src/update.ts b/src/update.ts index df8c7a9..d9cf967 100644 --- a/src/update.ts +++ b/src/update.ts @@ -14,7 +14,8 @@ export async function check_update(){ export async function update(){ const curl = await exec(`curl -sL ${process.env.INSTALL_URL}`); for(let cmd of curl.stdout.split("\n")){ + if(cmd.length === 0) return; const { stdout } = await exec(cmd); if(stdout != "") console.log(`${stdout.slice(0, -1)}`); } -} \ No newline at end of file +}