diff options
author | vantezzen <hello@vantezzen.io> | 2019-10-16 11:06:27 +0200 |
---|---|---|
committer | vantezzen <hello@vantezzen.io> | 2019-10-16 11:06:27 +0200 |
commit | a56408ad7531c1f5e552f926a88cc4540d805b85 (patch) | |
tree | b2b544c5b8deec837df7499c04aaa419246a912a /src/stores/ServicesStore.js | |
parent | Add custom CSS for darkmode to fix WhatsApp and Threema QR codes (diff) | |
download | ferdium-app-a56408ad7531c1f5e552f926a88cc4540d805b85.tar.gz ferdium-app-a56408ad7531c1f5e552f926a88cc4540d805b85.tar.zst ferdium-app-a56408ad7531c1f5e552f926a88cc4540d805b85.zip |
Add button to directly open darkmode.css
Diffstat (limited to 'src/stores/ServicesStore.js')
-rw-r--r-- | src/stores/ServicesStore.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 1bf32af9f..9e952a6b1 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)); |
@@ -316,6 +321,27 @@ export default class ServicesStore extends Store { | |||
316 | this.actionStatus = request.result.status; | 321 | this.actionStatus = request.result.status; |
317 | } | 322 | } |
318 | 323 | ||
324 | @action async _openDarkmodeCss({ recipe }) { | ||
325 | // Get directory for recipe | ||
326 | const normalDirectory = getRecipeDirectory(recipe); | ||
327 | const devDirectory = getDevRecipeDirectory(recipe); | ||
328 | let directory; | ||
329 | |||
330 | if (await fs.pathExists(normalDirectory)) { | ||
331 | directory = normalDirectory; | ||
332 | } else if (await fs.pathExists(devDirectory)) { | ||
333 | directory = devDirectory; | ||
334 | } else { | ||
335 | // Recipe cannot be found on drive | ||
336 | return; | ||
337 | } | ||
338 | |||
339 | // Create and open darkmode.css | ||
340 | const file = path.join(directory, 'darkmode.css'); | ||
341 | await fs.ensureFile(file); | ||
342 | shell.showItemInFolder(file); | ||
343 | } | ||
344 | |||
319 | @action async _clearCache({ serviceId }) { | 345 | @action async _clearCache({ serviceId }) { |
320 | this.clearCacheRequest.reset(); | 346 | this.clearCacheRequest.reset(); |
321 | const request = this.clearCacheRequest.execute(serviceId); | 347 | const request = this.clearCacheRequest.execute(serviceId); |