diff options
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 3173004d4..185a6f0ae 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -1,3 +1,4 @@ | |||
1 | import { shell } from 'electron'; | ||
1 | import { | 2 | import { |
2 | action, | 3 | action, |
3 | reaction, | 4 | reaction, |
@@ -6,12 +7,15 @@ import { | |||
6 | } from 'mobx'; | 7 | } from 'mobx'; |
7 | import { remove } from 'lodash'; | 8 | import { remove } from 'lodash'; |
8 | import ms from 'ms'; | 9 | import ms from 'ms'; |
10 | import fs from 'fs-extra'; | ||
11 | import path from 'path'; | ||
9 | 12 | ||
10 | import Store from './lib/Store'; | 13 | import Store from './lib/Store'; |
11 | import Request from './lib/Request'; | 14 | import Request from './lib/Request'; |
12 | import CachedRequest from './lib/CachedRequest'; | 15 | import CachedRequest from './lib/CachedRequest'; |
13 | import { matchRoute } from '../helpers/routing-helpers'; | 16 | import { matchRoute } from '../helpers/routing-helpers'; |
14 | import { isInTimeframe } from '../helpers/schedule-helpers'; | 17 | import { isInTimeframe } from '../helpers/schedule-helpers'; |
18 | import { getRecipeDirectory, getDevRecipeDirectory } from '../helpers/recipe-helpers'; | ||
15 | import { workspaceStore } from '../features/workspaces'; | 19 | import { workspaceStore } from '../features/workspaces'; |
16 | import { serviceLimitStore } from '../features/serviceLimit'; | 20 | import { serviceLimitStore } from '../features/serviceLimit'; |
17 | import { RESTRICTION_TYPES } from '../models/Service'; | 21 | import { RESTRICTION_TYPES } from '../models/Service'; |
@@ -34,6 +38,11 @@ export default class ServicesStore extends Store { | |||
34 | 38 | ||
35 | @observable filterNeedle = null; | 39 | @observable filterNeedle = null; |
36 | 40 | ||
41 | // Array of service IDs that have recently been used | ||
42 | // [0] => Most recent, [n] => Least recent | ||
43 | // No service ID should be in the list multiple times, not all service IDs have to be in the list | ||
44 | @observable lastUsedServices = []; | ||
45 | |||
37 | constructor(...args) { | 46 | constructor(...args) { |
38 | super(...args); | 47 | super(...args); |
39 | 48 | ||
@@ -47,6 +56,7 @@ export default class ServicesStore extends Store { | |||
47 | this.actions.service.createFromLegacyService.listen(this._createFromLegacyService.bind(this)); | 56 | this.actions.service.createFromLegacyService.listen(this._createFromLegacyService.bind(this)); |
48 | this.actions.service.updateService.listen(this._updateService.bind(this)); | 57 | this.actions.service.updateService.listen(this._updateService.bind(this)); |
49 | this.actions.service.deleteService.listen(this._deleteService.bind(this)); | 58 | this.actions.service.deleteService.listen(this._deleteService.bind(this)); |
59 | this.actions.service.openDarkmodeCss.listen(this._openDarkmodeCss.bind(this)); | ||
50 | this.actions.service.clearCache.listen(this._clearCache.bind(this)); | 60 | this.actions.service.clearCache.listen(this._clearCache.bind(this)); |
51 | this.actions.service.setWebviewReference.listen(this._setWebviewReference.bind(this)); | 61 | this.actions.service.setWebviewReference.listen(this._setWebviewReference.bind(this)); |
52 | this.actions.service.detachService.listen(this._detachService.bind(this)); | 62 | this.actions.service.detachService.listen(this._detachService.bind(this)); |
@@ -70,6 +80,7 @@ export default class ServicesStore extends Store { | |||
70 | this.actions.service.toggleAudio.listen(this._toggleAudio.bind(this)); | 80 | this.actions.service.toggleAudio.listen(this._toggleAudio.bind(this)); |
71 | this.actions.service.openDevTools.listen(this._openDevTools.bind(this)); | 81 | this.actions.service.openDevTools.listen(this._openDevTools.bind(this)); |
72 | this.actions.service.openDevToolsForActiveService.listen(this._openDevToolsForActiveService.bind(this)); | 82 | this.actions.service.openDevToolsForActiveService.listen(this._openDevToolsForActiveService.bind(this)); |
83 | this.actions.service.setHibernation.listen(this._setHibernation.bind(this)); | ||
73 | 84 | ||
74 | this.registerReactions([ | 85 | this.registerReactions([ |
75 | this._focusServiceReaction.bind(this), | 86 | this._focusServiceReaction.bind(this), |
@@ -101,6 +112,11 @@ export default class ServicesStore extends Store { | |||
101 | () => this.stores.settings.app.darkMode, | 112 | () => this.stores.settings.app.darkMode, |
102 | () => this._shareSettingsWithServiceProcess(), | 113 | () => this._shareSettingsWithServiceProcess(), |
103 | ); | 114 | ); |
115 | |||
116 | reaction( | ||
117 | () => this.stores.settings.app.universalDarkMode, | ||
118 | () => this._shareSettingsWithServiceProcess(), | ||
119 | ); | ||
104 | } | 120 | } |
105 | 121 | ||
106 | @computed get all() { | 122 | @computed get all() { |
@@ -310,6 +326,27 @@ export default class ServicesStore extends Store { | |||
310 | this.actionStatus = request.result.status; | 326 | this.actionStatus = request.result.status; |
311 | } | 327 | } |
312 | 328 | ||
329 | @action async _openDarkmodeCss({ recipe }) { | ||
330 | // Get directory for recipe | ||
331 | const normalDirectory = getRecipeDirectory(recipe); | ||
332 | const devDirectory = getDevRecipeDirectory(recipe); | ||
333 | let directory; | ||
334 | |||
335 | if (await fs.pathExists(normalDirectory)) { | ||
336 | directory = normalDirectory; | ||
337 | } else if (await fs.pathExists(devDirectory)) { | ||
338 | directory = devDirectory; | ||
339 | } else { | ||
340 | // Recipe cannot be found on drive | ||
341 | return; | ||
342 | } | ||
343 | |||
344 | // Create and open darkmode.css | ||
345 | const file = path.join(directory, 'darkmode.css'); | ||
346 | await fs.ensureFile(file); | ||
347 | shell.showItemInFolder(file); | ||
348 | } | ||
349 | |||
313 | @action async _clearCache({ serviceId }) { | 350 | @action async _clearCache({ serviceId }) { |
314 | this.clearCacheRequest.reset(); | 351 | this.clearCacheRequest.reset(); |
315 | const request = this.clearCacheRequest.execute(serviceId); | 352 | const request = this.clearCacheRequest.execute(serviceId); |
@@ -325,6 +362,10 @@ export default class ServicesStore extends Store { | |||
325 | }); | 362 | }); |
326 | service.isActive = true; | 363 | service.isActive = true; |
327 | 364 | ||
365 | // Update list of last used services | ||
366 | this.lastUsedServices = this.lastUsedServices.filter(id => id !== serviceId); | ||
367 | this.lastUsedServices.unshift(serviceId); | ||
368 | |||
328 | this._focusActiveService(); | 369 | this._focusActiveService(); |
329 | } | 370 | } |
330 | 371 | ||
@@ -370,6 +411,7 @@ export default class ServicesStore extends Store { | |||
370 | service.initializeWebViewEvents({ | 411 | service.initializeWebViewEvents({ |
371 | handleIPCMessage: this.actions.service.handleIPCMessage, | 412 | handleIPCMessage: this.actions.service.handleIPCMessage, |
372 | openWindow: this.actions.service.openWindow, | 413 | openWindow: this.actions.service.openWindow, |
414 | stores: this.stores, | ||
373 | }); | 415 | }); |
374 | service.initializeWebViewListener(); | 416 | service.initializeWebViewListener(); |
375 | } | 417 | } |
@@ -638,6 +680,11 @@ export default class ServicesStore extends Store { | |||
638 | } | 680 | } |
639 | } | 681 | } |
640 | 682 | ||
683 | @action _setHibernation({ serviceId, hibernating }) { | ||
684 | const service = this.one(serviceId); | ||
685 | service.isHibernating = hibernating; | ||
686 | } | ||
687 | |||
641 | // Reactions | 688 | // Reactions |
642 | _focusServiceReaction() { | 689 | _focusServiceReaction() { |
643 | const service = this.active; | 690 | const service = this.active; |
@@ -727,6 +774,8 @@ export default class ServicesStore extends Store { | |||
727 | const serviceData = data; | 774 | const serviceData = data; |
728 | const recipe = this.stores.recipes.one(recipeId); | 775 | const recipe = this.stores.recipes.one(recipeId); |
729 | 776 | ||
777 | if (!recipe) return; | ||
778 | |||
730 | if (recipe.hasTeamId && recipe.hasCustomUrl && data.team && data.customUrl) { | 779 | if (recipe.hasTeamId && recipe.hasCustomUrl && data.team && data.customUrl) { |
731 | delete serviceData.team; | 780 | delete serviceData.team; |
732 | } | 781 | } |