diff options
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/AppStore.js | 24 | ||||
-rw-r--r-- | src/stores/GlobalErrorStore.js | 5 | ||||
-rw-r--r-- | src/stores/PaymentStore.js | 3 | ||||
-rw-r--r-- | src/stores/RecipePreviewsStore.js | 10 | ||||
-rw-r--r-- | src/stores/RecipesStore.js | 2 | ||||
-rw-r--r-- | src/stores/RequestStore.js | 2 | ||||
-rw-r--r-- | src/stores/ServicesStore.js | 72 | ||||
-rw-r--r-- | src/stores/SettingsStore.js | 43 | ||||
-rw-r--r-- | src/stores/UserStore.js | 39 |
9 files changed, 112 insertions, 88 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 315235ba4..5bae6e8d4 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -1,6 +1,6 @@ | |||
1 | import { remote, ipcRenderer, shell } from 'electron'; | 1 | import { remote, ipcRenderer, shell } from 'electron'; |
2 | import { | 2 | import { |
3 | action, computed, observable, reaction, | 3 | action, computed, observable, |
4 | } from 'mobx'; | 4 | } from 'mobx'; |
5 | import moment from 'moment'; | 5 | import moment from 'moment'; |
6 | import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; | 6 | import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; |
@@ -17,14 +17,13 @@ import Request from './lib/Request'; | |||
17 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; | 17 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; |
18 | import { isMac } from '../environment'; | 18 | import { isMac } from '../environment'; |
19 | import locales from '../i18n/translations'; | 19 | import locales from '../i18n/translations'; |
20 | import { gaEvent, gaPage, statsEvent } from '../lib/analytics'; | ||
21 | import { onVisibilityChange } from '../helpers/visibility-helper'; | 20 | import { onVisibilityChange } from '../helpers/visibility-helper'; |
22 | import { getLocale } from '../helpers/i18n-helpers'; | 21 | import { getLocale } from '../helpers/i18n-helpers'; |
23 | 22 | ||
24 | import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; | 23 | import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; |
25 | import { isValidExternalURL } from '../helpers/url-helpers'; | 24 | import { isValidExternalURL } from '../helpers/url-helpers'; |
26 | 25 | ||
27 | const debug = require('debug')('Franz:AppStore'); | 26 | const debug = require('debug')('Ferdi:AppStore'); |
28 | 27 | ||
29 | const { app, systemPreferences, screen } = remote; | 28 | const { app, systemPreferences, screen } = remote; |
30 | 29 | ||
@@ -32,7 +31,7 @@ const mainWindow = remote.getCurrentWindow(); | |||
32 | 31 | ||
33 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; | 32 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; |
34 | const autoLauncher = new AutoLaunch({ | 33 | const autoLauncher = new AutoLaunch({ |
35 | name: 'Franz', | 34 | name: 'Ferdi', |
36 | }); | 35 | }); |
37 | 36 | ||
38 | export default class AppStore extends Store { | 37 | export default class AppStore extends Store { |
@@ -54,6 +53,8 @@ export default class AppStore extends Store { | |||
54 | 53 | ||
55 | @observable isOnline = navigator.onLine; | 54 | @observable isOnline = navigator.onLine; |
56 | 55 | ||
56 | @observable authRequestFailed = false; | ||
57 | |||
57 | @observable timeOfflineStart; | 58 | @observable timeOfflineStart; |
58 | 59 | ||
59 | @observable updateStatus = null; | 60 | @observable updateStatus = null; |
@@ -113,7 +114,7 @@ export default class AppStore extends Store { | |||
113 | 114 | ||
114 | this.isOnline = navigator.onLine; | 115 | this.isOnline = navigator.onLine; |
115 | 116 | ||
116 | // Check if Franz should launch on start | 117 | // Check if Ferdi should launch on start |
117 | // Needs to be delayed a bit | 118 | // Needs to be delayed a bit |
118 | this._autoStart(); | 119 | this._autoStart(); |
119 | 120 | ||
@@ -173,13 +174,6 @@ export default class AppStore extends Store { | |||
173 | 174 | ||
174 | debug('Window is visible/focused', isVisible); | 175 | debug('Window is visible/focused', isVisible); |
175 | }); | 176 | }); |
176 | |||
177 | // analytics autorun | ||
178 | reaction(() => this.stores.router.location.pathname, (pathname) => { | ||
179 | gaPage(pathname); | ||
180 | }); | ||
181 | |||
182 | statsEvent('app-start'); | ||
183 | } | 177 | } |
184 | 178 | ||
185 | @computed get cacheSize() { | 179 | @computed get cacheSize() { |
@@ -267,8 +261,6 @@ export default class AppStore extends Store { | |||
267 | } catch (err) { | 261 | } catch (err) { |
268 | console.warn(err); | 262 | console.warn(err); |
269 | } | 263 | } |
270 | |||
271 | gaEvent('App', enable ? 'enable autostart' : 'disable autostart'); | ||
272 | } | 264 | } |
273 | 265 | ||
274 | @action _openExternalUrl({ url }) { | 266 | @action _openExternalUrl({ url }) { |
@@ -278,8 +270,6 @@ export default class AppStore extends Store { | |||
278 | if (isValidExternalURL(url)) { | 270 | if (isValidExternalURL(url)) { |
279 | shell.openExternal(url); | 271 | shell.openExternal(url); |
280 | } | 272 | } |
281 | |||
282 | gaEvent('External URL', 'open', parsedUrl.host); | ||
283 | } | 273 | } |
284 | 274 | ||
285 | @action _checkForUpdates() { | 275 | @action _checkForUpdates() { |
@@ -373,7 +363,7 @@ export default class AppStore extends Store { | |||
373 | } | 363 | } |
374 | 364 | ||
375 | _muteAppHandler() { | 365 | _muteAppHandler() { |
376 | const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; | 366 | const { showMessageBadgesEvenWhenMuted } = this.stores.ui; |
377 | 367 | ||
378 | if (!showMessageBadgesEvenWhenMuted) { | 368 | if (!showMessageBadgesEvenWhenMuted) { |
379 | this.actions.app.setBadge({ unreadDirectMessageCount: 0, unreadIndirectMessageCount: 0 }); | 369 | this.actions.app.setBadge({ unreadDirectMessageCount: 0, unreadIndirectMessageCount: 0 }); |
diff --git a/src/stores/GlobalErrorStore.js b/src/stores/GlobalErrorStore.js index 7a85c2daa..8bdafb68c 100644 --- a/src/stores/GlobalErrorStore.js +++ b/src/stores/GlobalErrorStore.js | |||
@@ -24,9 +24,12 @@ export default class GlobalErrorStore extends Store { | |||
24 | this.response = {}; | 24 | this.response = {}; |
25 | } | 25 | } |
26 | if (this.error.status === 401) { | 26 | if (this.error.status === 401) { |
27 | this.actions.user.logout({ serverLogout: true }); | 27 | window.ferdi.stores.app.authRequestFailed = true; |
28 | // this.actions.user.logout({ serverLogout: true }); | ||
28 | } | 29 | } |
29 | } | 30 | } |
31 | } else { | ||
32 | window.ferdi.stores.app.authRequestFailed = false; | ||
30 | } | 33 | } |
31 | }); | 34 | }); |
32 | } | 35 | } |
diff --git a/src/stores/PaymentStore.js b/src/stores/PaymentStore.js index d4de476c8..8579812ad 100644 --- a/src/stores/PaymentStore.js +++ b/src/stores/PaymentStore.js | |||
@@ -3,7 +3,6 @@ import { action, observable, computed } from 'mobx'; | |||
3 | import Store from './lib/Store'; | 3 | import Store from './lib/Store'; |
4 | import CachedRequest from './lib/CachedRequest'; | 4 | import CachedRequest from './lib/CachedRequest'; |
5 | import Request from './lib/Request'; | 5 | import Request from './lib/Request'; |
6 | import { gaEvent } from '../lib/analytics'; | ||
7 | 6 | ||
8 | export default class PaymentStore extends Store { | 7 | export default class PaymentStore extends Store { |
9 | @observable plansRequest = new CachedRequest(this.api.payment, 'plans'); | 8 | @observable plansRequest = new CachedRequest(this.api.payment, 'plans'); |
@@ -26,8 +25,6 @@ export default class PaymentStore extends Store { | |||
26 | @action _createHostedPage({ planId }) { | 25 | @action _createHostedPage({ planId }) { |
27 | const request = this.createHostedPageRequest.execute(planId); | 26 | const request = this.createHostedPageRequest.execute(planId); |
28 | 27 | ||
29 | gaEvent('Payment', 'createHostedPage', planId); | ||
30 | |||
31 | return request; | 28 | return request; |
32 | } | 29 | } |
33 | } | 30 | } |
diff --git a/src/stores/RecipePreviewsStore.js b/src/stores/RecipePreviewsStore.js index 382820d58..989e1124a 100644 --- a/src/stores/RecipePreviewsStore.js +++ b/src/stores/RecipePreviewsStore.js | |||
@@ -1,11 +1,8 @@ | |||
1 | import { action, computed, observable } from 'mobx'; | 1 | import { action, computed, observable } from 'mobx'; |
2 | import { debounce } from 'lodash'; | ||
3 | import ms from 'ms'; | ||
4 | 2 | ||
5 | import Store from './lib/Store'; | 3 | import Store from './lib/Store'; |
6 | import CachedRequest from './lib/CachedRequest'; | 4 | import CachedRequest from './lib/CachedRequest'; |
7 | import Request from './lib/Request'; | 5 | import Request from './lib/Request'; |
8 | import { gaEvent } from '../lib/analytics'; | ||
9 | 6 | ||
10 | export default class RecipePreviewsStore extends Store { | 7 | export default class RecipePreviewsStore extends Store { |
11 | @observable allRecipePreviewsRequest = new CachedRequest(this.api.recipePreviews, 'all'); | 8 | @observable allRecipePreviewsRequest = new CachedRequest(this.api.recipePreviews, 'all'); |
@@ -41,13 +38,6 @@ export default class RecipePreviewsStore extends Store { | |||
41 | @action _search({ needle }) { | 38 | @action _search({ needle }) { |
42 | if (needle !== '') { | 39 | if (needle !== '') { |
43 | this.searchRecipePreviewsRequest.execute(needle); | 40 | this.searchRecipePreviewsRequest.execute(needle); |
44 | |||
45 | this._analyticsSearch(needle); | ||
46 | } | 41 | } |
47 | } | 42 | } |
48 | |||
49 | // Helper | ||
50 | _analyticsSearch = debounce((needle) => { | ||
51 | gaEvent('Recipe', 'search', needle); | ||
52 | }, ms('3s')); | ||
53 | } | 43 | } |
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index d51192078..7f91049df 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js | |||
@@ -5,7 +5,7 @@ import CachedRequest from './lib/CachedRequest'; | |||
5 | import Request from './lib/Request'; | 5 | import Request from './lib/Request'; |
6 | import { matchRoute } from '../helpers/routing-helpers'; | 6 | import { matchRoute } from '../helpers/routing-helpers'; |
7 | 7 | ||
8 | const debug = require('debug')('Franz:RecipeStore'); | 8 | const debug = require('debug')('Ferdi:RecipeStore'); |
9 | 9 | ||
10 | export default class RecipesStore extends Store { | 10 | export default class RecipesStore extends Store { |
11 | @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); | 11 | @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); |
diff --git a/src/stores/RequestStore.js b/src/stores/RequestStore.js index 9254e3223..2587d4eef 100644 --- a/src/stores/RequestStore.js +++ b/src/stores/RequestStore.js | |||
@@ -3,7 +3,7 @@ import ms from 'ms'; | |||
3 | 3 | ||
4 | import Store from './lib/Store'; | 4 | import Store from './lib/Store'; |
5 | 5 | ||
6 | const debug = require('debug')('Franz:RequestsStore'); | 6 | const debug = require('debug')('Ferdi:RequestsStore'); |
7 | 7 | ||
8 | export default class RequestStore extends Store { | 8 | export default class RequestStore extends Store { |
9 | @observable userInfoRequest; | 9 | @observable userInfoRequest; |
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index d1fd2be3d..f88b14983 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -4,19 +4,19 @@ import { | |||
4 | computed, | 4 | computed, |
5 | observable, | 5 | observable, |
6 | } from 'mobx'; | 6 | } from 'mobx'; |
7 | import { debounce, remove } from 'lodash'; | 7 | import { remove } from 'lodash'; |
8 | import ms from 'ms'; | 8 | import ms from 'ms'; |
9 | 9 | ||
10 | import Store from './lib/Store'; | 10 | import Store from './lib/Store'; |
11 | import Request from './lib/Request'; | 11 | import Request from './lib/Request'; |
12 | import CachedRequest from './lib/CachedRequest'; | 12 | import CachedRequest from './lib/CachedRequest'; |
13 | import { matchRoute } from '../helpers/routing-helpers'; | 13 | import { matchRoute } from '../helpers/routing-helpers'; |
14 | import { gaEvent, statsEvent } from '../lib/analytics'; | ||
15 | import { workspaceStore } from '../features/workspaces'; | 14 | import { workspaceStore } from '../features/workspaces'; |
16 | import { serviceLimitStore } from '../features/serviceLimit'; | 15 | import { serviceLimitStore } from '../features/serviceLimit'; |
17 | import { RESTRICTION_TYPES } from '../models/Service'; | 16 | import { RESTRICTION_TYPES } from '../models/Service'; |
17 | import { KEEP_WS_LOADED_USID } from '../config'; | ||
18 | 18 | ||
19 | const debug = require('debug')('Franz:ServiceStore'); | 19 | const debug = require('debug')('Ferdi:ServiceStore'); |
20 | 20 | ||
21 | export default class ServicesStore extends Store { | 21 | export default class ServicesStore extends Store { |
22 | @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); | 22 | @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); |
@@ -125,7 +125,35 @@ export default class ServicesStore extends Store { | |||
125 | const { keepAllWorkspacesLoaded } = this.stores.workspaces.settings; | 125 | const { keepAllWorkspacesLoaded } = this.stores.workspaces.settings; |
126 | const services = this.allServicesRequest.execute().result || []; | 126 | const services = this.allServicesRequest.execute().result || []; |
127 | const filteredServices = showDisabledServices ? services : services.filter(service => service.isEnabled); | 127 | const filteredServices = showDisabledServices ? services : services.filter(service => service.isEnabled); |
128 | return keepAllWorkspacesLoaded ? filteredServices : workspaceStore.filterServicesByActiveWorkspace(filteredServices); | 128 | |
129 | let displayedServices; | ||
130 | if (keepAllWorkspacesLoaded) { | ||
131 | // Keep all enabled services loaded | ||
132 | displayedServices = filteredServices; | ||
133 | } else { | ||
134 | // Keep all services in current workspace loaded | ||
135 | displayedServices = workspaceStore.filterServicesByActiveWorkspace(filteredServices); | ||
136 | |||
137 | // Keep all services active in workspaces that should be kept loaded | ||
138 | for (const workspace of this.stores.workspaces.workspaces) { | ||
139 | // Check if workspace needs to be kept loaded | ||
140 | if (workspace.services.includes(KEEP_WS_LOADED_USID)) { | ||
141 | // Get services for workspace | ||
142 | const serviceIDs = workspace.services.filter(i => i !== KEEP_WS_LOADED_USID); | ||
143 | const wsServices = filteredServices.filter(service => serviceIDs.includes(service.id)); | ||
144 | |||
145 | displayedServices = [ | ||
146 | ...displayedServices, | ||
147 | ...wsServices, | ||
148 | ]; | ||
149 | } | ||
150 | } | ||
151 | |||
152 | // Make sure every service is in the list only once | ||
153 | displayedServices = displayedServices.filter((v, i, a) => a.indexOf(v) === i); | ||
154 | } | ||
155 | |||
156 | return displayedServices; | ||
129 | } | 157 | } |
130 | 158 | ||
131 | @computed get filtered() { | 159 | @computed get filtered() { |
@@ -182,7 +210,6 @@ export default class ServicesStore extends Store { | |||
182 | 210 | ||
183 | if (redirect) { | 211 | if (redirect) { |
184 | this.stores.router.push('/settings/recipes'); | 212 | this.stores.router.push('/settings/recipes'); |
185 | gaEvent('Service', 'create', recipeId); | ||
186 | } | 213 | } |
187 | } | 214 | } |
188 | 215 | ||
@@ -259,7 +286,6 @@ export default class ServicesStore extends Store { | |||
259 | 286 | ||
260 | if (redirect) { | 287 | if (redirect) { |
261 | this.stores.router.push('/settings/services'); | 288 | this.stores.router.push('/settings/services'); |
262 | gaEvent('Service', 'update', service.recipe.id); | ||
263 | } | 289 | } |
264 | } | 290 | } |
265 | 291 | ||
@@ -274,19 +300,14 @@ export default class ServicesStore extends Store { | |||
274 | remove(result, c => c.id === serviceId); | 300 | remove(result, c => c.id === serviceId); |
275 | }); | 301 | }); |
276 | 302 | ||
277 | const service = this.one(serviceId); | ||
278 | |||
279 | await request._promise; | 303 | await request._promise; |
280 | this.actionStatus = request.result.status; | 304 | this.actionStatus = request.result.status; |
281 | |||
282 | gaEvent('Service', 'delete', service.recipe.id); | ||
283 | } | 305 | } |
284 | 306 | ||
285 | @action async _clearCache({ serviceId }) { | 307 | @action async _clearCache({ serviceId }) { |
286 | this.clearCacheRequest.reset(); | 308 | this.clearCacheRequest.reset(); |
287 | const request = this.clearCacheRequest.execute(serviceId); | 309 | const request = this.clearCacheRequest.execute(serviceId); |
288 | await request._promise; | 310 | await request._promise; |
289 | gaEvent('Service', 'clear cache'); | ||
290 | } | 311 | } |
291 | 312 | ||
292 | @action _setActive({ serviceId, keepActiveRoute }) { | 313 | @action _setActive({ serviceId, keepActiveRoute }) { |
@@ -298,8 +319,6 @@ export default class ServicesStore extends Store { | |||
298 | }); | 319 | }); |
299 | service.isActive = true; | 320 | service.isActive = true; |
300 | 321 | ||
301 | statsEvent('activate-service', service.recipe.id); | ||
302 | |||
303 | this._focusActiveService(); | 322 | this._focusActiveService(); |
304 | } | 323 | } |
305 | 324 | ||
@@ -402,7 +421,7 @@ export default class ServicesStore extends Store { | |||
402 | }, | 421 | }, |
403 | }); | 422 | }); |
404 | } else if (channel === 'notification') { | 423 | } else if (channel === 'notification') { |
405 | const options = args[0].options; | 424 | const { options } = args[0]; |
406 | if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) { | 425 | if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) { |
407 | Object.assign(options, { | 426 | Object.assign(options, { |
408 | silent: true, | 427 | silent: true, |
@@ -410,8 +429,17 @@ export default class ServicesStore extends Store { | |||
410 | } | 429 | } |
411 | 430 | ||
412 | if (service.isNotificationEnabled) { | 431 | if (service.isNotificationEnabled) { |
413 | const title = typeof args[0].title === 'string' ? args[0].title : service.name; | 432 | let title = `Notification from ${service.name}`; |
414 | options.body = typeof options.body === 'string' ? options.body : ''; | 433 | if (!this.stores.settings.all.app.privateNotifications) { |
434 | options.body = typeof options.body === 'string' ? options.body : ''; | ||
435 | title = typeof args[0].title === 'string' ? args[0].title : service.name; | ||
436 | } else { | ||
437 | // Remove message data from notification in private mode | ||
438 | options.body = ''; | ||
439 | options.icon = '/assets/img/notification-badge.gif'; | ||
440 | } | ||
441 | |||
442 | console.log(title, options); | ||
415 | 443 | ||
416 | this.actions.app.notify({ | 444 | this.actions.app.notify({ |
417 | notificationId: args[0].notificationId, | 445 | notificationId: args[0].notificationId, |
@@ -529,7 +557,7 @@ export default class ServicesStore extends Store { | |||
529 | } | 557 | } |
530 | 558 | ||
531 | @action _reorderService({ oldIndex, newIndex }) { | 559 | @action _reorderService({ oldIndex, newIndex }) { |
532 | const showDisabledServices = this.stores.settings.all.app.showDisabledServices; | 560 | const { showDisabledServices } = this.stores.settings.all.app; |
533 | const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); | 561 | const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); |
534 | const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); | 562 | const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); |
535 | 563 | ||
@@ -548,8 +576,6 @@ export default class ServicesStore extends Store { | |||
548 | service.order = services[s.id]; | 576 | service.order = services[s.id]; |
549 | }); | 577 | }); |
550 | }); | 578 | }); |
551 | |||
552 | this._reorderAnalytics(); | ||
553 | } | 579 | } |
554 | 580 | ||
555 | @action _toggleNotifications({ serviceId }) { | 581 | @action _toggleNotifications({ serviceId }) { |
@@ -625,8 +651,8 @@ export default class ServicesStore extends Store { | |||
625 | } | 651 | } |
626 | 652 | ||
627 | _getUnreadMessageCountReaction() { | 653 | _getUnreadMessageCountReaction() { |
628 | const showMessageBadgeWhenMuted = this.stores.settings.all.app.showMessageBadgeWhenMuted; | 654 | const { showMessageBadgeWhenMuted } = this.stores.settings.all.app; |
629 | const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; | 655 | const { showMessageBadgesEvenWhenMuted } = this.stores.ui; |
630 | 656 | ||
631 | const unreadDirectMessageCount = this.allDisplayed | 657 | const unreadDirectMessageCount = this.allDisplayed |
632 | .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) | 658 | .filter(s => (showMessageBadgeWhenMuted || s.isNotificationEnabled) && showMessageBadgesEvenWhenMuted && s.isBadgeEnabled) |
@@ -751,10 +777,6 @@ export default class ServicesStore extends Store { | |||
751 | } | 777 | } |
752 | } | 778 | } |
753 | 779 | ||
754 | _reorderAnalytics = debounce(() => { | ||
755 | gaEvent('Service', 'order'); | ||
756 | }, ms('5s')); | ||
757 | |||
758 | _wrapIndex(index, delta, size) { | 780 | _wrapIndex(index, delta, size) { |
759 | return (((index + delta) % size) + size) % size; | 781 | return (((index + delta) % size) + size) % size; |
760 | } | 782 | } |
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 75bb38fe0..c09f24af7 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,17 +1,18 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer, remote } from 'electron'; |
2 | import { | 2 | import { |
3 | action, computed, observable, | 3 | action, computed, observable, reaction, |
4 | } from 'mobx'; | 4 | } from 'mobx'; |
5 | import localStorage from 'mobx-localstorage'; | 5 | import localStorage from 'mobx-localstorage'; |
6 | 6 | ||
7 | import Store from './lib/Store'; | 7 | import Store from './lib/Store'; |
8 | import Request from './lib/Request'; | 8 | import Request from './lib/Request'; |
9 | import { getLocale } from '../helpers/i18n-helpers'; | 9 | import { getLocale } from '../helpers/i18n-helpers'; |
10 | import { API } from '../environment'; | ||
10 | 11 | ||
11 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; | 12 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; |
12 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 13 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
13 | 14 | ||
14 | const debug = require('debug')('Franz:SettingsStore'); | 15 | const debug = require('debug')('Ferdi:SettingsStore'); |
15 | 16 | ||
16 | export default class SettingsStore extends Store { | 17 | export default class SettingsStore extends Store { |
17 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); | 18 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); |
@@ -43,6 +44,41 @@ export default class SettingsStore extends Store { | |||
43 | 44 | ||
44 | async setup() { | 45 | async setup() { |
45 | await this._migrate(); | 46 | await this._migrate(); |
47 | |||
48 | reaction( | ||
49 | () => this.all.app.autohideMenuBar, | ||
50 | () => remote.getCurrentWindow().setAutoHideMenuBar( | ||
51 | this.all.app.autohideMenuBar, | ||
52 | ), | ||
53 | ); | ||
54 | |||
55 | reaction( | ||
56 | () => this.all.app.locked, | ||
57 | () => { | ||
58 | const { router } = window.ferdi.stores; | ||
59 | |||
60 | if (this.all.app.locked && this.all.app.lockingFeatureEnabled) { | ||
61 | // App just got locked, redirect to unlock screen | ||
62 | router.push('/auth/locked'); | ||
63 | } else if (router.location.pathname.includes('/auth/locked')) { | ||
64 | // App is unlocked but user is still on locked screen | ||
65 | // Redirect to homepage | ||
66 | router.push('/'); | ||
67 | } | ||
68 | }, | ||
69 | ); | ||
70 | |||
71 | // Make sure to lock app on launch if locking feature is enabled | ||
72 | setTimeout(() => { | ||
73 | if (this.all.app.lockingFeatureEnabled) { | ||
74 | this.actions.settings.update({ | ||
75 | type: 'app', | ||
76 | data: { | ||
77 | locked: true, | ||
78 | }, | ||
79 | }); | ||
80 | } | ||
81 | }, 1000); | ||
46 | } | 82 | } |
47 | 83 | ||
48 | @computed get app() { | 84 | @computed get app() { |
@@ -121,6 +157,7 @@ export default class SettingsStore extends Store { | |||
121 | runInBackground: legacySettings.runInBackground, | 157 | runInBackground: legacySettings.runInBackground, |
122 | enableSystemTray: legacySettings.enableSystemTray, | 158 | enableSystemTray: legacySettings.enableSystemTray, |
123 | minimizeToSystemTray: legacySettings.minimizeToSystemTray, | 159 | minimizeToSystemTray: legacySettings.minimizeToSystemTray, |
160 | server: API, | ||
124 | isAppMuted: legacySettings.isAppMuted, | 161 | isAppMuted: legacySettings.isAppMuted, |
125 | enableGPUAcceleration: legacySettings.enableGPUAcceleration, | 162 | enableGPUAcceleration: legacySettings.enableGPUAcceleration, |
126 | showMessageBadgeWhenMuted: legacySettings.showMessageBadgeWhenMuted, | 163 | showMessageBadgeWhenMuted: legacySettings.showMessageBadgeWhenMuted, |
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index b652098f9..61b7d4adf 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js | |||
@@ -8,12 +8,11 @@ import { isDevMode } from '../environment'; | |||
8 | import Store from './lib/Store'; | 8 | import Store from './lib/Store'; |
9 | import Request from './lib/Request'; | 9 | import Request from './lib/Request'; |
10 | import CachedRequest from './lib/CachedRequest'; | 10 | import CachedRequest from './lib/CachedRequest'; |
11 | import { gaEvent } from '../lib/analytics'; | ||
12 | import { sleep } from '../helpers/async-helpers'; | 11 | import { sleep } from '../helpers/async-helpers'; |
13 | import { getPlan } from '../helpers/plan-helpers'; | 12 | import { getPlan } from '../helpers/plan-helpers'; |
14 | import { PLANS } from '../config'; | 13 | import { PLANS } from '../config'; |
15 | 14 | ||
16 | const debug = require('debug')('Franz:UserStore'); | 15 | const debug = require('debug')('Ferdi:UserStore'); |
17 | 16 | ||
18 | // TODO: split stores into UserStore and AuthStore | 17 | // TODO: split stores into UserStore and AuthStore |
19 | export default class UserStore extends Store { | 18 | export default class UserStore extends Store { |
@@ -94,7 +93,7 @@ export default class UserStore extends Store { | |||
94 | 93 | ||
95 | // Reactions | 94 | // Reactions |
96 | this.registerReactions([ | 95 | this.registerReactions([ |
97 | this._requireAuthenticatedUser, | 96 | // this._requireAuthenticatedUser, |
98 | this._getUserData.bind(this), | 97 | this._getUserData.bind(this), |
99 | this._resetTrialActivationState.bind(this), | 98 | this._resetTrialActivationState.bind(this), |
100 | ]); | 99 | ]); |
@@ -157,7 +156,7 @@ export default class UserStore extends Store { | |||
157 | } | 156 | } |
158 | 157 | ||
159 | @computed get isPremium() { | 158 | @computed get isPremium() { |
160 | return !!this.data.isPremium; | 159 | return true; |
161 | } | 160 | } |
162 | 161 | ||
163 | @computed get isPremiumOverride() { | 162 | @computed get isPremiumOverride() { |
@@ -172,12 +171,13 @@ export default class UserStore extends Store { | |||
172 | } | 171 | } |
173 | 172 | ||
174 | @computed get isPro() { | 173 | @computed get isPro() { |
175 | if (this.isPremiumOverride) return true; | 174 | return true; |
175 | // if (this.isPremiumOverride) return true; | ||
176 | 176 | ||
177 | if (!this.team || (!this.team.plan || this.team.state === 'expired')) return false; | 177 | // if (!this.team || (!this.team.plan || this.team.state === 'expired')) return false; |
178 | const plan = getPlan(this.team.plan); | 178 | // const plan = getPlan(this.team.plan); |
179 | 179 | ||
180 | return plan === PLANS.PRO || plan === PLANS.LEGACY; | 180 | // return plan === PLANS.PRO || plan === PLANS.LEGACY; |
181 | } | 181 | } |
182 | 182 | ||
183 | @computed get legacyServices() { | 183 | @computed get legacyServices() { |
@@ -190,16 +190,12 @@ export default class UserStore extends Store { | |||
190 | this._setUserData(authToken); | 190 | this._setUserData(authToken); |
191 | 191 | ||
192 | this.stores.router.push('/'); | 192 | this.stores.router.push('/'); |
193 | |||
194 | gaEvent('User', 'login'); | ||
195 | } | 193 | } |
196 | 194 | ||
197 | @action _tokenLogin(authToken) { | 195 | @action _tokenLogin(authToken) { |
198 | this._setUserData(authToken); | 196 | this._setUserData(authToken); |
199 | 197 | ||
200 | this.stores.router.push('/'); | 198 | this.stores.router.push('/'); |
201 | |||
202 | gaEvent('User', 'tokenLogin'); | ||
203 | } | 199 | } |
204 | 200 | ||
205 | @action async _signup({ | 201 | @action async _signup({ |
@@ -215,13 +211,11 @@ export default class UserStore extends Store { | |||
215 | locale: this.stores.app.locale, | 211 | locale: this.stores.app.locale, |
216 | }); | 212 | }); |
217 | 213 | ||
218 | this.hasCompletedSignup = false; | 214 | this.hasCompletedSignup = true; |
219 | 215 | ||
220 | this._setUserData(authToken); | 216 | this._setUserData(authToken); |
221 | 217 | ||
222 | this.stores.router.push(this.PRICING_ROUTE); | 218 | this.stores.router.push('/'); |
223 | |||
224 | gaEvent('User', 'signup'); | ||
225 | } | 219 | } |
226 | 220 | ||
227 | @action async _retrievePassword({ email }) { | 221 | @action async _retrievePassword({ email }) { |
@@ -229,8 +223,6 @@ export default class UserStore extends Store { | |||
229 | 223 | ||
230 | await request._promise; | 224 | await request._promise; |
231 | this.actionStatus = request.result.status || []; | 225 | this.actionStatus = request.result.status || []; |
232 | |||
233 | gaEvent('User', 'retrievePassword'); | ||
234 | } | 226 | } |
235 | 227 | ||
236 | @action async _activateTrial({ planId }) { | 228 | @action async _activateTrial({ planId }) { |
@@ -246,9 +238,6 @@ export default class UserStore extends Store { | |||
246 | 238 | ||
247 | this.stores.features.featuresRequest.invalidate({ immediately: true }); | 239 | this.stores.features.featuresRequest.invalidate({ immediately: true }); |
248 | this.stores.user.getUserInfoRequest.invalidate({ immediately: true }); | 240 | this.stores.user.getUserInfoRequest.invalidate({ immediately: true }); |
249 | |||
250 | |||
251 | gaEvent('User', 'activateTrial'); | ||
252 | } | 241 | } |
253 | 242 | ||
254 | @action async _invite({ invites }) { | 243 | @action async _invite({ invites }) { |
@@ -262,8 +251,6 @@ export default class UserStore extends Store { | |||
262 | if (this.stores.router.location.pathname.includes(this.INVITE_ROUTE)) { | 251 | if (this.stores.router.location.pathname.includes(this.INVITE_ROUTE)) { |
263 | this.stores.router.push('/'); | 252 | this.stores.router.push('/'); |
264 | } | 253 | } |
265 | |||
266 | gaEvent('User', 'inviteUsers'); | ||
267 | } | 254 | } |
268 | 255 | ||
269 | @action async _update({ userData }) { | 256 | @action async _update({ userData }) { |
@@ -273,8 +260,6 @@ export default class UserStore extends Store { | |||
273 | 260 | ||
274 | this.getUserInfoRequest.patch(() => response.data); | 261 | this.getUserInfoRequest.patch(() => response.data); |
275 | this.actionStatus = response.status || []; | 262 | this.actionStatus = response.status || []; |
276 | |||
277 | gaEvent('User', 'update'); | ||
278 | } | 263 | } |
279 | 264 | ||
280 | @action _resetStatus() { | 265 | @action _resetStatus() { |
@@ -297,12 +282,12 @@ export default class UserStore extends Store { | |||
297 | const recipes = services.filter((obj, pos, arr) => arr.map(mapObj => mapObj.recipe.id).indexOf(obj.recipe.id) === pos).map(s => s.recipe.id); | 282 | const recipes = services.filter((obj, pos, arr) => arr.map(mapObj => mapObj.recipe.id).indexOf(obj.recipe.id) === pos).map(s => s.recipe.id); |
298 | 283 | ||
299 | // Install recipes | 284 | // Install recipes |
300 | for (const recipe of recipes) { | 285 | for (const recipe of recipes) { // eslint-disable-line no-unused-vars |
301 | // eslint-disable-next-line | 286 | // eslint-disable-next-line |
302 | await this.stores.recipes._install({ recipeId: recipe }); | 287 | await this.stores.recipes._install({ recipeId: recipe }); |
303 | } | 288 | } |
304 | 289 | ||
305 | for (const service of services) { | 290 | for (const service of services) { // eslint-disable-line no-unused-vars |
306 | this.actions.service.createFromLegacyService({ | 291 | this.actions.service.createFromLegacyService({ |
307 | data: service, | 292 | data: service, |
308 | }); | 293 | }); |