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.js36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index f7d92b1ff..ccb85421a 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';
@@ -63,13 +60,20 @@ export default class ServicesStore extends Store {
63 this._mapActiveServiceToServiceModelReaction.bind(this), 60 this._mapActiveServiceToServiceModelReaction.bind(this),
64 this._saveActiveService.bind(this), 61 this._saveActiveService.bind(this),
65 this._logoutReaction.bind(this), 62 this._logoutReaction.bind(this),
66 this._shareSettingsWithServiceProcess.bind(this),
67 ]); 63 ]);
68 64
69 // Just bind this 65 // Just bind this
70 this._initializeServiceRecipeInWebview.bind(this); 66 this._initializeServiceRecipeInWebview.bind(this);
71 } 67 }
72 68
69 setup() {
70 // Single key reactions
71 reaction(
72 () => this.stores.settings.all.app.enableSpellchecking,
73 () => this._shareSettingsWithServiceProcess(),
74 );
75 }
76
73 @computed get all() { 77 @computed get all() {
74 if (this.stores.user.isLoggedIn) { 78 if (this.stores.user.isLoggedIn) {
75 const services = this.allServicesRequest.execute().result; 79 const services = this.allServicesRequest.execute().result;
@@ -86,13 +90,13 @@ export default class ServicesStore extends Store {
86 } 90 }
87 91
88 @computed get allDisplayed() { 92 @computed get allDisplayed() {
89 return this.stores.settings.all.showDisabledServices ? this.all : this.enabled; 93 return this.stores.settings.all.app.showDisabledServices ? this.all : this.enabled;
90 } 94 }
91 95
92 // This is just used to avoid unnecessary rerendering of resource-heavy webviews 96 // This is just used to avoid unnecessary rerendering of resource-heavy webviews
93 @computed get allDisplayedUnordered() { 97 @computed get allDisplayedUnordered() {
94 const services = this.allServicesRequest.execute().result || []; 98 const services = this.allServicesRequest.execute().result || [];
95 return this.stores.settings.all.showDisabledServices ? services : services.filter(service => service.isEnabled); 99 return this.stores.settings.all.app.showDisabledServices ? services : services.filter(service => service.isEnabled);
96 } 100 }
97 101
98 @computed get filtered() { 102 @computed get filtered() {
@@ -334,7 +338,7 @@ export default class ServicesStore extends Store {
334 }); 338 });
335 } else if (channel === 'notification') { 339 } else if (channel === 'notification') {
336 const options = args[0].options; 340 const options = args[0].options;
337 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.isAppMuted) { 341 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) {
338 Object.assign(options, { 342 Object.assign(options, {
339 silent: true, 343 silent: true,
340 }); 344 });
@@ -434,7 +438,7 @@ export default class ServicesStore extends Store {
434 } 438 }
435 439
436 @action _reorder({ oldIndex, newIndex }) { 440 @action _reorder({ oldIndex, newIndex }) {
437 const showDisabledServices = this.stores.settings.all.showDisabledServices; 441 const showDisabledServices = this.stores.settings.all.app.showDisabledServices;
438 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); 442 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]);
439 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); 443 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]);
440 444
@@ -512,7 +516,8 @@ export default class ServicesStore extends Store {
512 516
513 if (service) { 517 if (service) {
514 this.actions.settings.update({ 518 this.actions.settings.update({
515 settings: { 519 type: 'service',
520 data: {
516 activeService: service.id, 521 activeService: service.id,
517 }, 522 },
518 }); 523 });
@@ -520,7 +525,7 @@ export default class ServicesStore extends Store {
520 } 525 }
521 526
522 _mapActiveServiceToServiceModelReaction() { 527 _mapActiveServiceToServiceModelReaction() {
523 const { activeService } = this.stores.settings.all; 528 const { activeService } = this.stores.settings.all.service;
524 if (this.allDisplayed.length) { 529 if (this.allDisplayed.length) {
525 this.allDisplayed.map(service => Object.assign(service, { 530 this.allDisplayed.map(service => Object.assign(service, {
526 isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id, 531 isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id,
@@ -529,7 +534,7 @@ export default class ServicesStore extends Store {
529 } 534 }
530 535
531 _getUnreadMessageCountReaction() { 536 _getUnreadMessageCountReaction() {
532 const showMessageBadgeWhenMuted = this.stores.settings.all.showMessageBadgeWhenMuted; 537 const showMessageBadgeWhenMuted = this.stores.settings.all.app.showMessageBadgeWhenMuted;
533 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; 538 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted;
534 539
535 const unreadDirectMessageCount = this.allDisplayed 540 const unreadDirectMessageCount = this.allDisplayed
@@ -553,7 +558,10 @@ export default class ServicesStore extends Store {
553 558
554 _logoutReaction() { 559 _logoutReaction() {
555 if (!this.stores.user.isLoggedIn) { 560 if (!this.stores.user.isLoggedIn) {
556 this.actions.settings.remove({ key: 'activeService' }); 561 this.actions.settings.remove({
562 type: 'service',
563 key: 'activeService',
564 });
557 this.allServicesRequest.invalidate().reset(); 565 this.allServicesRequest.invalidate().reset();
558 } 566 }
559 } 567 }
@@ -561,7 +569,7 @@ export default class ServicesStore extends Store {
561 _shareSettingsWithServiceProcess() { 569 _shareSettingsWithServiceProcess() {
562 this.actions.service.sendIPCMessageToAllServices({ 570 this.actions.service.sendIPCMessageToAllServices({
563 channel: 'settings-update', 571 channel: 'settings-update',
564 args: this.stores.settings.all, 572 args: this.stores.settings.all.app,
565 }); 573 });
566 } 574 }
567 575