aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/ServicesStore.js
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2019-10-16 11:06:27 +0200
committerLibravatar vantezzen <hello@vantezzen.io>2019-10-16 11:06:27 +0200
commita56408ad7531c1f5e552f926a88cc4540d805b85 (patch)
treeb2b544c5b8deec837df7499c04aaa419246a912a /src/stores/ServicesStore.js
parentAdd custom CSS for darkmode to fix WhatsApp and Threema QR codes (diff)
downloadferdium-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.js26
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 @@
1import { shell } from 'electron';
1import { 2import {
2 action, 3 action,
3 reaction, 4 reaction,
@@ -6,12 +7,15 @@ import {
6} from 'mobx'; 7} from 'mobx';
7import { remove } from 'lodash'; 8import { remove } from 'lodash';
8import ms from 'ms'; 9import ms from 'ms';
10import fs from 'fs-extra';
11import path from 'path';
9 12
10import Store from './lib/Store'; 13import Store from './lib/Store';
11import Request from './lib/Request'; 14import Request from './lib/Request';
12import CachedRequest from './lib/CachedRequest'; 15import CachedRequest from './lib/CachedRequest';
13import { matchRoute } from '../helpers/routing-helpers'; 16import { matchRoute } from '../helpers/routing-helpers';
14import { isInTimeframe } from '../helpers/schedule-helpers'; 17import { isInTimeframe } from '../helpers/schedule-helpers';
18import { getRecipeDirectory, getDevRecipeDirectory } from '../helpers/recipe-helpers';
15import { workspaceStore } from '../features/workspaces'; 19import { workspaceStore } from '../features/workspaces';
16import { serviceLimitStore } from '../features/serviceLimit'; 20import { serviceLimitStore } from '../features/serviceLimit';
17import { RESTRICTION_TYPES } from '../models/Service'; 21import { 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);