diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-11-23 16:17:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 16:17:34 +0100 |
commit | abca425e4a7b63be93132067bc335e8b6b39c2b2 (patch) | |
tree | e386f3e5d4c1c1caff19e3555e7ed1ce93e625f6 /src/stores/ServicesStore.js | |
parent | replace typeform (diff) | |
parent | Add windows notification fix to changelog (diff) | |
download | ferdium-app-abca425e4a7b63be93132067bc335e8b6b39c2b2.tar.gz ferdium-app-abca425e4a7b63be93132067bc335e8b6b39c2b2.tar.zst ferdium-app-abca425e4a7b63be93132067bc335e8b6b39c2b2.zip |
Merge pull request #330 from meetfranz/developv5.0.0-beta.14
Beta 14
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 83 |
1 files changed, 60 insertions, 23 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 1d895d532..22c376c06 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -37,6 +37,7 @@ export default class ServicesStore extends Store { | |||
37 | this.actions.service.toggleService.listen(this._toggleService.bind(this)); | 37 | this.actions.service.toggleService.listen(this._toggleService.bind(this)); |
38 | this.actions.service.handleIPCMessage.listen(this._handleIPCMessage.bind(this)); | 38 | this.actions.service.handleIPCMessage.listen(this._handleIPCMessage.bind(this)); |
39 | this.actions.service.sendIPCMessage.listen(this._sendIPCMessage.bind(this)); | 39 | this.actions.service.sendIPCMessage.listen(this._sendIPCMessage.bind(this)); |
40 | this.actions.service.sendIPCMessageToAllServices.listen(this._sendIPCMessageToAllServices.bind(this)); | ||
40 | this.actions.service.setUnreadMessageCount.listen(this._setUnreadMessageCount.bind(this)); | 41 | this.actions.service.setUnreadMessageCount.listen(this._setUnreadMessageCount.bind(this)); |
41 | this.actions.service.openWindow.listen(this._openWindow.bind(this)); | 42 | this.actions.service.openWindow.listen(this._openWindow.bind(this)); |
42 | this.actions.service.filter.listen(this._filter.bind(this)); | 43 | this.actions.service.filter.listen(this._filter.bind(this)); |
@@ -48,6 +49,7 @@ export default class ServicesStore extends Store { | |||
48 | this.actions.service.reloadUpdatedServices.listen(this._reloadUpdatedServices.bind(this)); | 49 | this.actions.service.reloadUpdatedServices.listen(this._reloadUpdatedServices.bind(this)); |
49 | this.actions.service.reorder.listen(this._reorder.bind(this)); | 50 | this.actions.service.reorder.listen(this._reorder.bind(this)); |
50 | this.actions.service.toggleNotifications.listen(this._toggleNotifications.bind(this)); | 51 | this.actions.service.toggleNotifications.listen(this._toggleNotifications.bind(this)); |
52 | this.actions.service.toggleAudio.listen(this._toggleAudio.bind(this)); | ||
51 | this.actions.service.openDevTools.listen(this._openDevTools.bind(this)); | 53 | this.actions.service.openDevTools.listen(this._openDevTools.bind(this)); |
52 | this.actions.service.openDevToolsForActiveService.listen(this._openDevToolsForActiveService.bind(this)); | 54 | this.actions.service.openDevToolsForActiveService.listen(this._openDevToolsForActiveService.bind(this)); |
53 | 55 | ||
@@ -57,6 +59,7 @@ export default class ServicesStore extends Store { | |||
57 | this._mapActiveServiceToServiceModelReaction.bind(this), | 59 | this._mapActiveServiceToServiceModelReaction.bind(this), |
58 | this._saveActiveService.bind(this), | 60 | this._saveActiveService.bind(this), |
59 | this._logoutReaction.bind(this), | 61 | this._logoutReaction.bind(this), |
62 | this._shareSettingsWithServiceProcess.bind(this), | ||
60 | ]); | 63 | ]); |
61 | 64 | ||
62 | // Just bind this | 65 | // Just bind this |
@@ -78,6 +81,10 @@ export default class ServicesStore extends Store { | |||
78 | return this.all.filter(service => service.isEnabled); | 81 | return this.all.filter(service => service.isEnabled); |
79 | } | 82 | } |
80 | 83 | ||
84 | @computed get allDisplayed() { | ||
85 | return this.stores.settings.all.showDisabledServices ? this.all : this.enabled; | ||
86 | } | ||
87 | |||
81 | @computed get filtered() { | 88 | @computed get filtered() { |
82 | return this.all.filter(service => service.name.toLowerCase().includes(this.filterNeedle.toLowerCase())); | 89 | return this.all.filter(service => service.name.toLowerCase().includes(this.filterNeedle.toLowerCase())); |
83 | } | 90 | } |
@@ -208,21 +215,23 @@ export default class ServicesStore extends Store { | |||
208 | } | 215 | } |
209 | 216 | ||
210 | @action _setActiveNext() { | 217 | @action _setActiveNext() { |
211 | const nextIndex = this._wrapIndex(this.enabled.findIndex(service => service.isActive), 1, this.enabled.length); | 218 | const nextIndex = this._wrapIndex(this.allDisplayed.findIndex(service => service.isActive), 1, this.allDisplayed.length); |
212 | 219 | ||
220 | // TODO: simplify this; | ||
213 | this.all.forEach((s, index) => { | 221 | this.all.forEach((s, index) => { |
214 | this.all[index].isActive = false; | 222 | this.all[index].isActive = false; |
215 | }); | 223 | }); |
216 | this.enabled[nextIndex].isActive = true; | 224 | this.allDisplayed[nextIndex].isActive = true; |
217 | } | 225 | } |
218 | 226 | ||
219 | @action _setActivePrev() { | 227 | @action _setActivePrev() { |
220 | const prevIndex = this._wrapIndex(this.enabled.findIndex(service => service.isActive), -1, this.enabled.length); | 228 | const prevIndex = this._wrapIndex(this.allDisplayed.findIndex(service => service.isActive), -1, this.allDisplayed.length); |
221 | 229 | ||
230 | // TODO: simplify this; | ||
222 | this.all.forEach((s, index) => { | 231 | this.all.forEach((s, index) => { |
223 | this.all[index].isActive = false; | 232 | this.all[index].isActive = false; |
224 | }); | 233 | }); |
225 | this.enabled[prevIndex].isActive = true; | 234 | this.allDisplayed[prevIndex].isActive = true; |
226 | } | 235 | } |
227 | 236 | ||
228 | @action _setUnreadMessageCount({ serviceId, count }) { | 237 | @action _setUnreadMessageCount({ serviceId, count }) { |
@@ -277,6 +286,7 @@ export default class ServicesStore extends Store { | |||
277 | if (channel === 'hello') { | 286 | if (channel === 'hello') { |
278 | this._initRecipePolling(service.id); | 287 | this._initRecipePolling(service.id); |
279 | this._initializeServiceRecipeInWebview(serviceId); | 288 | this._initializeServiceRecipeInWebview(serviceId); |
289 | this._shareSettingsWithServiceProcess(); | ||
280 | } else if (channel === 'messages') { | 290 | } else if (channel === 'messages') { |
281 | this.actions.service.setUnreadMessageCount({ | 291 | this.actions.service.setUnreadMessageCount({ |
282 | serviceId, | 292 | serviceId, |
@@ -287,7 +297,7 @@ export default class ServicesStore extends Store { | |||
287 | }); | 297 | }); |
288 | } else if (channel === 'notification') { | 298 | } else if (channel === 'notification') { |
289 | const options = args[0].options; | 299 | const options = args[0].options; |
290 | if (service.recipe.hasNotificationSound) { | 300 | if (service.recipe.hasNotificationSound || service.isMuted) { |
291 | Object.assign(options, { | 301 | Object.assign(options, { |
292 | silent: true, | 302 | silent: true, |
293 | }); | 303 | }); |
@@ -323,7 +333,17 @@ export default class ServicesStore extends Store { | |||
323 | @action _sendIPCMessage({ serviceId, channel, args }) { | 333 | @action _sendIPCMessage({ serviceId, channel, args }) { |
324 | const service = this.one(serviceId); | 334 | const service = this.one(serviceId); |
325 | 335 | ||
326 | service.webview.send(channel, args); | 336 | if (service.webview) { |
337 | service.webview.send(channel, args); | ||
338 | } | ||
339 | } | ||
340 | |||
341 | @action _sendIPCMessageToAllServices({ channel, args }) { | ||
342 | this.all.forEach(s => this.actions.service.sendIPCMessage({ | ||
343 | serviceId: s.id, | ||
344 | channel, | ||
345 | args, | ||
346 | })); | ||
327 | } | 347 | } |
328 | 348 | ||
329 | @action _openWindow({ event }) { | 349 | @action _openWindow({ event }) { |
@@ -373,9 +393,9 @@ export default class ServicesStore extends Store { | |||
373 | } | 393 | } |
374 | 394 | ||
375 | @action _reorder({ oldIndex, newIndex }) { | 395 | @action _reorder({ oldIndex, newIndex }) { |
376 | const oldEnabledSortIndex = this.all.indexOf(this.enabled[oldIndex]); | 396 | const showDisabledServices = this.stores.settings.all.showDisabledServices; |
377 | const newEnabledSortIndex = this.all.indexOf(this.enabled[newIndex]); | 397 | const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); |
378 | 398 | const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); | |
379 | 399 | ||
380 | this.all.splice(newEnabledSortIndex, 0, this.all.splice(oldEnabledSortIndex, 1)[0]); | 400 | this.all.splice(newEnabledSortIndex, 0, this.all.splice(oldEnabledSortIndex, 1)[0]); |
381 | 401 | ||
@@ -399,11 +419,25 @@ export default class ServicesStore extends Store { | |||
399 | @action _toggleNotifications({ serviceId }) { | 419 | @action _toggleNotifications({ serviceId }) { |
400 | const service = this.one(serviceId); | 420 | const service = this.one(serviceId); |
401 | 421 | ||
422 | this.actions.service.updateService({ | ||
423 | serviceId, | ||
424 | serviceData: { | ||
425 | isNotificationEnabled: !service.isNotificationEnabled, | ||
426 | }, | ||
427 | redirect: false, | ||
428 | }); | ||
429 | } | ||
430 | |||
431 | @action _toggleAudio({ serviceId }) { | ||
432 | const service = this.one(serviceId); | ||
433 | |||
402 | service.isNotificationEnabled = !service.isNotificationEnabled; | 434 | service.isNotificationEnabled = !service.isNotificationEnabled; |
403 | 435 | ||
404 | this.actions.service.updateService({ | 436 | this.actions.service.updateService({ |
405 | serviceId, | 437 | serviceId, |
406 | serviceData: service, | 438 | serviceData: { |
439 | isMuted: !service.isMuted, | ||
440 | }, | ||
407 | redirect: false, | 441 | redirect: false, |
408 | }); | 442 | }); |
409 | } | 443 | } |
@@ -436,27 +470,21 @@ export default class ServicesStore extends Store { | |||
436 | const service = this.active; | 470 | const service = this.active; |
437 | 471 | ||
438 | if (service) { | 472 | if (service) { |
439 | this.stores.settings.updateSettingsRequest.execute({ | 473 | this.actions.settings.update({ |
440 | activeService: service.id, | 474 | settings: { |
475 | activeService: service.id, | ||
476 | }, | ||
441 | }); | 477 | }); |
442 | } | 478 | } |
443 | } | 479 | } |
444 | 480 | ||
445 | _mapActiveServiceToServiceModelReaction() { | 481 | _mapActiveServiceToServiceModelReaction() { |
446 | const { activeService } = this.stores.settings.all; | 482 | const { activeService } = this.stores.settings.all; |
447 | const services = this.enabled; | 483 | if (this.allDisplayed.length) { |
448 | if (services.length) { | 484 | this.allDisplayed.map(service => Object.assign(service, { |
449 | services.map(service => Object.assign(service, { | 485 | isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id, |
450 | isActive: activeService ? activeService === service.id : services[0].id === service.id, | ||
451 | })); | 486 | })); |
452 | |||
453 | // if (!services.active) { | ||
454 | // | ||
455 | // } | ||
456 | } | 487 | } |
457 | // else if (!activeService && services.length) { | ||
458 | // services[0].isActive = true; | ||
459 | // } | ||
460 | } | 488 | } |
461 | 489 | ||
462 | _getUnreadMessageCountReaction() { | 490 | _getUnreadMessageCountReaction() { |
@@ -482,6 +510,13 @@ export default class ServicesStore extends Store { | |||
482 | } | 510 | } |
483 | } | 511 | } |
484 | 512 | ||
513 | _shareSettingsWithServiceProcess() { | ||
514 | this.actions.service.sendIPCMessageToAllServices({ | ||
515 | channel: 'settings-update', | ||
516 | args: this.stores.settings.all, | ||
517 | }); | ||
518 | } | ||
519 | |||
485 | _cleanUpTeamIdAndCustomUrl(recipeId, data) { | 520 | _cleanUpTeamIdAndCustomUrl(recipeId, data) { |
486 | const serviceData = data; | 521 | const serviceData = data; |
487 | const recipe = this.stores.recipes.one(recipeId); | 522 | const recipe = this.stores.recipes.one(recipeId); |
@@ -514,6 +549,8 @@ export default class ServicesStore extends Store { | |||
514 | 549 | ||
515 | if (service) { | 550 | if (service) { |
516 | const loop = () => { | 551 | const loop = () => { |
552 | if (!service.webview) return; | ||
553 | |||
517 | service.webview.send('poll'); | 554 | service.webview.send('poll'); |
518 | 555 | ||
519 | setTimeout(loop, delay); | 556 | setTimeout(loop, delay); |