@@ -19,13 +19,13 @@ interface ChromiumConfig {
1919}
2020
2121const 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
2325export 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}
0 commit comments