@@ -2,19 +2,23 @@ import { remote, ipcRenderer, shell } from 'electron';
2
2
import { action , observable } from 'mobx' ;
3
3
import moment from 'moment' ;
4
4
import key from 'keymaster' ;
5
- import path from 'path' ;
5
+ // import path from 'path';
6
6
import idleTimer from '@paulcbetts/system-idle-time' ;
7
+ import AutoLaunch from 'auto-launch' ;
7
8
8
9
import Store from './lib/Store' ;
9
10
import Request from './lib/Request' ;
10
11
import { CHECK_INTERVAL } from '../config' ;
11
- import { isMac , isLinux } from '../environment' ;
12
+ import { isMac } from '../environment' ;
12
13
import locales from '../i18n/translations' ;
13
14
import { gaEvent } from '../lib/analytics' ;
14
15
import Miner from '../lib/Miner' ;
15
16
16
17
const { app, powerMonitor } = remote ;
17
18
const defaultLocale = 'en-US' ;
19
+ const autoLauncher = new AutoLaunch ( {
20
+ name : 'Franz' ,
21
+ } ) ;
18
22
19
23
export default class AppStore extends Store {
20
24
updateStatusTypes = {
@@ -41,7 +45,7 @@ export default class AppStore extends Store {
41
45
miner = null ;
42
46
@observable minerHashrate = 0.0 ;
43
47
44
- constructor ( ...args : any ) {
48
+ constructor ( ...args ) {
45
49
super ( ...args ) ;
46
50
47
51
// Register action handlers
@@ -157,28 +161,17 @@ export default class AppStore extends Store {
157
161
ipcRenderer . send ( 'updateAppIndicator' , { indicator } ) ;
158
162
}
159
163
160
- @action _launchOnStartup ( { enable, openInBackground } ) {
164
+ @action _launchOnStartup ( { enable } ) {
161
165
this . autoLaunchOnStart = enable ;
162
166
163
- let settings = {
164
- openAtLogin : enable ,
165
- } ;
166
-
167
- // For Windows
168
- if ( process . platform === 'win32' ) {
169
- settings = Object . assign ( {
170
- openAsHidden : openInBackground ,
171
- path : app . getPath ( 'exe' ) ,
172
- args : [
173
- '--processStart' , `"${ path . basename ( app . getPath ( 'exe' ) ) } "` ,
174
- ] ,
175
- } , settings ) ;
176
-
177
- if ( openInBackground ) {
178
- settings . args . push (
179
- '--process-start-args' , '"--hidden"' ,
180
- ) ;
167
+ try {
168
+ if ( enable ) {
169
+ autoLauncher . enable ( ) ;
170
+ } else {
171
+ autoLauncher . disable ( ) ;
181
172
}
173
+ } catch ( err ) {
174
+ console . warn ( err ) ;
182
175
}
183
176
184
177
gaEvent ( 'App' , enable ? 'enable autostart' : 'disable autostart' ) ;
@@ -287,31 +280,19 @@ export default class AppStore extends Store {
287
280
}
288
281
289
282
async _autoStart ( ) {
290
- if ( ! isLinux ) {
291
- this . _checkAutoStart ( ) ;
292
-
293
- // we need to wait until the settings request is resolved
294
- await this . stores . settings . allSettingsRequest ;
283
+ this . autoLaunchOnStart = await this . _checkAutoStart ( ) ;
295
284
296
- // We don't set autostart on first launch for macOS as disabling
297
- // the option is currently broken
298
- // https://github.com/meetfranz/franz/issues/17
299
- // https://github.com/electron/electron/issues/10880
300
- if ( process . platform === 'darwin' ) return ;
285
+ // we need to wait until the settings request is resolved
286
+ await this . stores . settings . allSettingsRequest ;
301
287
302
- if ( ! this . stores . settings . all . appStarts ) {
303
- this . actions . app . launchOnStartup ( {
304
- enable : true ,
305
- } ) ;
306
- }
288
+ if ( ! this . stores . settings . all . appStarts ) {
289
+ this . actions . app . launchOnStartup ( {
290
+ enable : true ,
291
+ } ) ;
307
292
}
308
293
}
309
294
310
- _checkAutoStart ( ) {
311
- const loginItem = app . getLoginItemSettings ( {
312
- path : app . getPath ( 'exe' ) ,
313
- } ) ;
314
-
315
- this . autoLaunchOnStart = loginItem . openAtLogin ;
295
+ async _checkAutoStart ( ) {
296
+ return autoLauncher . isEnabled ( ) || false ;
316
297
}
317
298
}
0 commit comments