aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-08-24 10:22:22 +0530
committerLibravatar Vijay A <avijayr@protonmail.com>2021-08-24 10:22:22 +0530
commit2dc7b2fd3976853f3dc2f182f12cfe11c3b83688 (patch)
tree22fc7a9e4d3ddd2be16821c871259fb067c7df30 /src/stores
parentdocs: upgraded version to 5.6.1-beta.1 (diff)
parent5.6.1-nightly.37 [skip ci] (diff)
downloadferdium-app-2dc7b2fd3976853f3dc2f182f12cfe11c3b83688.tar.gz
ferdium-app-2dc7b2fd3976853f3dc2f182f12cfe11c3b83688.tar.zst
ferdium-app-2dc7b2fd3976853f3dc2f182f12cfe11c3b83688.zip
Merge remote-tracking branch 'origin/develop' into release
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js23
-rw-r--r--src/stores/FeaturesStore.js2
-rw-r--r--src/stores/ServicesStore.js144
-rw-r--r--src/stores/SettingsStore.js12
-rw-r--r--src/stores/UIStore.js8
-rw-r--r--src/stores/index.ts (renamed from src/stores/index.js)5
6 files changed, 107 insertions, 87 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 1d706f1ef..9c8cce679 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -1,4 +1,4 @@
1import { ipcRenderer, shell } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { 2import {
3 app, 3 app,
4 screen, 4 screen,
@@ -24,16 +24,16 @@ import {
24 electronVersion, 24 electronVersion,
25 osRelease, 25 osRelease,
26 userDataPath, 26 userDataPath,
27 ferdiLocale,
27} from '../environment'; 28} from '../environment';
28import locales from '../i18n/translations'; 29import locales from '../i18n/translations';
29import { onVisibilityChange } from '../helpers/visibility-helper';
30import { getLocale } from '../helpers/i18n-helpers'; 30import { getLocale } from '../helpers/i18n-helpers';
31 31
32import { 32import {
33 getServiceIdsFromPartitions, 33 getServiceIdsFromPartitions,
34 removeServicePartitionDirectory, 34 removeServicePartitionDirectory,
35} from '../helpers/service-helpers'; 35} from '../helpers/service-helpers';
36import { isValidExternalURL } from '../helpers/url-helpers'; 36import { openExternalUrl } from '../helpers/url-helpers';
37import { sleep } from '../helpers/async-helpers'; 37import { sleep } from '../helpers/async-helpers';
38 38
39const debug = require('debug')('Ferdi:AppStore'); 39const debug = require('debug')('Ferdi:AppStore');
@@ -220,10 +220,9 @@ export default class AppStore extends Store {
220 220
221 this.isSystemDarkModeEnabled = nativeTheme.shouldUseDarkColors; 221 this.isSystemDarkModeEnabled = nativeTheme.shouldUseDarkColors;
222 222
223 onVisibilityChange((isVisible) => { 223 ipcRenderer.on('isWindowFocused', (event, isFocused) => {
224 this.isFocused = isVisible; 224 debug('Setting is focused to', isFocused);
225 225 this.isFocused = isFocused;
226 debug('Window is visible/focused', isVisible);
227 }); 226 });
228 227
229 powerMonitor.on('suspend', () => { 228 powerMonitor.on('suspend', () => {
@@ -389,13 +388,9 @@ export default class AppStore extends Store {
389 } 388 }
390 } 389 }
391 390
391 // Ideally(?) this should be merged with the 'shell-helpers' functionality
392 @action _openExternalUrl({ url }) { 392 @action _openExternalUrl({ url }) {
393 const parsedUrl = new URL(url); 393 openExternalUrl(new URL(url));
394 debug('open external url', parsedUrl);
395
396 if (isValidExternalURL(url)) {
397 shell.openExternal(url);
398 }
399 } 394 }
400 395
401 @action _checkForUpdates() { 396 @action _checkForUpdates() {
@@ -509,7 +504,7 @@ export default class AppStore extends Store {
509 504
510 _getDefaultLocale() { 505 _getDefaultLocale() {
511 return getLocale({ 506 return getLocale({
512 locale: app.getLocale(), 507 locale: ferdiLocale,
513 locales, 508 locales,
514 defaultLocale, 509 defaultLocale,
515 fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale, 510 fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale,
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js
index ac623c258..0dff2fda2 100644
--- a/src/stores/FeaturesStore.js
+++ b/src/stores/FeaturesStore.js
@@ -13,7 +13,6 @@ import workspaces from '../features/workspaces';
13import quickSwitch from '../features/quickSwitch'; 13import quickSwitch from '../features/quickSwitch';
14import nightlyBuilds from '../features/nightlyBuilds'; 14import nightlyBuilds from '../features/nightlyBuilds';
15import publishDebugInfo from '../features/publishDebugInfo'; 15import publishDebugInfo from '../features/publishDebugInfo';
16import shareFranz from '../features/shareFranz';
17import announcements from '../features/announcements'; 16import announcements from '../features/announcements';
18import settingsWS from '../features/settingsWS'; 17import settingsWS from '../features/settingsWS';
19import communityRecipes from '../features/communityRecipes'; 18import communityRecipes from '../features/communityRecipes';
@@ -73,7 +72,6 @@ export default class FeaturesStore extends Store {
73 quickSwitch(this.stores, this.actions); 72 quickSwitch(this.stores, this.actions);
74 nightlyBuilds(this.stores, this.actions); 73 nightlyBuilds(this.stores, this.actions);
75 publishDebugInfo(this.stores, this.actions); 74 publishDebugInfo(this.stores, this.actions);
76 shareFranz(this.stores, this.actions);
77 announcements(this.stores, this.actions); 75 announcements(this.stores, this.actions);
78 settingsWS(this.stores, this.actions); 76 settingsWS(this.stores, this.actions);
79 communityRecipes(this.stores, this.actions); 77 communityRecipes(this.stores, this.actions);
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 4ccb995ae..8598c6234 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -2,7 +2,6 @@ import { shell } from 'electron';
2import { action, reaction, computed, observable } from 'mobx'; 2import { action, reaction, computed, observable } from 'mobx';
3import { debounce, remove } from 'lodash'; 3import { debounce, remove } from 'lodash';
4import ms from 'ms'; 4import ms from 'ms';
5import { app } from '@electron/remote';
6import { ensureFileSync, pathExistsSync, writeFileSync } from 'fs-extra'; 5import { ensureFileSync, pathExistsSync, writeFileSync } from 'fs-extra';
7import { join } from 'path'; 6import { join } from 'path';
8 7
@@ -11,13 +10,11 @@ import Request from './lib/Request';
11import CachedRequest from './lib/CachedRequest'; 10import CachedRequest from './lib/CachedRequest';
12import { matchRoute } from '../helpers/routing-helpers'; 11import { matchRoute } from '../helpers/routing-helpers';
13import { isInTimeframe } from '../helpers/schedule-helpers'; 12import { isInTimeframe } from '../helpers/schedule-helpers';
14import { 13import { getRecipeDirectory, getDevRecipeDirectory } from '../helpers/recipe-helpers';
15 getRecipeDirectory,
16 getDevRecipeDirectory,
17} from '../helpers/recipe-helpers';
18import { workspaceStore } from '../features/workspaces'; 14import { workspaceStore } from '../features/workspaces';
19import { KEEP_WS_LOADED_USID } from '../config'; 15import { KEEP_WS_LOADED_USID } from '../config';
20import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 16import { SPELLCHECKER_LOCALES } from '../i18n/languages';
17import { ferdiVersion } from '../environment';
21 18
22const debug = require('debug')('Ferdi:ServiceStore'); 19const debug = require('debug')('Ferdi:ServiceStore');
23 20
@@ -128,38 +125,66 @@ export default class ServicesStore extends Store {
128 setup() { 125 setup() {
129 // Single key reactions for the sake of your CPU 126 // Single key reactions for the sake of your CPU
130 reaction( 127 reaction(
131 () => this.stores.settings.app.enableSpellchecking, 128 () => (
132 () => this._shareSettingsWithServiceProcess(), 129 this.stores.settings.app.enableSpellchecking
130 ),
131 () => {
132 this._shareSettingsWithServiceProcess();
133 },
133 ); 134 );
134 135
135 reaction( 136 reaction(
136 () => this.stores.settings.app.spellcheckerLanguage, 137 () => (
137 () => this._shareSettingsWithServiceProcess(), 138 this.stores.settings.app.spellcheckerLanguage
139 ),
140 () => {
141 this._shareSettingsWithServiceProcess();
142 },
138 ); 143 );
139 144
140 reaction( 145 reaction(
141 () => this.stores.settings.app.darkMode, 146 () => (
142 () => this._shareSettingsWithServiceProcess(), 147 this.stores.settings.app.darkMode
148 ),
149 () => {
150 this._shareSettingsWithServiceProcess();
151 },
143 ); 152 );
144 153
145 reaction( 154 reaction(
146 () => this.stores.settings.app.adaptableDarkMode, 155 () => (
147 () => this._shareSettingsWithServiceProcess(), 156 this.stores.settings.app.adaptableDarkMode
157 ),
158 () => {
159 this._shareSettingsWithServiceProcess();
160 },
148 ); 161 );
149 162
150 reaction( 163 reaction(
151 () => this.stores.settings.app.universalDarkMode, 164 () => (
152 () => this._shareSettingsWithServiceProcess(), 165 this.stores.settings.app.universalDarkMode
166 ),
167 () => {
168 this._shareSettingsWithServiceProcess();
169 },
153 ); 170 );
154 171
155 reaction( 172 reaction(
156 () => this.stores.settings.app.searchEngine, 173 () => (
157 () => this._shareSettingsWithServiceProcess(), 174 this.stores.settings.app.searchEngine
175 ),
176 () => {
177 this._shareSettingsWithServiceProcess();
178 },
158 ); 179 );
159 180
160 reaction( 181 reaction(
161 () => this.stores.settings.app.clipboardNotifications, 182 () => (
162 () => this._shareSettingsWithServiceProcess(), 183 this.stores.settings.app.clipboardNotifications
184 ),
185 () => {
186 this._shareSettingsWithServiceProcess();
187 },
163 ); 188 );
164 } 189 }
165 190
@@ -190,12 +215,12 @@ export default class ServicesStore extends Store {
190 * Run various maintenance tasks on services 215 * Run various maintenance tasks on services
191 */ 216 */
192 _serviceMaintenance() { 217 _serviceMaintenance() {
193 this.all.forEach(service => { 218 this.enabled.forEach(service => {
194 // Defines which services should be hibernated or woken up 219 // Defines which services should be hibernated or woken up
195 if (!service.isActive) { 220 if (!service.isActive) {
196 if ( 221 if (
197 !service.lastHibernated && 222 !service.lastHibernated &&
198 Date.now() - service.lastUsed > 223 (Date.now() - service.lastUsed) >
199 ms(`${this.stores.settings.all.app.hibernationStrategy}s`) 224 ms(`${this.stores.settings.all.app.hibernationStrategy}s`)
200 ) { 225 ) {
201 // If service is stale, hibernate it. 226 // If service is stale, hibernate it.
@@ -204,21 +229,18 @@ export default class ServicesStore extends Store {
204 229
205 if ( 230 if (
206 service.lastHibernated && 231 service.lastHibernated &&
207 Number(this.stores.settings.all.app.wakeUpStrategy) > 0 232 Number(this.stores.settings.all.app.wakeUpStrategy) > 0 &&
233 (Date.now() - service.lastHibernated) >
234 ms(`${this.stores.settings.all.app.wakeUpStrategy}s`)
208 ) { 235 ) {
209 // If service is in hibernation and the wakeup time has elapsed, wake it. 236 // If service is in hibernation and the wakeup time has elapsed, wake it.
210 if ( 237 this._awake({ serviceId: service.id });
211 Date.now() - service.lastHibernated >
212 ms(`${this.stores.settings.all.app.wakeUpStrategy}s`)
213 ) {
214 this._awake({ serviceId: service.id });
215 }
216 } 238 }
217 } 239 }
218 240
219 if ( 241 if (
220 service.lastPoll && 242 service.lastPoll &&
221 service.lastPoll - service.lastPollAnswer > ms('1m') 243 (service.lastPoll - service.lastPollAnswer) > ms('1m')
222 ) { 244 ) {
223 // If service did not reply for more than 1m try to reload. 245 // If service did not reply for more than 1m try to reload.
224 if (!service.isActive) { 246 if (!service.isActive) {
@@ -378,27 +400,22 @@ export default class ServicesStore extends Store {
378 400
379 // set default values for serviceData 401 // set default values for serviceData
380 // eslint-disable-next-line prefer-object-spread 402 // eslint-disable-next-line prefer-object-spread
381 Object.assign( 403 // TODO: How is this different from the defaults of the recipe in 'src/models/Recipe' file?
382 { 404 serviceData = {
383 isEnabled: true, 405 isEnabled: true,
384 isHibernationEnabled: false, 406 isHibernationEnabled: false,
385 isNotificationEnabled: true, 407 isNotificationEnabled: true,
386 isBadgeEnabled: true, 408 isBadgeEnabled: true,
387 isMuted: false, 409 isMuted: false,
388 customIcon: false, 410 customIcon: false,
389 isDarkModeEnabled: false, 411 isDarkModeEnabled: false,
390 spellcheckerLanguage: 412 spellcheckerLanguage:
391 SPELLCHECKER_LOCALES[this.stores.settings.app.spellcheckerLanguage], 413 SPELLCHECKER_LOCALES[this.stores.settings.app.spellcheckerLanguage],
392 userAgentPref: '', 414 userAgentPref: '',
393 }, 415 ...serviceData,
394 serviceData, 416 };
395 );
396
397 let data = serviceData;
398 417
399 if (!skipCleanup) { 418 const data = skipCleanup ? serviceData : this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData);
400 data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData);
401 }
402 419
403 const response = await this.createServiceRequest.execute(recipeId, data) 420 const response = await this.createServiceRequest.execute(recipeId, data)
404 ._promise; 421 ._promise;
@@ -430,12 +447,13 @@ export default class ServicesStore extends Store {
430 serviceData.name = data.name; 447 serviceData.name = data.name;
431 } 448 }
432 449
433 if (data.team && !data.customURL) { 450 if (data.team) {
434 serviceData.team = data.team; 451 if (!data.customURL) {
435 } 452 serviceData.team = data.team;
436 453 } else {
437 if (data.team && data.customURL) { 454 // TODO: Is this correct?
438 serviceData.customUrl = data.team; 455 serviceData.customUrl = data.team;
456 }
439 } 457 }
440 458
441 this.actions.service.createService({ 459 this.actions.service.createService({
@@ -596,9 +614,8 @@ export default class ServicesStore extends Store {
596 this.allDisplayed.length, 614 this.allDisplayed.length,
597 ); 615 );
598 616
599 // TODO: simplify this; 617 this.all.forEach(s => {
600 this.all.forEach((s, index) => { 618 s.isActive = false;
601 this.all[index].isActive = false;
602 }); 619 });
603 this.allDisplayed[nextIndex].isActive = true; 620 this.allDisplayed[nextIndex].isActive = true;
604 } 621 }
@@ -610,9 +627,8 @@ export default class ServicesStore extends Store {
610 this.allDisplayed.length, 627 this.allDisplayed.length,
611 ); 628 );
612 629
613 // TODO: simplify this; 630 this.all.forEach(s => {
614 this.all.forEach((s, index) => { 631 s.isActive = false;
615 this.all[index].isActive = false;
616 }); 632 });
617 this.allDisplayed[prevIndex].isActive = true; 633 this.allDisplayed[prevIndex].isActive = true;
618 } 634 }
@@ -877,6 +893,7 @@ export default class ServicesStore extends Store {
877 ); 893 );
878 894
879 const services = {}; 895 const services = {};
896 // TODO: simplify this
880 this.all.forEach((s, index) => { 897 this.all.forEach((s, index) => {
881 services[this.all[index].id] = index; 898 services[this.all[index].id] = index;
882 }); 899 });
@@ -893,6 +910,7 @@ export default class ServicesStore extends Store {
893 910
894 @action _toggleNotifications({ serviceId }) { 911 @action _toggleNotifications({ serviceId }) {
895 const service = this.one(serviceId); 912 const service = this.one(serviceId);
913 service.isNotificationEnabled = !service.isNotificationEnabled;
896 914
897 this.actions.service.updateService({ 915 this.actions.service.updateService({
898 serviceId, 916 serviceId,
@@ -905,8 +923,7 @@ export default class ServicesStore extends Store {
905 923
906 @action _toggleAudio({ serviceId }) { 924 @action _toggleAudio({ serviceId }) {
907 const service = this.one(serviceId); 925 const service = this.one(serviceId);
908 926 service.isMuted = !service.isMuted;
909 service.isNotificationEnabled = !service.isNotificationEnabled;
910 927
911 this.actions.service.updateService({ 928 this.actions.service.updateService({
912 serviceId, 929 serviceId,
@@ -919,6 +936,7 @@ export default class ServicesStore extends Store {
919 936
920 @action _toggleDarkMode({ serviceId }) { 937 @action _toggleDarkMode({ serviceId }) {
921 const service = this.one(serviceId); 938 const service = this.one(serviceId);
939 service.isDarkModeEnabled = !service.isDarkModeEnabled;
922 940
923 this.actions.service.updateService({ 941 this.actions.service.updateService({
924 serviceId, 942 serviceId,
@@ -1149,7 +1167,7 @@ export default class ServicesStore extends Store {
1149 'initialize-recipe', 1167 'initialize-recipe',
1150 { 1168 {
1151 ...shareWithWebview, 1169 ...shareWithWebview,
1152 franzVersion: app.getVersion(), 1170 franzVersion: ferdiVersion,
1153 }, 1171 },
1154 service.recipe, 1172 service.recipe,
1155 ); 1173 );
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index cd627c2b8..f551e1e49 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -40,7 +40,9 @@ export default class SettingsStore extends Store {
40 await this._migrate(); 40 await this._migrate();
41 41
42 reaction( 42 reaction(
43 () => this.all.app.autohideMenuBar, 43 () => (
44 this.all.app.autohideMenuBar
45 ),
44 () => { 46 () => {
45 const currentWindow = getCurrentWindow(); 47 const currentWindow = getCurrentWindow();
46 currentWindow.setMenuBarVisibility(!this.all.app.autohideMenuBar); 48 currentWindow.setMenuBarVisibility(!this.all.app.autohideMenuBar);
@@ -49,15 +51,15 @@ export default class SettingsStore extends Store {
49 ); 51 );
50 52
51 reaction( 53 reaction(
52 () => this.all.app.server, 54 () => (
55 this.all.app.server
56 ),
53 (server) => { 57 (server) => {
54 if (server === LOCAL_SERVER) { 58 if (server === LOCAL_SERVER) {
55 ipcRenderer.send('startLocalServer'); 59 ipcRenderer.send('startLocalServer');
56 } 60 }
57 }, 61 },
58 { 62 { fireImmediately: true },
59 fireImmediately: true,
60 },
61 ); 63 );
62 64
63 // Inactivity lock timer 65 // Inactivity lock timer
diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js
index adcd776c1..be675d5ed 100644
--- a/src/stores/UIStore.js
+++ b/src/stores/UIStore.js
@@ -43,8 +43,12 @@ export default class UIStore extends Store {
43 43
44 setup() { 44 setup() {
45 reaction( 45 reaction(
46 () => this.isDarkThemeActive, 46 () => (
47 () => this._setupThemeInDOM(), 47 this.isDarkThemeActive
48 ),
49 () => {
50 this._setupThemeInDOM();
51 },
48 { fireImmediately: true }, 52 { fireImmediately: true },
49 ); 53 );
50 } 54 }
diff --git a/src/stores/index.js b/src/stores/index.ts
index b6e481e8a..e980f2c5b 100644
--- a/src/stores/index.js
+++ b/src/stores/index.ts
@@ -34,9 +34,12 @@ export default (api, actions, router) => {
34 communityRecipes: communityRecipesStore, 34 communityRecipes: communityRecipesStore,
35 todos: todosStore, 35 todos: todosStore,
36 }); 36 });
37
37 // Initialize all stores 38 // Initialize all stores
38 Object.keys(stores).forEach((name) => { 39 Object.keys(stores).forEach((name) => {
39 if (stores[name] && stores[name].initialize) stores[name].initialize(); 40 if (stores[name] && stores[name].initialize) {
41 stores[name].initialize();
42 }
40 }); 43 });
41 return stores; 44 return stores;
42}; 45};