aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r--src/stores/ServicesStore.js58
1 files changed, 41 insertions, 17 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index c38d0d9ee..cdb2db142 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -1,8 +1,5 @@
1// import { remote } from 'electron'; 1import { action, reaction, computed, observable } from 'mobx';
2import { action, computed, observable } from 'mobx';
3import { debounce, remove } from 'lodash'; 2import { debounce, remove } from 'lodash';
4// import path from 'path';
5// import fs from 'fs-extra';
6 3
7import Store from './lib/Store'; 4import Store from './lib/Store';
8import Request from './lib/Request'; 5import Request from './lib/Request';
@@ -10,6 +7,8 @@ import CachedRequest from './lib/CachedRequest';
10import { matchRoute } from '../helpers/routing-helpers'; 7import { matchRoute } from '../helpers/routing-helpers';
11import { gaEvent } from '../lib/analytics'; 8import { gaEvent } from '../lib/analytics';
12 9
10const debug = require('debug')('Franz:ServiceStore');
11
13export default class ServicesStore extends Store { 12export default class ServicesStore extends Store {
14 @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); 13 @observable allServicesRequest = new CachedRequest(this.api.services, 'all');
15 @observable createServiceRequest = new Request(this.api.services, 'create'); 14 @observable createServiceRequest = new Request(this.api.services, 'create');
@@ -61,13 +60,20 @@ export default class ServicesStore extends Store {
61 this._mapActiveServiceToServiceModelReaction.bind(this), 60 this._mapActiveServiceToServiceModelReaction.bind(this),
62 this._saveActiveService.bind(this), 61 this._saveActiveService.bind(this),
63 this._logoutReaction.bind(this), 62 this._logoutReaction.bind(this),
64 this._shareSettingsWithServiceProcess.bind(this),
65 ]); 63 ]);
66 64
67 // Just bind this 65 // Just bind this
68 this._initializeServiceRecipeInWebview.bind(this); 66 this._initializeServiceRecipeInWebview.bind(this);
69 } 67 }
70 68
69 setup() {
70 // Single key reactions
71 reaction(
72 () => this.stores.settings.all.app.enableSpellchecking,
73 () => this._shareSettingsWithServiceProcess(),
74 );
75 }
76
71 @computed get all() { 77 @computed get all() {
72 if (this.stores.user.isLoggedIn) { 78 if (this.stores.user.isLoggedIn) {
73 const services = this.allServicesRequest.execute().result; 79 const services = this.allServicesRequest.execute().result;
@@ -84,7 +90,13 @@ export default class ServicesStore extends Store {
84 } 90 }
85 91
86 @computed get allDisplayed() { 92 @computed get allDisplayed() {
87 return this.stores.settings.all.showDisabledServices ? this.all : this.enabled; 93 return this.stores.settings.all.app.showDisabledServices ? this.all : this.enabled;
94 }
95
96 // This is just used to avoid unnecessary rerendering of resource-heavy webviews
97 @computed get allDisplayedUnordered() {
98 const services = this.allServicesRequest.execute().result || [];
99 return this.stores.settings.all.app.showDisabledServices ? services : services.filter(service => service.isEnabled);
88 } 100 }
89 101
90 @computed get filtered() { 102 @computed get filtered() {
@@ -103,7 +115,7 @@ export default class ServicesStore extends Store {
103 return activeService; 115 return activeService;
104 } 116 }
105 117
106 console.warn('Service not available'); 118 debug('Service not available');
107 } 119 }
108 120
109 return null; 121 return null;
@@ -117,10 +129,10 @@ export default class ServicesStore extends Store {
117 const recipesStore = this.stores.recipes; 129 const recipesStore = this.stores.recipes;
118 130
119 if (recipesStore.isInstalled(recipeId)) { 131 if (recipesStore.isInstalled(recipeId)) {
120 console.debug('Recipe is installed'); 132 debug(`Recipe ${recipeId} is installed`);
121 this._redirectToAddServiceRoute(recipeId); 133 this._redirectToAddServiceRoute(recipeId);
122 } else { 134 } else {
123 console.warn('Recipe is not installed'); 135 debug(`Recipe ${recipeId} is not installed`);
124 // We access the RecipeStore action directly 136 // We access the RecipeStore action directly
125 // returns Promise instead of action 137 // returns Promise instead of action
126 await this.stores.recipes._install({ recipeId }); 138 await this.stores.recipes._install({ recipeId });
@@ -202,6 +214,14 @@ export default class ServicesStore extends Store {
202 await request._promise; 214 await request._promise;
203 this.actionStatus = request.result.status; 215 this.actionStatus = request.result.status;
204 216
217 if (service.isEnabled) {
218 this._sendIPCMessage({
219 serviceId,
220 channel: 'service-settings-update',
221 args: newData,
222 });
223 }
224
205 if (redirect) { 225 if (redirect) {
206 this.stores.router.push('/settings/services'); 226 this.stores.router.push('/settings/services');
207 gaEvent('Service', 'update', service.recipe.id); 227 gaEvent('Service', 'update', service.recipe.id);
@@ -326,7 +346,7 @@ export default class ServicesStore extends Store {
326 }); 346 });
327 } else if (channel === 'notification') { 347 } else if (channel === 'notification') {
328 const options = args[0].options; 348 const options = args[0].options;
329 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.isAppMuted) { 349 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) {
330 Object.assign(options, { 350 Object.assign(options, {
331 silent: true, 351 silent: true,
332 }); 352 });
@@ -426,7 +446,7 @@ export default class ServicesStore extends Store {
426 } 446 }
427 447
428 @action _reorder({ oldIndex, newIndex }) { 448 @action _reorder({ oldIndex, newIndex }) {
429 const showDisabledServices = this.stores.settings.all.showDisabledServices; 449 const showDisabledServices = this.stores.settings.all.app.showDisabledServices;
430 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); 450 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]);
431 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); 451 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]);
432 452
@@ -487,7 +507,7 @@ export default class ServicesStore extends Store {
487 if (service) { 507 if (service) {
488 service.webview.openDevTools(); 508 service.webview.openDevTools();
489 } else { 509 } else {
490 console.warn('No service is active'); 510 debug('No service is active');
491 } 511 }
492 } 512 }
493 513
@@ -504,7 +524,8 @@ export default class ServicesStore extends Store {
504 524
505 if (service) { 525 if (service) {
506 this.actions.settings.update({ 526 this.actions.settings.update({
507 settings: { 527 type: 'service',
528 data: {
508 activeService: service.id, 529 activeService: service.id,
509 }, 530 },
510 }); 531 });
@@ -512,7 +533,7 @@ export default class ServicesStore extends Store {
512 } 533 }
513 534
514 _mapActiveServiceToServiceModelReaction() { 535 _mapActiveServiceToServiceModelReaction() {
515 const { activeService } = this.stores.settings.all; 536 const { activeService } = this.stores.settings.all.service;
516 if (this.allDisplayed.length) { 537 if (this.allDisplayed.length) {
517 this.allDisplayed.map(service => Object.assign(service, { 538 this.allDisplayed.map(service => Object.assign(service, {
518 isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id, 539 isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id,
@@ -521,7 +542,7 @@ export default class ServicesStore extends Store {
521 } 542 }
522 543
523 _getUnreadMessageCountReaction() { 544 _getUnreadMessageCountReaction() {
524 const showMessageBadgeWhenMuted = this.stores.settings.all.showMessageBadgeWhenMuted; 545 const showMessageBadgeWhenMuted = this.stores.settings.all.app.showMessageBadgeWhenMuted;
525 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; 546 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted;
526 547
527 const unreadDirectMessageCount = this.allDisplayed 548 const unreadDirectMessageCount = this.allDisplayed
@@ -545,7 +566,10 @@ export default class ServicesStore extends Store {
545 566
546 _logoutReaction() { 567 _logoutReaction() {
547 if (!this.stores.user.isLoggedIn) { 568 if (!this.stores.user.isLoggedIn) {
548 this.actions.settings.remove({ key: 'activeService' }); 569 this.actions.settings.remove({
570 type: 'service',
571 key: 'activeService',
572 });
549 this.allServicesRequest.invalidate().reset(); 573 this.allServicesRequest.invalidate().reset();
550 } 574 }
551 } 575 }
@@ -553,7 +577,7 @@ export default class ServicesStore extends Store {
553 _shareSettingsWithServiceProcess() { 577 _shareSettingsWithServiceProcess() {
554 this.actions.service.sendIPCMessageToAllServices({ 578 this.actions.service.sendIPCMessageToAllServices({
555 channel: 'settings-update', 579 channel: 'settings-update',
556 args: this.stores.settings.all, 580 args: this.stores.settings.all.app,
557 }); 581 });
558 } 582 }
559 583