From b2338e15b0740704bc123d0cbf432ee5fb3ec978 Mon Sep 17 00:00:00 2001 From: Alvin Dimas Praditya Date: Thu, 26 Sep 2024 17:34:57 +0700 Subject: [PATCH] improve chromium browsers detection --- src/commandline.ts | 2 +- src/patches/chromium.ts | 20 +++++++++++++++----- src/update.ts | 12 ++++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/commandline.ts b/src/commandline.ts index 942a2d3..42749d4 100644 --- a/src/commandline.ts +++ b/src/commandline.ts @@ -34,7 +34,7 @@ export default class CommandLine { console.log(`(C) ${global.commandlineChromiumMode ? "Exit" : "Enter"} Chromium apps mode (${chalk.rgb(255,99,71)("EXPERIMENTAL")})`) const ryzenadj = new Ryzenadj(); - console.log(`(O) ${ryzenadj.enabled() ? "Remove" : "Apply"} battery optimization (${chalk.rgb(255,99,71)("REQUIRES PASSWORD")})`) + console.log(`(O) ${ryzenadj.enabled() ? "Remove" : "Apply"} battery optimization (${chalk.rgb(255,99,71)("May cause lag and REQUIRES PASSWORD")})`) console.log("(Q) Quit") diff --git a/src/patches/chromium.ts b/src/patches/chromium.ts index 3451716..8eb6b56 100644 --- a/src/patches/chromium.ts +++ b/src/patches/chromium.ts @@ -17,7 +17,7 @@ interface ChromiumConfig { } } -const chromiumBrowsers = ["Chromium", "Google Chrome", "Arc", "Microsoft Edge", "Brave"]; +const chromiumBrowsers = ["Chromium", "Google Chrome", "Arc", "Microsoft Edge", "Brave Browser"]; export const bashPath = path.join("/", "Library", "amdhelper", amdhelperChromiumBashName); export const plistPath = path.join("/", "Library", "LaunchAgents", amdhelperChromiumPlistName); @@ -57,12 +57,22 @@ export default class Chromium extends AppPatch { this.config = JSON.parse(fs.readFileSync(this.configPath).toString("utf8")); } supported() { - return (chromiumBrowsers.includes(this.appName) && this.configPath != null) || - this.supportElectron(); + return chromiumBrowsers.includes(this.appName) || this.isChromiumBrowser() || this.supportElectron(); } supportElectron(){ - return fs.existsSync(path.join("/Applications", `${this.appName}.app`, "Contents", "Frameworks", "Electron Framework.framework")) - || fs.existsSync(path.join("/Applications", `${this.appName}.app`, "Contents", "Frameworks", "Chromium Embedded Framework.framework")); + return fs.existsSync(path.join(this.appPath, "Contents", "Frameworks", "Electron Framework.framework")) + || fs.existsSync(path.join(this.appPath, "Contents", "Frameworks", "Chromium Embedded Framework.framework")); + } + isChromiumBrowser(): boolean { + if (!fs.existsSync(path.join(this.appPath, "Contents", "Frameworks"))) return false; + + const frameworks = fs.readdirSync(path.join(this.appPath, "Contents", "Frameworks")) + for(const framework of frameworks){ + if (!framework.startsWith(this.appName) || !framework.endsWith(".framework")) continue; + return fs.existsSync(path.join(this.appPath, "Contents", "Frameworks", framework, "Helpers", + `${this.appName} Helper (GPU).app`)); + } + return false } selected(): boolean { return global.chromiumApps.findIndex(fapp => fapp.name === this.appName) !== -1 diff --git a/src/update.ts b/src/update.ts index d9cf967..eefd784 100644 --- a/src/update.ts +++ b/src/update.ts @@ -5,10 +5,14 @@ interface UpdateResponse { } export async function check_update(){ - const res = await fetch(process.env.RELEASE_URL); - const data : UpdateResponse[] = await res.json(); - if(data[0].tag_name === process.env.VERSION) return; - console.log(`New update version ${data[0].tag_name}! Run "amdhelper -u" to update.`); + try { + const res = await fetch(process.env.RELEASE_URL); + const data : UpdateResponse[] = await res.json(); + if(data[0].tag_name === process.env.VERSION) return; + console.log(`New update version ${data[0].tag_name}! Run "amdhelper -u" to update.`); + } catch { + console.log("Can't check AMDHelper update...") + } } export async function update(){