Skip to content

Commit

Permalink
readable condition
Browse files Browse the repository at this point in the history
  • Loading branch information
alvindimas05 committed Aug 25, 2024
1 parent 3f8a523 commit 78571d1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 deletions.
7 changes: 5 additions & 2 deletions src/commandline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import inquirer from "inquirer";
// @ts-ignore
import clear from "console-clear";
import path from "path";
import {PatchType} from "@src/types";


export default class CommandLine {
basePath = "/Applications/";
Expand Down Expand Up @@ -53,12 +55,13 @@ export default class CommandLine {
logSupportedApps(){
this.supportedApps.forEach((app, i) => {
let status: string;

switch(app.patched()){
case 1:
case PatchType.PATCHED:
// @ts-ignore
status = chalk.green("PATCHED");
break;
case 0:
case PatchType.UNPATCHED:
// @ts-ignore
status = chalk.red("NOT PATCHED");
break;
Expand Down
7 changes: 4 additions & 3 deletions src/patches/amdfriend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {PatchOptions} from "amdfriend/src/types";
import {patchFile} from "amdfriend/src";
import {isRoot, patchOptions} from "@src/utils";
import AppPatch from "@patches/apppatch";
import {PatchType} from "@src/types";

const amdfriends = ["Adobe Photoshop", "CorelDRAW"];

Expand All @@ -18,14 +19,14 @@ export default class Amdfriend extends AppPatch {
}
patched() {
const fileExists = fs.existsSync(this.patchedPath);
if(!isRoot() && !fileExists) return -1;
return (fileExists ? 1 : 0);
if(!isRoot() && !fileExists) return PatchType.UNDETECTED;
return (fileExists ? PatchType.PATCHED : PatchType.UNPATCHED);
}
supported(){
return amdfriends.some(v => this.appName.includes(v) || v.includes(this.appName));
}
async patch(){
if(this.patched() === 1) return console.log(`${this.appName} already patched. Ignoring...`);
if(this.patched() === PatchType.PATCHED) return console.log(`${this.appName} already patched. Ignoring...`);
await parallelizer(this.patchDirectories(), cpus().length);

if(!isRoot()) fs.writeFileSync(this.patchedPath, "");
Expand Down
4 changes: 3 additions & 1 deletion src/patches/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import os from "os";
import fs from "fs";
import AppPatch from "@patches/apppatch";
import {PatchType} from "@src/types";

interface ChromiumConfig {
browser?: {
Expand Down Expand Up @@ -51,7 +52,8 @@ export default class Chromium extends AppPatch {
patched() {
return (this.config.browser !== undefined &&
this.config.browser.enabled_labs_experiments !== undefined &&
this.config.browser.enabled_labs_experiments.includes(this.patchValue)) ? 1 : 0;
this.config.browser.enabled_labs_experiments.includes(this.patchValue)) ?
PatchType.PATCHED : PatchType.UNPATCHED;
}
patch(){
if(this.configPath == undefined || this.config == undefined){
Expand Down
3 changes: 2 additions & 1 deletion src/patches/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {homedir} from "os";
import {isRoot, patchOptions, searchFile} from "@src/utils";
import fs from "fs";
import {patchFile} from "amdfriend/src";
import {PatchType} from "@src/types";

const discordPath = path.join(homedir(), "Library", "Application Support", "discord")
export default class Discord extends AppPatch {
Expand All @@ -24,7 +25,7 @@ export default class Discord extends AppPatch {
}
patched() {
const fileExists = fs.existsSync(this.patchedPath);
return (fileExists ? 1 : 0);
return (fileExists ? PatchType.PATCHED : PatchType.UNPATCHED);
}
supported(): boolean {
return this.appName === "Discord";
Expand Down
23 changes: 3 additions & 20 deletions src/patches/firefox-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,15 @@ import AppPatch from "@patches/apppatch";
import path from "path";
import {homedir} from "os";
import fs from "fs";
import Firefox from "@patches/firefox";

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
export default class FirefoxDev extends Firefox {
constructor(appName: string) {
super(appName);
if(this.pathExists(firefoxPath)){
fs.readdirSync(firefoxPath).forEach(dir => {
if(dir.endsWith(".dev-edition-default")){
this.prefPath = path.join(firefoxPath, dir, "prefs.js");
}
});
}
this.setPrefPath(".dev-edition-default")
}
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);
}
}
18 changes: 12 additions & 6 deletions src/patches/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ import AppPatch from "@patches/apppatch";
import path from "path";
import {homedir} from "os";
import fs from "fs";
import {PatchType} from "@src/types";

const firefoxPath = path.join(homedir(), "Library", "Application Support", "Firefox", "Profiles")
const patchCode = "user_pref(\"layers.acceleration.disabled\", true);"
export default class Firefox extends AppPatch {
firefoxPath: string
prefPath: string
constructor(appName: string) {
super(appName);

if(this.pathExists(firefoxPath)){
fs.readdirSync(firefoxPath).forEach(dir => {
if(dir.endsWith(".default-release")){
this.prefPath = path.join(firefoxPath, dir, "prefs.js");
this.firefoxPath = firefoxPath;
this.setPrefPath(".default-release")
}
setPrefPath(dirname: string){
if(this.pathExists(this.firefoxPath)){
fs.readdirSync(this.firefoxPath).forEach(dir => {
if(dir.endsWith(dirname)){
this.prefPath = path.join(this.firefoxPath, dir, "prefs.js");
}
});
}
Expand All @@ -23,10 +29,10 @@ export default class Firefox extends AppPatch {
}
patched() {
let pref = fs.readFileSync(this.prefPath, "utf8");
return pref.includes("user_pref(\"layers.acceleration.disabled\", true);") ? 1 : 0;
return pref.includes("user_pref(\"layers.acceleration.disabled\", true);") ? PatchType.PATCHED : PatchType.UNPATCHED;
}
patch() {
if(this.patched() === 1) return console.log(`${this.appName} already patched. Ignoring...`);
if(this.patched() === PatchType.PATCHED) return console.log(`${this.appName} already patched. Ignoring...`);
let pref = fs.readFileSync(this.prefPath, "utf8");
pref += "\n" + patchCode;
fs.writeFileSync(this.prefPath, pref);
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum PatchType {
PATCHED = 1,
UNPATCHED = 0,
UNDETECTED = -1
}

0 comments on commit 78571d1

Please sign in to comment.