@@ -13,50 +13,23 @@ class AutostartManager {
1313 this . platform = platform
1414 this . windowsStore = windowsStore
1515 this . app = app
16- this . settings = settings
17- this . flatpakPortalManager = new FlatpakPortalManager ( )
1816
19- // Decide the Linux autostart strategy once during construction
20- if ( this . platform === 'linux' ) {
21- if ( insideFlatpak ( ) ) {
22- this . _linuxAutoLaunch = this . _createFlatpakAutostarter ( )
23- } else {
24- this . _linuxAutoLaunch = new AutoLaunch ( { name : 'stretchly' } )
25- }
26- }
27- }
17+ this . isFlatpak = this . platform === 'linux' && insideFlatpak ( )
2818
29- _createFlatpakAutostarter ( ) {
30- return {
31- enable : async ( ) => {
32- try {
33- await this . flatpakPortalManager . initialize ( )
34- await this . flatpakPortalManager . setAutostart ( true )
35- this . settings . set ( 'flatpakAutostart' , true )
36- } catch ( error ) {
37- log . error ( 'Stretchly: Failed to set autostart (enable) via XDG Portal' , error )
38- }
39- } ,
40- disable : async ( ) => {
41- try {
42- await this . flatpakPortalManager . initialize ( )
43- await this . flatpakPortalManager . setAutostart ( false )
44- this . settings . set ( 'flatpakAutostart' , false )
45- } catch ( error ) {
46- log . error ( 'Stretchly: Failed to set autostart (disable) via XDG Portal' , error )
47- }
48- } ,
49- isEnabled : async ( ) => {
50- // XDG portals don't provide a reliable query method, so we read from our cache
51- return Promise . resolve ( this . settings . get ( 'flatpakAutostart' , false ) )
52- }
19+ if ( this . isFlatpak ) {
20+ this . flatpakPortalManager = new FlatpakPortalManager ( settings )
21+ } else if ( this . platform === 'linux' ) {
22+ this . nativeAutoLauncher = new AutoLaunch ( { name : 'stretchly' } )
5323 }
5424 }
5525
5626 async setAutostartEnabled ( value ) {
57- log . info ( `Stretchly: setting autostart to ${ value } on ${ this . platform } ${ this . platform === 'win32' && this . windowsStore ? ' (Windows Store)' : '' } ${ insideFlatpak ( ) && this . platform === 'linux' ? ' (Flatpak)' : '' } ` )
58- if ( this . platform === 'linux' ) {
59- await ( value ? this . _linuxAutoLaunch . enable ( ) : this . _linuxAutoLaunch . disable ( ) )
27+ log . info ( `Stretchly: setting autostart to ${ value } on ${ this . platform } ${ this . platform === 'win32' && this . windowsStore ? ' (Windows Store)' : '' } ${ this . isFlatpak ? ' (Flatpak)' : '' } ` )
28+
29+ if ( this . isFlatpak ) {
30+ await ( value ? this . flatpakPortalManager . enableAutostart ( ) : this . flatpakPortalManager . disableAutostart ( ) )
31+ } else if ( this . platform === 'linux' ) {
32+ await ( value ? this . nativeAutoLauncher . enable ( ) : this . nativeAutoLauncher . disable ( ) )
6033 } else if ( this . platform === 'win32' && this . windowsStore ) {
6134 await ( value ? this . _windowsStoreAutoLaunch . enable ( ) : this . _windowsStoreAutoLaunch . disable ( ) )
6235 } else {
@@ -65,8 +38,10 @@ class AutostartManager {
6538 }
6639
6740 async autoLaunchStatus ( ) {
68- if ( this . platform === 'linux' ) {
69- return await this . _linuxAutoLaunch . isEnabled ( )
41+ if ( this . isFlatpak ) {
42+ return await this . flatpakPortalManager . isAutostartEnabled ( )
43+ } else if ( this . platform === 'linux' ) {
44+ return await this . nativeAutoLauncher . isEnabled ( )
7045 } else if ( this . platform === 'win32' && this . windowsStore ) {
7146 return await this . _windowsStoreAutoLaunch . isEnabled ( )
7247 } else {
0 commit comments