Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.

Commit 45b73a8

Browse files
committed
improve chromium apps patch
1 parent 3d5e16a commit 45b73a8

7 files changed

Lines changed: 113 additions & 64 deletions

File tree

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ async function main(){
3131
await check_update();
3232
if(!isRoot()) console.log("Please run as sudo to detect apps that's not patched.");
3333

34+
global.chromiumApps = [];
35+
3436
const cli = new CommandLine();
3537
await cli.start();
3638
}

src/app.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@ export default class App {
1313
constructor(path: string) {
1414
this.path = path;
1515
this.name = path.split("/").pop()!.replace(/.app/g, '');
16-
17-
global.electronApps = [];
1816
this.appPatches = [
19-
new Chromium(path),
2017
new Amdfriend(path),
2118
new Discord(path),
2219
new Firefox(path),
2320
new FirefoxDev(path),
2421
];
22+
if(global.commandlineChromiumMode){
23+
this.appPatches = [new Chromium(path)];
24+
}
25+
}
26+
getAppPatch(): AppPatch {
27+
for(const app of this.appPatches){
28+
if(!app.supported()) continue;
29+
return app;
30+
}
2531
}
2632
async patch() {
2733
for(const app of this.appPatches){

src/commandline.ts

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import inquirer from "inquirer";
55
import clear from "console-clear";
66
import path from "path";
77
import {PatchType} from "@src/types";
8+
import Chromium, { bashPath, patchChromiumApps, removePatchChromiumApps } from "./patches/chromium";
9+
import { exec } from "./utils";
10+
import child_process from "child_process";
811

912
export default class CommandLine {
1013
basePath = "/Applications/";
@@ -15,9 +18,19 @@ export default class CommandLine {
1518

1619
console.log(`Applications that can be patched:`)
1720
this.logSupportedApps();
18-
console.log("\n(A) Patch all apps")
19-
console.log(`(G) ${global.disableGpuMode ? "Disable" : "Enable"} disable-gpu-rasterization patch instead of disableBlendFuncExtended`)
20-
console.log(`(E) ${global.patchElectronApps ? "Disable" : "Enable"} patch Electron apps (${chalk.rgb(255,99,71)("EXPERIMENTAL")})`)
21+
console.log("");
22+
if(global.commandlineChromiumMode){
23+
if (global.disableGpuMode) {
24+
console.log(`(G) Use disableBlendFuncExtended patch instead of disable-gpu-rasterization`)
25+
} else {
26+
console.log(`(G) Use disable-gpu-rasterization patch instead of disableBlendFuncExtended`)
27+
}
28+
if(global.chromiumApps.length > 0) console.log("(P) Patch selected chromium apps.")
29+
console.log("(R) Remove chromium apps patch")
30+
} else {
31+
console.log("(A) Patch all apps")
32+
}
33+
console.log(`(C) ${global.commandlineChromiumMode ? "Exit" : "Enter"} Chromium apps mode (${chalk.rgb(255,99,71)("EXPERIMENTAL")})`)
2134
console.log("(Q) Quit")
2235

2336
// @ts-ignore
@@ -33,19 +46,52 @@ export default class CommandLine {
3346
console.log("Bye!");
3447
process.exit();
3548
break;
36-
case "e":
37-
global.patchElectronApps = !global.patchElectronApps;
49+
case "c":
50+
global.commandlineChromiumMode = !global.commandlineChromiumMode;
3851
break;
3952
case "g":
4053
global.disableGpuMode = !global.disableGpuMode;
4154
break;
4255
case "a":
43-
await this.patchAllApps();
44-
break;
56+
if(!global.commandlineChromiumMode){
57+
await this.patchAllApps();
58+
break;
59+
}
60+
case "p":
61+
if(global.chromiumApps.length > 0){
62+
console.log("Applying chromium apps patch...")
63+
64+
const macosVersion = (await exec("sw_vers -productVersion")).stdout;
65+
const majorVersion = parseInt(macosVersion.split(".")[0]);
66+
const minorVersion = parseInt(macosVersion.split(".")[1]);
67+
if(majorVersion > 13 && minorVersion > 3){
68+
console.log("You are running on MacOS Sonoma 14.3.1 or above. Please restart or run the command below to start.");
69+
console.log(`bash ${bashPath} &`)
70+
} else {
71+
child_process.spawn("bash", [bashPath], { stdio: "ignore", detached: true }).unref();
72+
}
73+
74+
patchChromiumApps();
75+
break;
76+
}
77+
case "r":
78+
if(global.commandlineChromiumMode){
79+
removePatchChromiumApps();
80+
break;
81+
}
4582
default:
4683
const val = parseInt(value);
47-
if(!isNaN(val) && val <= this.supportedApps.length + 1 && val > 0)
48-
await this.supportedApps[val-1].patch()
84+
if (isNaN(val) || val < 1 || val > this.supportedApps.length + 1) break;
85+
const app = this.supportedApps[val - 1];
86+
87+
if (global.commandlineChromiumMode) {
88+
// @ts-ignore
89+
const appPatch: Chromium = app.getAppPatch();
90+
if(appPatch.selected()) break;
91+
global.chromiumApps.push(app);
92+
} else {
93+
await app.patch()
94+
}
4995
}
5096

5197
const cli = new CommandLine();
@@ -73,6 +119,9 @@ export default class CommandLine {
73119
case PatchType.EXPERIMENTAL:
74120
status = chalk.rgb(255,99,71)("EXPERIMENTAL");
75121
break;
122+
case PatchType.SELECTED:
123+
status = chalk.cyan("SELECTED");
124+
break;
76125
default: status = chalk.yellow("UNDETECTED");
77126
}
78127

src/globals.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import App from "./app";
2+
3+
export {}
4+
5+
declare global {
6+
var commandlineChromiumMode: boolean;
7+
var disableGpuMode: boolean;
8+
var chromiumApps: App[];
9+
}

src/patches/chromium.ts

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ interface ChromiumConfig {
1919
}
2020

2121
const chromiumBrowsers = ["Chromium", "Google Chrome", "Arc", "Microsoft Edge", "Brave"];
22+
export const bashPath = path.join("/", "Library", "amdhelper", amdhelperChromiumBashName);
23+
export const plistPath = path.join("/", "Library", "LaunchAgents", amdhelperChromiumPlistName);
2224

2325
export default class Chromium extends AppPatch {
2426
configPath: string | null = null;
2527
// patchValue = "use-angle@1";
2628
oldPatchValues = ["enable-gpu-rasterization@1", "enable-gpu-rasterization@2"];
27-
bashPath = path.join("/", "Library", "amdhelper", amdhelperChromiumBashName);
28-
plistPath = path.join("/", "Library", "LaunchAgents", amdhelperChromiumPlistName);
2929
config: ChromiumConfig;
3030
constructor(appPath: string) {
3131
super(appPath);
@@ -59,47 +59,20 @@ export default class Chromium extends AppPatch {
5959
}
6060
supported() {
6161
return (chromiumBrowsers.includes(this.appName) && this.configPath != null) ||
62-
(global.patchElectronApps && this.supportElectron());
62+
this.supportElectron();
6363
}
6464
supportElectron(){
6565
return fs.existsSync(path.join("/Applications", `${this.appName}.app`, "Contents", "Frameworks", "Electron Framework.framework"))
6666
}
67+
selected(): boolean {
68+
return global.chromiumApps.findIndex(fapp => fapp.name === this.appName) !== -1
69+
}
6770
patched() {
71+
if(this.selected()) return PatchType.SELECTED;
6872
if(this.isOldPatch()) return PatchType.OLD_PATCH;
6973
if(this.supportElectron()) return PatchType.EXPERIMENTAL;
70-
return fs.existsSync(this.bashPath) ?
71-
PatchType.PATCHED : PatchType.UNPATCHED;
72-
// return (fs.existsSync(this.bashPath) && this.config.browser !== undefined &&
73-
// this.config.browser.enabled_labs_experiments !== undefined &&
74-
// this.config.browser.enabled_labs_experiments.includes(this.patchValue))
75-
// ? PatchType.PATCHED : PatchType.UNPATCHED;
74+
return fs.existsSync(bashPath) ? PatchType.PATCHED : PatchType.UNPATCHED;
7675
}
77-
async patch(){
78-
// if(this.configPath == undefined || this.config == null){
79-
// console.error(`Can't apply patch to ${this.appName}! Config not found.`)
80-
// return;
81-
// }
82-
83-
if(this.isOldPatch()) this.removeOldPatch();
84-
85-
// if(this.patched()){
86-
// console.log(`${this.appName} already patched. Ignoring...`);
87-
// return;
88-
// }
89-
90-
console.log(`Applying patch to ${this.appName}...`);
91-
if(global.electronApps.indexOf(this.appName) === -1) global.electronApps.push(this.appName);
92-
93-
// this.apply();
94-
// this.save();
95-
await this.addLaunchAgent();
96-
}
97-
// apply(){
98-
// if(this.config.browser === undefined) this.config.browser = { enabled_labs_experiments: [] };
99-
// if(this.config.browser.enabled_labs_experiments === undefined) this.config.browser.enabled_labs_experiments = [];
100-
// this.config.browser!.enabled_labs_experiments.push(this.patchValue);
101-
// console.log(`Patch applied to ${this.appName}!`)
102-
// }
10376
save(){
10477
fs.writeFileSync(this.configPath!, JSON.stringify(this.config));
10578
}
@@ -108,27 +81,36 @@ export default class Chromium extends AppPatch {
10881
this.config.browser.enabled_labs_experiments !== undefined &&
10982
this.config.browser.enabled_labs_experiments.some(value => this.oldPatchValues.includes(value)))
11083
}
111-
async addLaunchAgent(){
112-
try {
113-
await exec(`pkill -f bash`);
114-
} catch {}
115-
116-
let apps = chromiumBrowsers;
117-
if(global.patchElectronApps) apps.push(...global.electronApps);
118-
119-
fs.mkdirSync(path.join(this.bashPath, ".."), { recursive: true });
120-
fs.writeFileSync(this.bashPath, amdhelperChromiumBash(apps, global.disableGpuMode));
121-
await exec(`sudo chmod +x ${escapePathSpaces(this.bashPath)}`);
122-
123-
fs.writeFileSync(this.plistPath, amdhelperChromiumPlist);
124-
child_process.spawn("bash", [this.bashPath], { detached: true });
125-
}
12684
removeOldPatch(){
85+
if (!this.isOldPatch()) return;
12786
if(this.config.browser === undefined) return;
12887
if(this.config.browser.enabled_labs_experiments === undefined) return;
12988
this.config.browser!.enabled_labs_experiments =
13089
this.config.browser!.enabled_labs_experiments.filter(val => !this.oldPatchValues.includes(val));
13190
this.save();
13291
console.log(`Removing old patch from ${this.appName}!`)
13392
}
93+
}
94+
95+
async function killPatchProcess(){
96+
try { await exec(`pkill -f bash`) } catch {}
97+
try { await exec(`pkill -f amdhelper_chromium`) } catch {}
98+
}
99+
100+
export async function patchChromiumApps(){
101+
killPatchProcess();
102+
const apps = global.chromiumApps.map(app => app.name);
103+
104+
fs.mkdirSync(path.join(bashPath, ".."), { recursive: true });
105+
fs.writeFileSync(bashPath, amdhelperChromiumBash(apps, global.disableGpuMode));
106+
await exec(`sudo chmod +x ${escapePathSpaces(bashPath)}`);
107+
108+
fs.writeFileSync(plistPath, amdhelperChromiumPlist);
109+
}
110+
111+
export async function removePatchChromiumApps(){
112+
console.log("Removing chromium apps patch...");
113+
killPatchProcess();
114+
try { fs.rmSync(bashPath) } catch {}
115+
try { fs.rmSync(plistPath) } catch {}
134116
}

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export enum PatchType {
33
UNPATCHED = 0,
44
UNDETECTED = -1,
55
OLD_PATCH = -2,
6-
EXPERIMENTAL = -3
6+
EXPERIMENTAL = -3,
7+
SELECTED = -4,
78
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
},
2828
"include": [
2929
"index.ts",
30+
"src/globals.d.ts",
3031
"src/**/*.ts",
31-
"src/globals.d.ts"
3232
],
3333
"exclude": [
3434
"node_modules",

0 commit comments

Comments
 (0)