aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/AppStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r--src/stores/AppStore.js84
1 files changed, 29 insertions, 55 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 7dbef985d..ecfd621d3 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -2,19 +2,23 @@ import { remote, ipcRenderer, shell } from 'electron';
2import { action, observable } from 'mobx'; 2import { action, observable } from 'mobx';
3import moment from 'moment'; 3import moment from 'moment';
4import key from 'keymaster'; 4import key from 'keymaster';
5import path from 'path'; 5// import path from 'path';
6import idleTimer from '@paulcbetts/system-idle-time'; 6import idleTimer from '@paulcbetts/system-idle-time';
7import AutoLaunch from 'auto-launch';
7 8
8import Store from './lib/Store'; 9import Store from './lib/Store';
9import Request from './lib/Request'; 10import Request from './lib/Request';
10import { CHECK_INTERVAL } from '../config'; 11import { CHECK_INTERVAL } from '../config';
11import { isMac, isLinux } from '../environment'; 12import { isMac } from '../environment';
12import locales from '../i18n/translations'; 13import locales from '../i18n/translations';
13import { gaEvent } from '../lib/analytics'; 14import { gaEvent } from '../lib/analytics';
14import Miner from '../lib/Miner'; 15import Miner from '../lib/Miner';
15 16
16const { app, getCurrentWindow, powerMonitor } = remote; 17const { app, powerMonitor } = remote;
17const defaultLocale = 'en-US'; 18const defaultLocale = 'en-US';
19const autoLauncher = new AutoLaunch({
20 name: 'Franz',
21});
18 22
19export default class AppStore extends Store { 23export default class AppStore extends Store {
20 updateStatusTypes = { 24 updateStatusTypes = {
@@ -41,7 +45,7 @@ export default class AppStore extends Store {
41 miner = null; 45 miner = null;
42 @observable minerHashrate = 0.0; 46 @observable minerHashrate = 0.0;
43 47
44 constructor(...args: any) { 48 constructor(...args) {
45 super(...args); 49 super(...args);
46 50
47 // Register action handlers 51 // Register action handlers
@@ -112,24 +116,15 @@ export default class AppStore extends Store {
112 setTimeout(window.location.reload, 5000); 116 setTimeout(window.location.reload, 5000);
113 }); 117 });
114 118
115 // Open Dev Tools (even in production mode)
116 key('⌘+ctrl+shift+alt+i, ctrl+shift+alt+i', () => {
117 getCurrentWindow().toggleDevTools();
118 });
119
120 key('⌘+ctrl+shift+alt+pageup, ctrl+shift+alt+pageup', () => {
121 this.actions.service.openDevToolsForActiveService();
122 });
123
124 // Set active the next service 119 // Set active the next service
125 key( 120 key(
126 '⌘+pagedown, ctrl+pagedown, ⌘+shift+tab, ctrl+shift+tab', () => { 121 '⌘+pagedown, ctrl+pagedown, ⌘+tab, ctrl+tab', () => {
127 this.actions.service.setActiveNext(); 122 this.actions.service.setActiveNext();
128 }); 123 });
129 124
130 // Set active the prev service 125 // Set active the prev service
131 key( 126 key(
132 '⌘+pageup, ctrl+pageup, ⌘+tab, ctrl+tab', () => { 127 '⌘+pageup, ctrl+pageup, ⌘+shift+tab, ctrl+shift+tab', () => {
133 this.actions.service.setActivePrev(); 128 this.actions.service.setActivePrev();
134 }); 129 });
135 130
@@ -161,33 +156,24 @@ export default class AppStore extends Store {
161 indicator = '•'; 156 indicator = '•';
162 } else if (unreadDirectMessageCount === 0 && unreadIndirectMessageCount === 0) { 157 } else if (unreadDirectMessageCount === 0 && unreadIndirectMessageCount === 0) {
163 indicator = 0; 158 indicator = 0;
159 } else {
160 indicator = parseInt(indicator, 10);
164 } 161 }
165 162
166 ipcRenderer.send('updateAppIndicator', { indicator }); 163 ipcRenderer.send('updateAppIndicator', { indicator });
167 } 164 }
168 165
169 @action _launchOnStartup({ enable, openInBackground }) { 166 @action _launchOnStartup({ enable }) {
170 this.autoLaunchOnStart = enable; 167 this.autoLaunchOnStart = enable;
171 168
172 let settings = { 169 try {
173 openAtLogin: enable, 170 if (enable) {
174 }; 171 autoLauncher.enable();
175 172 } else {
176 // For Windows 173 autoLauncher.disable();
177 if (process.platform === 'win32') {
178 settings = Object.assign({
179 openAsHidden: openInBackground,
180 path: app.getPath('exe'),
181 args: [
182 '--processStart', `"${path.basename(app.getPath('exe'))}"`,
183 ],
184 }, settings);
185
186 if (openInBackground) {
187 settings.args.push(
188 '--process-start-args', '"--hidden"',
189 );
190 } 174 }
175 } catch (err) {
176 console.warn(err);
191 } 177 }
192 178
193 gaEvent('App', enable ? 'enable autostart' : 'disable autostart'); 179 gaEvent('App', enable ? 'enable autostart' : 'disable autostart');
@@ -296,31 +282,19 @@ export default class AppStore extends Store {
296 } 282 }
297 283
298 async _autoStart() { 284 async _autoStart() {
299 if (!isLinux) { 285 this.autoLaunchOnStart = await this._checkAutoStart();
300 this._checkAutoStart();
301
302 // we need to wait until the settings request is resolved
303 await this.stores.settings.allSettingsRequest;
304 286
305 // We don't set autostart on first launch for macOS as disabling 287 // we need to wait until the settings request is resolved
306 // the option is currently broken 288 await this.stores.settings.allSettingsRequest;
307 // https://github.com/meetfranz/franz/issues/17
308 // https://github.com/electron/electron/issues/10880
309 if (process.platform === 'darwin') return;
310 289
311 if (!this.stores.settings.all.appStarts) { 290 if (!this.stores.settings.all.appStarts) {
312 this.actions.app.launchOnStartup({ 291 this.actions.app.launchOnStartup({
313 enable: true, 292 enable: true,
314 }); 293 });
315 }
316 } 294 }
317 } 295 }
318 296
319 _checkAutoStart() { 297 async _checkAutoStart() {
320 const loginItem = app.getLoginItemSettings({ 298 return autoLauncher.isEnabled() || false;
321 path: app.getPath('exe'),
322 });
323
324 this.autoLaunchOnStart = loginItem.openAtLogin;
325 } 299 }
326} 300}