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, 38 insertions, 34 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index b21d48a11..351ad6422 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -1,21 +1,25 @@
1import { remote, ipcRenderer, shell } from 'electron'; 1import { remote, ipcRenderer, shell } from 'electron';
2import { action, computed, observable } from 'mobx'; 2import {
3 action, computed, observable, reaction,
4} from 'mobx';
3import moment from 'moment'; 5import moment from 'moment';
4import key from 'keymaster';
5import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; 6import { getDoNotDisturb } from '@meetfranz/electron-notification-state';
6import AutoLaunch from 'auto-launch'; 7import AutoLaunch from 'auto-launch';
7import prettyBytes from 'pretty-bytes'; 8import prettyBytes from 'pretty-bytes';
9import ms from 'ms';
10import { URL } from 'url';
8 11
9import Store from './lib/Store'; 12import Store from './lib/Store';
10import Request from './lib/Request'; 13import Request from './lib/Request';
11import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; 14import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config';
12import { isMac, isLinux, isWindows } from '../environment'; 15import { isMac } from '../environment';
13import locales from '../i18n/translations'; 16import locales from '../i18n/translations';
14import { gaEvent } from '../lib/analytics'; 17import { gaEvent, gaPage } from '../lib/analytics';
15import { onVisibilityChange } from '../helpers/visibility-helper'; 18import { onVisibilityChange } from '../helpers/visibility-helper';
16import { getLocale } from '../helpers/i18n-helpers'; 19import { getLocale } from '../helpers/i18n-helpers';
17 20
18import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; 21import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js';
22import { isValidExternalURL } from '../helpers/url-helpers';
19 23
20const debug = require('debug')('Franz:AppStore'); 24const debug = require('debug')('Franz:AppStore');
21 25
@@ -110,12 +114,12 @@ export default class AppStore extends Store {
110 // Check if system is muted 114 // Check if system is muted
111 // There are no events to subscribe so we need to poll everey 5s 115 // There are no events to subscribe so we need to poll everey 5s
112 this._systemDND(); 116 this._systemDND();
113 setInterval(() => this._systemDND(), 5000); 117 setInterval(() => this._systemDND(), ms('5s'));
114 118
115 // Check for updates once every 4 hours 119 // Check for updates once every 4 hours
116 setInterval(() => this._checkForUpdates(), CHECK_INTERVAL); 120 setInterval(() => this._checkForUpdates(), CHECK_INTERVAL);
117 // Check for an update in 30s (need a delay to prevent Squirrel Installer lock file issues) 121 // Check for an update in 30s (need a delay to prevent Squirrel Installer lock file issues)
118 setTimeout(() => this._checkForUpdates(), 30000); 122 setTimeout(() => this._checkForUpdates(), ms('30s'));
119 ipcRenderer.on('autoUpdate', (event, data) => { 123 ipcRenderer.on('autoUpdate', (event, data) => {
120 if (data.available) { 124 if (data.available) {
121 this.updateStatus = this.updateStatusTypes.AVAILABLE; 125 this.updateStatus = this.updateStatusTypes.AVAILABLE;
@@ -152,27 +156,6 @@ export default class AppStore extends Store {
152 this.stores.router.push(url); 156 this.stores.router.push(url);
153 }); 157 });
154 158
155 // Set active the next service
156 key(
157 '⌘+pagedown, ctrl+pagedown, ⌘+alt+right, ctrl+tab', () => {
158 this.actions.service.setActiveNext();
159 },
160 );
161
162 // Set active the prev service
163 key(
164 '⌘+pageup, ctrl+pageup, ⌘+alt+left, ctrl+shift+tab', () => {
165 this.actions.service.setActivePrev();
166 },
167 );
168
169 // Global Mute
170 key(
171 '⌘+shift+m ctrl+shift+m', () => {
172 this.actions.app.toggleMuteApp();
173 },
174 );
175
176 this.locale = this._getDefaultLocale(); 159 this.locale = this._getDefaultLocale();
177 160
178 this._healthCheck(); 161 this._healthCheck();
@@ -184,6 +167,12 @@ export default class AppStore extends Store {
184 167
185 debug('Window is visible/focused', isVisible); 168 debug('Window is visible/focused', isVisible);
186 }); 169 });
170
171 // analytics autorun
172 reaction(() => this.stores.router.location.pathname, (pathname) => {
173 gaPage(pathname);
174 });
175 console.log('router location', this.stores.router.location);
187 } 176 }
188 177
189 @computed get cacheSize() { 178 @computed get cacheSize() {
@@ -196,7 +185,15 @@ export default class AppStore extends Store {
196 }) { 185 }) {
197 if (this.stores.settings.all.app.isAppMuted) return; 186 if (this.stores.settings.all.app.isAppMuted) return;
198 187
188 // TODO: is there a simple way to use blobs for notifications without storing them on disk?
189 if (options.icon.startsWith('blob:')) {
190 delete options.icon;
191 }
192
199 const notification = new window.Notification(title, options); 193 const notification = new window.Notification(title, options);
194
195 debug('New notification', title, options);
196
200 notification.onclick = (e) => { 197 notification.onclick = (e) => {
201 if (serviceId) { 198 if (serviceId) {
202 this.actions.service.sendIPCMessage({ 199 this.actions.service.sendIPCMessage({
@@ -206,12 +203,13 @@ export default class AppStore extends Store {
206 }); 203 });
207 204
208 this.actions.service.setActive({ serviceId }); 205 this.actions.service.setActive({ serviceId });
209 206 mainWindow.show();
210 if (isWindows) { 207 if (app.mainWindow.isMinimized()) {
211 mainWindow.restore(); 208 mainWindow.restore();
212 } else if (isLinux) {
213 mainWindow.show();
214 } 209 }
210 mainWindow.focus();
211
212 debug('Notification click handler');
215 } 213 }
216 }; 214 };
217 } 215 }
@@ -247,7 +245,14 @@ export default class AppStore extends Store {
247 } 245 }
248 246
249 @action _openExternalUrl({ url }) { 247 @action _openExternalUrl({ url }) {
250 shell.openExternal(url); 248 const parsedUrl = new URL(url);
249 debug('open external url', parsedUrl);
250
251 if (isValidExternalURL(url)) {
252 shell.openExternal(url);
253 }
254
255 gaEvent('External URL', 'open', parsedUrl.host);
251 } 256 }
252 257
253 @action _checkForUpdates() { 258 @action _checkForUpdates() {
@@ -271,7 +276,6 @@ export default class AppStore extends Store {
271 276
272 @action _muteApp({ isMuted, overrideSystemMute = true }) { 277 @action _muteApp({ isMuted, overrideSystemMute = true }) {
273 this.isSystemMuteOverridden = overrideSystemMute; 278 this.isSystemMuteOverridden = overrideSystemMute;
274
275 this.actions.settings.update({ 279 this.actions.settings.update({
276 type: 'app', 280 type: 'app',
277 data: { 281 data: {
@@ -308,7 +312,7 @@ export default class AppStore extends Store {
308 } else { 312 } else {
309 const deltaTime = moment().diff(this.timeOfflineStart); 313 const deltaTime = moment().diff(this.timeOfflineStart);
310 314
311 if (deltaTime > 30 * 60 * 1000) { 315 if (deltaTime > ms('30m')) {
312 this.actions.service.reloadAll(); 316 this.actions.service.reloadAll();
313 } 317 }
314 } 318 }