diff options
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index ccb85421a..99b091589 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -7,7 +7,7 @@ import CachedRequest from './lib/CachedRequest'; | |||
7 | import { matchRoute } from '../helpers/routing-helpers'; | 7 | import { matchRoute } from '../helpers/routing-helpers'; |
8 | import { gaEvent } from '../lib/analytics'; | 8 | import { gaEvent } from '../lib/analytics'; |
9 | 9 | ||
10 | const debug = require('debug')('ServiceStore'); | 10 | const debug = require('debug')('Franz:ServiceStore'); |
11 | 11 | ||
12 | export default class ServicesStore extends Store { | 12 | export default class ServicesStore extends Store { |
13 | @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); | 13 | @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); |
@@ -67,9 +67,14 @@ export default class ServicesStore extends Store { | |||
67 | } | 67 | } |
68 | 68 | ||
69 | setup() { | 69 | setup() { |
70 | // Single key reactions | 70 | // Single key reactions for the sake of your CPU |
71 | reaction( | 71 | reaction( |
72 | () => this.stores.settings.all.app.enableSpellchecking, | 72 | () => this.stores.settings.app.enableSpellchecking, |
73 | () => this._shareSettingsWithServiceProcess(), | ||
74 | ); | ||
75 | |||
76 | reaction( | ||
77 | () => this.stores.settings.app.spellcheckerLanguage, | ||
73 | () => this._shareSettingsWithServiceProcess(), | 78 | () => this._shareSettingsWithServiceProcess(), |
74 | ); | 79 | ); |
75 | } | 80 | } |
@@ -93,7 +98,7 @@ export default class ServicesStore extends Store { | |||
93 | return this.stores.settings.all.app.showDisabledServices ? this.all : this.enabled; | 98 | return this.stores.settings.all.app.showDisabledServices ? this.all : this.enabled; |
94 | } | 99 | } |
95 | 100 | ||
96 | // This is just used to avoid unnecessary rerendering of resource-heavy webviews | 101 | // This is just used to avoid unnecessary rerendering of resource-heavy webviews |
97 | @computed get allDisplayedUnordered() { | 102 | @computed get allDisplayedUnordered() { |
98 | const services = this.allServicesRequest.execute().result || []; | 103 | const services = this.allServicesRequest.execute().result || []; |
99 | return this.stores.settings.all.app.showDisabledServices ? services : services.filter(service => service.isEnabled); | 104 | return this.stores.settings.all.app.showDisabledServices ? services : services.filter(service => service.isEnabled); |
@@ -143,6 +148,7 @@ export default class ServicesStore extends Store { | |||
143 | // Actions | 148 | // Actions |
144 | @action async _createService({ recipeId, serviceData, redirect = true }) { | 149 | @action async _createService({ recipeId, serviceData, redirect = true }) { |
145 | const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData); | 150 | const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData); |
151 | |||
146 | const response = await this.createServiceRequest.execute(recipeId, data)._promise; | 152 | const response = await this.createServiceRequest.execute(recipeId, data)._promise; |
147 | 153 | ||
148 | this.allServicesRequest.patch((result) => { | 154 | this.allServicesRequest.patch((result) => { |
@@ -150,6 +156,13 @@ export default class ServicesStore extends Store { | |||
150 | result.push(response.data); | 156 | result.push(response.data); |
151 | }); | 157 | }); |
152 | 158 | ||
159 | this.actions.settings.update({ | ||
160 | type: 'proxy', | ||
161 | data: { | ||
162 | [`${response.data.id}`]: data.proxy, | ||
163 | }, | ||
164 | }); | ||
165 | |||
153 | this.actionStatus = response.status || []; | 166 | this.actionStatus = response.status || []; |
154 | 167 | ||
155 | if (redirect) { | 168 | if (redirect) { |
@@ -214,6 +227,21 @@ export default class ServicesStore extends Store { | |||
214 | await request._promise; | 227 | await request._promise; |
215 | this.actionStatus = request.result.status; | 228 | this.actionStatus = request.result.status; |
216 | 229 | ||
230 | if (service.isEnabled) { | ||
231 | this._sendIPCMessage({ | ||
232 | serviceId, | ||
233 | channel: 'service-settings-update', | ||
234 | args: newData, | ||
235 | }); | ||
236 | } | ||
237 | |||
238 | this.actions.settings.update({ | ||
239 | type: 'proxy', | ||
240 | data: { | ||
241 | [`${serviceId}`]: data.proxy, | ||
242 | }, | ||
243 | }); | ||
244 | |||
217 | if (redirect) { | 245 | if (redirect) { |
218 | this.stores.router.push('/settings/services'); | 246 | this.stores.router.push('/settings/services'); |
219 | gaEvent('Service', 'update', service.recipe.id); | 247 | gaEvent('Service', 'update', service.recipe.id); |
@@ -411,6 +439,8 @@ export default class ServicesStore extends Store { | |||
411 | 439 | ||
412 | @action _reload({ serviceId }) { | 440 | @action _reload({ serviceId }) { |
413 | const service = this.one(serviceId); | 441 | const service = this.one(serviceId); |
442 | if (!service.isEnabled) return; | ||
443 | |||
414 | service.resetMessageCount(); | 444 | service.resetMessageCount(); |
415 | 445 | ||
416 | service.webview.loadURL(service.url); | 446 | service.webview.loadURL(service.url); |
@@ -567,9 +597,10 @@ export default class ServicesStore extends Store { | |||
567 | } | 597 | } |
568 | 598 | ||
569 | _shareSettingsWithServiceProcess() { | 599 | _shareSettingsWithServiceProcess() { |
600 | const settings = this.stores.settings.app; | ||
570 | this.actions.service.sendIPCMessageToAllServices({ | 601 | this.actions.service.sendIPCMessageToAllServices({ |
571 | channel: 'settings-update', | 602 | channel: 'settings-update', |
572 | args: this.stores.settings.all.app, | 603 | args: settings, |
573 | }); | 604 | }); |
574 | } | 605 | } |
575 | 606 | ||