aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js3
-rw-r--r--src/stores/FeaturesStore.js2
-rw-r--r--src/stores/RecipesStore.js2
-rw-r--r--src/stores/RequestStore.js9
-rw-r--r--src/stores/ServicesStore.js49
-rw-r--r--src/stores/SettingsStore.js14
6 files changed, 77 insertions, 2 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 5bae6e8d4..40d98cf42 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -22,6 +22,7 @@ import { getLocale } from '../helpers/i18n-helpers';
22 22
23import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; 23import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js';
24import { isValidExternalURL } from '../helpers/url-helpers'; 24import { isValidExternalURL } from '../helpers/url-helpers';
25import { sleep } from '../helpers/async-helpers';
25 26
26const debug = require('debug')('Ferdi:AppStore'); 27const debug = require('debug')('Ferdi:AppStore');
27 28
@@ -317,6 +318,8 @@ export default class AppStore extends Store {
317 318
318 await clearAppCache._promise; 319 await clearAppCache._promise;
319 320
321 await sleep(ms('1s'));
322
320 this.getAppCacheSizeRequest.execute(); 323 this.getAppCacheSizeRequest.execute();
321 324
322 this.isClearingAllCache = false; 325 this.isClearingAllCache = false;
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js
index c39b6d7f3..3d9542245 100644
--- a/src/stores/FeaturesStore.js
+++ b/src/stores/FeaturesStore.js
@@ -20,6 +20,7 @@ import settingsWS from '../features/settingsWS';
20import serviceLimit from '../features/serviceLimit'; 20import serviceLimit from '../features/serviceLimit';
21import communityRecipes from '../features/communityRecipes'; 21import communityRecipes from '../features/communityRecipes';
22import todos from '../features/todos'; 22import todos from '../features/todos';
23import accentColor from '../features/accentColor';
23 24
24import { DEFAULT_FEATURES_CONFIG } from '../config'; 25import { DEFAULT_FEATURES_CONFIG } from '../config';
25 26
@@ -83,5 +84,6 @@ export default class FeaturesStore extends Store {
83 serviceLimit(this.stores, this.actions); 84 serviceLimit(this.stores, this.actions);
84 communityRecipes(this.stores, this.actions); 85 communityRecipes(this.stores, this.actions);
85 todos(this.stores, this.actions); 86 todos(this.stores, this.actions);
87 accentColor(this.stores, this.actions);
86 } 88 }
87} 89}
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js
index 7f91049df..8b2bde5df 100644
--- a/src/stores/RecipesStore.js
+++ b/src/stores/RecipesStore.js
@@ -108,7 +108,7 @@ export default class RecipesStore extends Store {
108 async _checkIfRecipeIsInstalled() { 108 async _checkIfRecipeIsInstalled() {
109 const { router } = this.stores; 109 const { router } = this.stores;
110 110
111 const match = matchRoute('/settings/services/add/:id', router.location.pathname); 111 const match = router.location && matchRoute('/settings/services/add/:id', router.location.pathname);
112 if (match) { 112 if (match) {
113 const recipeId = match.id; 113 const recipeId = match.id;
114 114
diff --git a/src/stores/RequestStore.js b/src/stores/RequestStore.js
index 2587d4eef..a92f4c685 100644
--- a/src/stores/RequestStore.js
+++ b/src/stores/RequestStore.js
@@ -1,3 +1,4 @@
1import { ipcRenderer } from 'electron';
1import { action, computed, observable } from 'mobx'; 2import { action, computed, observable } from 'mobx';
2import ms from 'ms'; 3import ms from 'ms';
3 4
@@ -12,6 +13,8 @@ export default class RequestStore extends Store {
12 13
13 @observable showRequiredRequestsError = false; 14 @observable showRequiredRequestsError = false;
14 15
16 @observable localServerPort = 45569;
17
15 retries = 0; 18 retries = 0;
16 19
17 retryDelay = ms('2s'); 20 retryDelay = ms('2s');
@@ -29,6 +32,12 @@ export default class RequestStore extends Store {
29 setup() { 32 setup() {
30 this.userInfoRequest = this.stores.user.getUserInfoRequest; 33 this.userInfoRequest = this.stores.user.getUserInfoRequest;
31 this.servicesRequest = this.stores.services.allServicesRequest; 34 this.servicesRequest = this.stores.services.allServicesRequest;
35
36 ipcRenderer.on('localServerPort', (event, data) => {
37 if (data.port) {
38 this.localServerPort = data.port;
39 }
40 });
32 } 41 }
33 42
34 @computed get areRequiredRequestsSuccessful() { 43 @computed get areRequiredRequestsSuccessful() {
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 @@
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';
@@ -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 }
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index 8c4cd47eb..df0fc77e9 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -9,7 +9,7 @@ import Request from './lib/Request';
9import { getLocale } from '../helpers/i18n-helpers'; 9import { getLocale } from '../helpers/i18n-helpers';
10import { API } from '../environment'; 10import { API } from '../environment';
11 11
12import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; 12import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config';
13import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 13import { SPELLCHECKER_LOCALES } from '../i18n/languages';
14 14
15const debug = require('debug')('Ferdi:SettingsStore'); 15const debug = require('debug')('Ferdi:SettingsStore');
@@ -53,6 +53,18 @@ export default class SettingsStore extends Store {
53 ); 53 );
54 54
55 reaction( 55 reaction(
56 () => this.all.app.server,
57 (server) => {
58 if (server === LOCAL_SERVER) {
59 ipcRenderer.send('startLocalServer');
60 }
61 },
62 {
63 fireImmediately: true,
64 },
65 );
66
67 reaction(
56 () => this.all.app.locked, 68 () => this.all.app.locked,
57 () => { 69 () => {
58 const { router } = window.ferdi.stores; 70 const { router } = window.ferdi.stores;