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.js72
1 files changed, 37 insertions, 35 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 162422017..9ad4cd531 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -15,7 +15,11 @@ import { gaEvent } from '../lib/analytics';
15 15
16import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; 16import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js';
17 17
18const { app } = remote; 18const debug = require('debug')('Franz:AppStore');
19
20const { app, systemPreferences } = remote;
21
22const mainWindow = remote.getCurrentWindow();
19 23
20const defaultLocale = DEFAULT_APP_SETTINGS.locale; 24const defaultLocale = DEFAULT_APP_SETTINGS.locale;
21const autoLauncher = new AutoLaunch({ 25const autoLauncher = new AutoLaunch({
@@ -46,8 +50,12 @@ export default class AppStore extends Store {
46 50
47 @observable isSystemMuteOverridden = false; 51 @observable isSystemMuteOverridden = false;
48 52
53 @observable isSystemDarkModeEnabled = false;
54
49 @observable isClearingAllCache = false; 55 @observable isClearingAllCache = false;
50 56
57 @observable isFullScreen = mainWindow.isFullScreen();
58
51 constructor(...args) { 59 constructor(...args) {
52 super(...args); 60 super(...args);
53 61
@@ -80,6 +88,10 @@ export default class AppStore extends Store {
80 window.addEventListener('online', () => { this.isOnline = true; }); 88 window.addEventListener('online', () => { this.isOnline = true; });
81 window.addEventListener('offline', () => { this.isOnline = false; }); 89 window.addEventListener('offline', () => { this.isOnline = false; });
82 90
91 mainWindow.on('enter-full-screen', () => { this.isFullScreen = true; });
92 mainWindow.on('leave-full-screen', () => { this.isFullScreen = false; });
93
94
83 this.isOnline = navigator.onLine; 95 this.isOnline = navigator.onLine;
84 96
85 // Check if Franz should launch on start 97 // Check if Franz should launch on start
@@ -98,6 +110,10 @@ export default class AppStore extends Store {
98 ipcRenderer.on('autoUpdate', (event, data) => { 110 ipcRenderer.on('autoUpdate', (event, data) => {
99 if (data.available) { 111 if (data.available) {
100 this.updateStatus = this.updateStatusTypes.AVAILABLE; 112 this.updateStatus = this.updateStatusTypes.AVAILABLE;
113
114 if (isMac) {
115 app.dock.bounce();
116 }
101 } 117 }
102 118
103 if (data.available !== undefined && !data.available) { 119 if (data.available !== undefined && !data.available) {
@@ -124,19 +140,6 @@ export default class AppStore extends Store {
124 this.stores.router.push(data.url); 140 this.stores.router.push(data.url);
125 }); 141 });
126 142
127 // Reload all services after a healthy nap
128 // Alternative solution for powerMonitor as the resume event is not fired
129 // More information: https://github.com/electron/electron/issues/1615
130 const TIMEOUT = 5000;
131 let lastTime = (new Date()).getTime();
132 setInterval(() => {
133 const currentTime = (new Date()).getTime();
134 if (currentTime > (lastTime + TIMEOUT + 2000)) {
135 this._reactivateServices();
136 }
137 lastTime = currentTime;
138 }, TIMEOUT);
139
140 // Set active the next service 143 // Set active the next service
141 key( 144 key(
142 '⌘+pagedown, ctrl+pagedown, ⌘+alt+right, ctrl+tab', () => { 145 '⌘+pagedown, ctrl+pagedown, ⌘+alt+right, ctrl+tab', () => {
@@ -158,6 +161,8 @@ export default class AppStore extends Store {
158 this.locale = this._getDefaultLocale(); 161 this.locale = this._getDefaultLocale();
159 162
160 this._healthCheck(); 163 this._healthCheck();
164
165 this.isSystemDarkModeEnabled = systemPreferences.isDarkMode();
161 } 166 }
162 167
163 @computed get cacheSize() { 168 @computed get cacheSize() {
@@ -166,7 +171,7 @@ export default class AppStore extends Store {
166 171
167 // Actions 172 // Actions
168 @action _notify({ title, options, notificationId, serviceId = null }) { 173 @action _notify({ title, options, notificationId, serviceId = null }) {
169 if (this.stores.settings.all.isAppMuted) return; 174 if (this.stores.settings.all.app.isAppMuted) return;
170 175
171 const notification = new window.Notification(title, options); 176 const notification = new window.Notification(title, options);
172 notification.onclick = (e) => { 177 notification.onclick = (e) => {
@@ -179,8 +184,6 @@ export default class AppStore extends Store {
179 184
180 this.actions.service.setActive({ serviceId }); 185 this.actions.service.setActive({ serviceId });
181 186
182 const mainWindow = remote.getCurrentWindow();
183
184 if (isWindows) { 187 if (isWindows) {
185 mainWindow.restore(); 188 mainWindow.restore();
186 } else if (isLinux) { 189 } else if (isLinux) {
@@ -244,17 +247,18 @@ export default class AppStore extends Store {
244 } 247 }
245 248
246 @action _muteApp({ isMuted, overrideSystemMute = true }) { 249 @action _muteApp({ isMuted, overrideSystemMute = true }) {
247 this.isSystemMuteOverriden = overrideSystemMute; 250 this.isSystemMuteOverridden = overrideSystemMute;
248 251
249 this.actions.settings.update({ 252 this.actions.settings.update({
250 settings: { 253 type: 'app',
254 data: {
251 isAppMuted: isMuted, 255 isAppMuted: isMuted,
252 }, 256 },
253 }); 257 });
254 } 258 }
255 259
256 @action _toggleMuteApp() { 260 @action _toggleMuteApp() {
257 this._muteApp({ isMuted: !this.stores.settings.all.isAppMuted }); 261 this._muteApp({ isMuted: !this.stores.settings.all.app.isAppMuted });
258 } 262 }
259 263
260 @action async _clearAllCache() { 264 @action async _clearAllCache() {
@@ -288,13 +292,19 @@ export default class AppStore extends Store {
288 } 292 }
289 293
290 _setLocale() { 294 _setLocale() {
291 const locale = this.stores.settings.all.locale; 295 let locale;
296 if (this.stores.user.isLoggedIn) {
297 locale = this.stores.user.data.locale;
298 }
299
292 300
293 if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) { 301 if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) {
294 this.locale = locale; 302 this.locale = locale;
295 } else if (!locale) { 303 } else if (!locale) {
296 this.locale = this._getDefaultLocale(); 304 this.locale = this._getDefaultLocale();
297 } 305 }
306
307 debug(`Set locale to "${this.locale}"`);
298 } 308 }
299 309
300 _getDefaultLocale() { 310 _getDefaultLocale() {
@@ -336,8 +346,9 @@ export default class AppStore extends Store {
336 // Helpers 346 // Helpers
337 _appStartsCounter() { 347 _appStartsCounter() {
338 this.actions.settings.update({ 348 this.actions.settings.update({
339 settings: { 349 type: 'stats',
340 appStarts: (this.stores.settings.all.appStarts || 0) + 1, 350 data: {
351 appStarts: (this.stores.settings.all.stats.appStarts || 0) + 1,
341 }, 352 },
342 }); 353 });
343 } 354 }
@@ -345,7 +356,8 @@ export default class AppStore extends Store {
345 async _autoStart() { 356 async _autoStart() {
346 this.autoLaunchOnStart = await this._checkAutoStart(); 357 this.autoLaunchOnStart = await this._checkAutoStart();
347 358
348 if (this.stores.settings.all.appStarts === 1) { 359 if (this.stores.settings.all.stats.appStarts === 1) {
360 debug('Set app to launch on start');
349 this.actions.app.launchOnStartup({ 361 this.actions.app.launchOnStartup({
350 enable: true, 362 enable: true,
351 }); 363 });
@@ -356,19 +368,9 @@ export default class AppStore extends Store {
356 return autoLauncher.isEnabled() || false; 368 return autoLauncher.isEnabled() || false;
357 } 369 }
358 370
359 _reactivateServices(retryCount = 0) {
360 if (!this.isOnline) {
361 console.debug('reactivateServices: computer is offline, trying again in 5s, retries:', retryCount);
362 setTimeout(() => this._reactivateServices(retryCount + 1), 5000);
363 } else {
364 console.debug('reactivateServices: reload Franz');
365 window.location.reload();
366 }
367 }
368
369 _systemDND() { 371 _systemDND() {
370 const dnd = getDoNotDisturb(); 372 const dnd = getDoNotDisturb();
371 if (dnd === this.stores.settings.all.isAppMuted || !this.isSystemMuteOverriden) { 373 if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) {
372 this.actions.app.muteApp({ 374 this.actions.app.muteApp({
373 isMuted: dnd, 375 isMuted: dnd,
374 overrideSystemMute: false, 376 overrideSystemMute: false,