Skip to content

Commit

Permalink
firefox support
Browse files Browse the repository at this point in the history
  • Loading branch information
alvindimas05 committed Aug 16, 2024
1 parent f65ceaa commit bdbe506
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -25,4 +29,4 @@ export default class App {
}
return -1;
}
}
}
31 changes: 31 additions & 0 deletions src/patches/firefox-dev.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
31 changes: 31 additions & 0 deletions src/patches/firefox.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
3 changes: 2 additions & 1 deletion src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
}
}

0 comments on commit bdbe506

Please sign in to comment.