diff options
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 1bf32af9f..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'; |
@@ -52,6 +56,7 @@ export default class ServicesStore extends Store { | |||
52 | this.actions.service.createFromLegacyService.listen(this._createFromLegacyService.bind(this)); | 56 | this.actions.service.createFromLegacyService.listen(this._createFromLegacyService.bind(this)); |
53 | this.actions.service.updateService.listen(this._updateService.bind(this)); | 57 | this.actions.service.updateService.listen(this._updateService.bind(this)); |
54 | 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)); | ||
55 | this.actions.service.clearCache.listen(this._clearCache.bind(this)); | 60 | this.actions.service.clearCache.listen(this._clearCache.bind(this)); |
56 | this.actions.service.setWebviewReference.listen(this._setWebviewReference.bind(this)); | 61 | this.actions.service.setWebviewReference.listen(this._setWebviewReference.bind(this)); |
57 | this.actions.service.detachService.listen(this._detachService.bind(this)); | 62 | this.actions.service.detachService.listen(this._detachService.bind(this)); |
@@ -107,6 +112,11 @@ export default class ServicesStore extends Store { | |||
107 | () => this.stores.settings.app.darkMode, | 112 | () => this.stores.settings.app.darkMode, |
108 | () => this._shareSettingsWithServiceProcess(), | 113 | () => this._shareSettingsWithServiceProcess(), |
109 | ); | 114 | ); |
115 | |||
116 | reaction( | ||
117 | () => this.stores.settings.app.universalDarkMode, | ||
118 | () => this._shareSettingsWithServiceProcess(), | ||
119 | ); | ||
110 | } | 120 | } |
111 | 121 | ||
112 | @computed get all() { | 122 | @computed get all() { |
@@ -316,6 +326,27 @@ export default class ServicesStore extends Store { | |||
316 | this.actionStatus = request.result.status; | 326 | this.actionStatus = request.result.status; |
317 | } | 327 | } |
318 | 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 | |||
319 | @action async _clearCache({ serviceId }) { | 350 | @action async _clearCache({ serviceId }) { |
320 | this.clearCacheRequest.reset(); | 351 | this.clearCacheRequest.reset(); |
321 | const request = this.clearCacheRequest.execute(serviceId); | 352 | const request = this.clearCacheRequest.execute(serviceId); |