aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js7
-rw-r--r--src/stores/FeaturesStore.js11
-rw-r--r--src/stores/ServicesStore.js20
-rw-r--r--src/stores/UserStore.js27
4 files changed, 58 insertions, 7 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index dd4642d70..b21d48a11 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -143,10 +143,13 @@ export default class AppStore extends Store {
143 143
144 // Handle deep linking (franz://) 144 // Handle deep linking (franz://)
145 ipcRenderer.on('navigateFromDeepLink', (event, data) => { 145 ipcRenderer.on('navigateFromDeepLink', (event, data) => {
146 const { url } = data; 146 debug('Navigate from deep link', data);
147 let { url } = data;
147 if (!url) return; 148 if (!url) return;
148 149
149 this.stores.router.push(data.url); 150 url = url.replace(/\/$/, '');
151
152 this.stores.router.push(url);
150 }); 153 });
151 154
152 // Set active the next service 155 // Set active the next service
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js
index 2a0713b6f..0adee6adf 100644
--- a/src/stores/FeaturesStore.js
+++ b/src/stores/FeaturesStore.js
@@ -1,4 +1,4 @@
1import { computed, observable } from 'mobx'; 1import { computed, observable, reaction } from 'mobx';
2 2
3import Store from './lib/Store'; 3import Store from './lib/Store';
4import CachedRequest from './lib/CachedRequest'; 4import CachedRequest from './lib/CachedRequest';
@@ -6,6 +6,7 @@ import CachedRequest from './lib/CachedRequest';
6import delayApp from '../features/delayApp'; 6import delayApp from '../features/delayApp';
7import spellchecker from '../features/spellchecker'; 7import spellchecker from '../features/spellchecker';
8import serviceProxy from '../features/serviceProxy'; 8import serviceProxy from '../features/serviceProxy';
9import basicAuth from '../features/basicAuth';
9 10
10import { DEFAULT_FEATURES_CONFIG } from '../config'; 11import { DEFAULT_FEATURES_CONFIG } from '../config';
11 12
@@ -21,6 +22,13 @@ export default class FeaturesStore extends Store {
21 22
22 await this.featuresRequest._promise; 23 await this.featuresRequest._promise;
23 setTimeout(this._enableFeatures.bind(this), 1); 24 setTimeout(this._enableFeatures.bind(this), 1);
25
26 // single key reaction
27 reaction(() => this.stores.user.data.isPremium, () => {
28 if (this.stores.user.isLoggedIn) {
29 this.featuresRequest.invalidate({ immediately: true });
30 }
31 });
24 } 32 }
25 33
26 @computed get anonymousFeatures() { 34 @computed get anonymousFeatures() {
@@ -47,5 +55,6 @@ export default class FeaturesStore extends Store {
47 delayApp(this.stores, this.actions); 55 delayApp(this.stores, this.actions);
48 spellchecker(this.stores, this.actions); 56 spellchecker(this.stores, this.actions);
49 serviceProxy(this.stores, this.actions); 57 serviceProxy(this.stores, this.actions);
58 basicAuth(this.stores, this.actions);
50 } 59 }
51} 60}
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 84f84891a..efd57a09d 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -70,6 +70,7 @@ export default class ServicesStore extends Store {
70 this._mapActiveServiceToServiceModelReaction.bind(this), 70 this._mapActiveServiceToServiceModelReaction.bind(this),
71 this._saveActiveService.bind(this), 71 this._saveActiveService.bind(this),
72 this._logoutReaction.bind(this), 72 this._logoutReaction.bind(this),
73 this._handleMuteSettings.bind(this),
73 ]); 74 ]);
74 75
75 // Just bind this 76 // Just bind this
@@ -291,6 +292,8 @@ export default class ServicesStore extends Store {
291 this.all[index].isActive = false; 292 this.all[index].isActive = false;
292 }); 293 });
293 service.isActive = true; 294 service.isActive = true;
295
296 this._focusActiveService();
294 } 297 }
295 298
296 @action _setActiveNext() { 299 @action _setActiveNext() {
@@ -341,6 +344,9 @@ export default class ServicesStore extends Store {
341 const service = this.one(serviceId); 344 const service = this.one(serviceId);
342 345
343 if (service.webview) { 346 if (service.webview) {
347 if (document.activeElement) {
348 document.activeElement.blur();
349 }
344 service.webview.focus(); 350 service.webview.focus();
345 } 351 }
346 } 352 }
@@ -622,6 +628,20 @@ export default class ServicesStore extends Store {
622 } 628 }
623 } 629 }
624 630
631 _handleMuteSettings() {
632 const { enabled } = this;
633 const { isAppMuted } = this.stores.settings.app;
634
635 enabled.forEach((service) => {
636 const { isAttached } = service;
637 const isMuted = isAppMuted || service.isMuted;
638
639 if (isAttached) {
640 service.webview.setAudioMuted(isMuted);
641 }
642 });
643 }
644
625 _shareSettingsWithServiceProcess() { 645 _shareSettingsWithServiceProcess() {
626 const settings = this.stores.settings.app; 646 const settings = this.stores.settings.app;
627 this.actions.service.sendIPCMessageToAllServices({ 647 this.actions.service.sendIPCMessageToAllServices({
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js
index 7addb5760..77d84afe1 100644
--- a/src/stores/UserStore.js
+++ b/src/stores/UserStore.js
@@ -129,10 +129,6 @@ export default class UserStore extends Store {
129 return Boolean(localStorage.getItem('authToken')); 129 return Boolean(localStorage.getItem('authToken'));
130 } 130 }
131 131
132 // @computed get isTokenValid() {
133 // return this.authToken !== null && moment(this.tokenExpiry).isAfter(moment());
134 // }
135
136 @computed get isTokenExpired() { 132 @computed get isTokenExpired() {
137 if (!this.authToken) return false; 133 if (!this.authToken) return false;
138 134
@@ -160,6 +156,14 @@ export default class UserStore extends Store {
160 gaEvent('User', 'login'); 156 gaEvent('User', 'login');
161 } 157 }
162 158
159 @action _tokenLogin(authToken) {
160 this._setUserData(authToken);
161
162 this.stores.router.push('/');
163
164 gaEvent('User', 'tokenLogin');
165 }
166
163 @action async _signup({ 167 @action async _signup({
164 firstname, lastname, email, password, accountType, company, 168 firstname, lastname, email, password, accountType, company,
165 }) { 169 }) {
@@ -206,6 +210,8 @@ export default class UserStore extends Store {
206 } 210 }
207 211
208 @action async _update({ userData }) { 212 @action async _update({ userData }) {
213 if (!this.isLoggedIn) return;
214
209 const response = await this.updateUserInfoRequest.execute(userData)._promise; 215 const response = await this.updateUserInfoRequest.execute(userData)._promise;
210 216
211 this.getUserInfoRequest.patch(() => response.data); 217 this.getUserInfoRequest.patch(() => response.data);
@@ -222,6 +228,7 @@ export default class UserStore extends Store {
222 // workaround mobx issue 228 // workaround mobx issue
223 localStorage.removeItem('authToken'); 229 localStorage.removeItem('authToken');
224 window.localStorage.removeItem('authToken'); 230 window.localStorage.removeItem('authToken');
231
225 this.getUserInfoRequest.invalidate().reset(); 232 this.getUserInfoRequest.invalidate().reset();
226 this.authToken = null; 233 this.authToken = null;
227 } 234 }
@@ -262,6 +269,18 @@ export default class UserStore extends Store {
262 const { router } = this.stores; 269 const { router } = this.stores;
263 const currentRoute = router.location.pathname; 270 const currentRoute = router.location.pathname;
264 if (!this.isLoggedIn 271 if (!this.isLoggedIn
272 && currentRoute.includes('token=')) {
273 router.push(this.WELCOME_ROUTE);
274 const token = currentRoute.split('=')[1];
275
276 const data = this._parseToken(token);
277 if (data) {
278 // Give this some time to sink
279 setTimeout(() => {
280 this._tokenLogin(token);
281 }, 1000);
282 }
283 } else if (!this.isLoggedIn
265 && !currentRoute.includes(this.BASE_ROUTE)) { 284 && !currentRoute.includes(this.BASE_ROUTE)) {
266 router.push(this.WELCOME_ROUTE); 285 router.push(this.WELCOME_ROUTE);
267 } else if (this.isLoggedIn 286 } else if (this.isLoggedIn