-
-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
341 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const log = require('electron-log/main') | ||
|
||
class AutostartManager { | ||
constructor ({ | ||
platform, | ||
windowsStore, | ||
app | ||
}) { | ||
this.platform = platform | ||
this.windowsStore = windowsStore | ||
this.app = app | ||
} | ||
|
||
get autostartEnabled () { | ||
if (this.platform === 'win32') { | ||
if (this.windowsStore) { | ||
return false | ||
} else { | ||
return true | ||
} | ||
} else if (this.platform === 'darwin') { | ||
return true | ||
} else if (this.platform === 'linux') { | ||
return this.autoLaunchStatus() | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
set autostartEnabled (value) { | ||
if (this.platform === 'linux') { | ||
value ? this._linuxAutoLaunch.enable() : this._linuxAutoLaunch.disable() | ||
} else if (process.platform === 'win32' && process.windowsStore) { | ||
value ? this._windowsStoreAutoLaunch.enable() : this._windowsStoreAutoLaunch.disable() | ||
} else { | ||
this.app.setLoginItemSettings({ openAtLogin: value }) | ||
} | ||
log.info(`Stretchly: setting autostart to ${value} on ${this.platform}${this.platform === 'win32' && this.windowsStore ? ' (Windows Store)' : ''}`) | ||
} | ||
|
||
async autoLaunchStatus () { | ||
if (this.platform === 'linux') { | ||
return await this._linuxAutoLaunch.isEnabled() | ||
} else if (this.platform === 'win32' && this.windowsStore) { | ||
return await this._windowsStoreAutoLaunch.isEnabled() | ||
} else { | ||
return Promise.resolve(this.app.getLoginItemSettings().openAtLogin) | ||
} | ||
} | ||
|
||
get _linuxAutoLaunch () { | ||
const AutoLaunch = require('auto-launch') | ||
const stretchlyAutoLaunch = new AutoLaunch({ | ||
name: 'stretchly' | ||
}) | ||
return stretchlyAutoLaunch | ||
} | ||
|
||
get _windowsStoreAutoLaunch () { | ||
const AutoLaunch = require('auto-launch') | ||
const stretchlyAutoLaunch = new AutoLaunch({ | ||
name: 'Stretchly', | ||
path: '33881JanHovancik.stretchly_24fg4m0zq65je!Stretchly', | ||
isHidden: true | ||
}) | ||
return stretchlyAutoLaunch | ||
} | ||
} | ||
|
||
module.exports = AutostartManager | ||
Oops, something went wrong.