diff options
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/AppStore.js | 4 | ||||
-rw-r--r-- | src/stores/FeaturesStore.js | 4 | ||||
-rw-r--r-- | src/stores/RecipesStore.js | 29 | ||||
-rw-r--r-- | src/stores/ServicesStore.js | 6 | ||||
-rw-r--r-- | src/stores/SettingsStore.js | 24 | ||||
-rw-r--r-- | src/stores/UIStore.js | 41 | ||||
-rw-r--r-- | src/stores/lib/Request.js | 3 |
7 files changed, 90 insertions, 21 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 0756a05eb..36e6efd4f 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -27,7 +27,7 @@ import { sleep } from '../helpers/async-helpers'; | |||
27 | const debug = require('debug')('Ferdi:AppStore'); | 27 | const debug = require('debug')('Ferdi:AppStore'); |
28 | 28 | ||
29 | const { | 29 | const { |
30 | app, systemPreferences, screen, powerMonitor, | 30 | app, nativeTheme, screen, powerMonitor, |
31 | } = remote; | 31 | } = remote; |
32 | 32 | ||
33 | const mainWindow = remote.getCurrentWindow(); | 33 | const mainWindow = remote.getCurrentWindow(); |
@@ -185,7 +185,7 @@ export default class AppStore extends Store { | |||
185 | this._healthCheck(); | 185 | this._healthCheck(); |
186 | }, 1000); | 186 | }, 1000); |
187 | 187 | ||
188 | this.isSystemDarkModeEnabled = systemPreferences.isDarkMode(); | 188 | this.isSystemDarkModeEnabled = nativeTheme.shouldUseDarkColors; |
189 | 189 | ||
190 | onVisibilityChange((isVisible) => { | 190 | onVisibilityChange((isVisible) => { |
191 | this.isFocused = isVisible; | 191 | this.isFocused = isVisible; |
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js index 780cde3a7..eec4678b9 100644 --- a/src/stores/FeaturesStore.js +++ b/src/stores/FeaturesStore.js | |||
@@ -20,7 +20,7 @@ import settingsWS from '../features/settingsWS'; | |||
20 | import serviceLimit from '../features/serviceLimit'; | 20 | import serviceLimit from '../features/serviceLimit'; |
21 | import communityRecipes from '../features/communityRecipes'; | 21 | import communityRecipes from '../features/communityRecipes'; |
22 | import todos from '../features/todos'; | 22 | import todos from '../features/todos'; |
23 | import accentColor from '../features/accentColor'; | 23 | import appearance from '../features/appearance'; |
24 | import planSelection from '../features/planSelection'; | 24 | import planSelection from '../features/planSelection'; |
25 | import trialStatusBar from '../features/trialStatusBar'; | 25 | import trialStatusBar from '../features/trialStatusBar'; |
26 | 26 | ||
@@ -90,7 +90,7 @@ export default class FeaturesStore extends Store { | |||
90 | serviceLimit(this.stores, this.actions); | 90 | serviceLimit(this.stores, this.actions); |
91 | communityRecipes(this.stores, this.actions); | 91 | communityRecipes(this.stores, this.actions); |
92 | todos(this.stores, this.actions); | 92 | todos(this.stores, this.actions); |
93 | accentColor(this.stores, this.actions); | 93 | appearance(this.stores, this.actions); |
94 | planSelection(this.stores, this.actions); | 94 | planSelection(this.stores, this.actions); |
95 | trialStatusBar(this.stores, this.actions); | 95 | trialStatusBar(this.stores, this.actions); |
96 | } | 96 | } |
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index 8b2bde5df..cf5d0a074 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js | |||
@@ -1,9 +1,13 @@ | |||
1 | import { action, computed, observable } from 'mobx'; | 1 | import { action, computed, observable } from 'mobx'; |
2 | import fs from 'fs-extra'; | ||
3 | import path from 'path'; | ||
4 | import semver from 'semver'; | ||
2 | 5 | ||
3 | import Store from './lib/Store'; | 6 | import Store from './lib/Store'; |
4 | import CachedRequest from './lib/CachedRequest'; | 7 | import CachedRequest from './lib/CachedRequest'; |
5 | import Request from './lib/Request'; | 8 | import Request from './lib/Request'; |
6 | import { matchRoute } from '../helpers/routing-helpers'; | 9 | import { matchRoute } from '../helpers/routing-helpers'; |
10 | import { RECIPES_PATH } from '../config'; | ||
7 | 11 | ||
8 | const debug = require('debug')('Ferdi:RecipeStore'); | 12 | const debug = require('debug')('Ferdi:RecipeStore'); |
9 | 13 | ||
@@ -83,7 +87,30 @@ export default class RecipesStore extends Store { | |||
83 | 87 | ||
84 | if (Object.keys(recipes).length === 0) return; | 88 | if (Object.keys(recipes).length === 0) return; |
85 | 89 | ||
86 | const updates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; | 90 | const remoteUpdates = await this.getRecipeUpdatesRequest.execute(recipes)._promise; |
91 | |||
92 | // Check for local updates | ||
93 | const allJsonFile = path.join(RECIPES_PATH, 'all.json'); | ||
94 | const allJson = await fs.readJSON(allJsonFile); | ||
95 | const localUpdates = []; | ||
96 | |||
97 | Object.keys(recipes).forEach((recipe) => { | ||
98 | const version = recipes[recipe]; | ||
99 | |||
100 | // Find recipe in local recipe repository | ||
101 | const localRecipe = allJson.find(r => r.id === recipe); | ||
102 | |||
103 | if (localRecipe && semver.lt(version, localRecipe.version)) { | ||
104 | localUpdates.push(recipe); | ||
105 | } | ||
106 | }); | ||
107 | |||
108 | const updates = [ | ||
109 | ...remoteUpdates, | ||
110 | ...localUpdates, | ||
111 | ]; | ||
112 | debug('Got update information (local, remote):', localUpdates, remoteUpdates); | ||
113 | |||
87 | const length = updates.length - 1; | 114 | const length = updates.length - 1; |
88 | const syncUpdate = async (i) => { | 115 | const syncUpdate = async (i) => { |
89 | const update = updates[i]; | 116 | const update = updates[i]; |
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 3dd601bc3..fda18b514 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -83,6 +83,7 @@ export default class ServicesStore extends Store { | |||
83 | this.actions.service.openDevTools.listen(this._openDevTools.bind(this)); | 83 | this.actions.service.openDevTools.listen(this._openDevTools.bind(this)); |
84 | this.actions.service.openDevToolsForActiveService.listen(this._openDevToolsForActiveService.bind(this)); | 84 | this.actions.service.openDevToolsForActiveService.listen(this._openDevToolsForActiveService.bind(this)); |
85 | this.actions.service.setHibernation.listen(this._setHibernation.bind(this)); | 85 | this.actions.service.setHibernation.listen(this._setHibernation.bind(this)); |
86 | this.actions.service.shareSettingsWithServiceProcess.listen(this._shareSettingsWithServiceProcess.bind(this)); | ||
86 | 87 | ||
87 | this.registerReactions([ | 88 | this.registerReactions([ |
88 | this._focusServiceReaction.bind(this), | 89 | this._focusServiceReaction.bind(this), |
@@ -771,7 +772,10 @@ export default class ServicesStore extends Store { | |||
771 | } | 772 | } |
772 | 773 | ||
773 | _shareSettingsWithServiceProcess() { | 774 | _shareSettingsWithServiceProcess() { |
774 | const settings = this.stores.settings.app; | 775 | const settings = { |
776 | ...this.stores.settings.app, | ||
777 | isDarkThemeActive: this.stores.ui.isDarkThemeActive, | ||
778 | }; | ||
775 | this.actions.service.sendIPCMessageToAllServices({ | 779 | this.actions.service.sendIPCMessageToAllServices({ |
776 | channel: 'settings-update', | 780 | channel: 'settings-update', |
777 | args: settings, | 781 | args: settings, |
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index df0fc77e9..8a5ee7204 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -68,7 +68,6 @@ export default class SettingsStore extends Store { | |||
68 | () => this.all.app.locked, | 68 | () => this.all.app.locked, |
69 | () => { | 69 | () => { |
70 | const { router } = window.ferdi.stores; | 70 | const { router } = window.ferdi.stores; |
71 | |||
72 | if (this.all.app.locked && this.all.app.lockingFeatureEnabled) { | 71 | if (this.all.app.locked && this.all.app.lockingFeatureEnabled) { |
73 | // App just got locked, redirect to unlock screen | 72 | // App just got locked, redirect to unlock screen |
74 | router.push('/auth/locked'); | 73 | router.push('/auth/locked'); |
@@ -80,9 +79,30 @@ export default class SettingsStore extends Store { | |||
80 | }, | 79 | }, |
81 | ); | 80 | ); |
82 | 81 | ||
82 | // Inactivity lock timer | ||
83 | let inactivityTimer; | ||
84 | remote.getCurrentWindow().on('blur', () => { | ||
85 | if (this.all.app.inactivityLock !== 0) { | ||
86 | inactivityTimer = setTimeout(() => { | ||
87 | this.actions.settings.update({ | ||
88 | type: 'app', | ||
89 | data: { | ||
90 | locked: true, | ||
91 | }, | ||
92 | }); | ||
93 | }, this.all.app.inactivityLock * 1000 * 60); | ||
94 | } | ||
95 | }); | ||
96 | remote.getCurrentWindow().on('focus', () => { | ||
97 | if (inactivityTimer) { | ||
98 | clearTimeout(inactivityTimer); | ||
99 | } | ||
100 | }); | ||
101 | |||
83 | // Make sure to lock app on launch if locking feature is enabled | 102 | // Make sure to lock app on launch if locking feature is enabled |
84 | setTimeout(() => { | 103 | setTimeout(() => { |
85 | if (this.all.app.lockingFeatureEnabled) { | 104 | const isLoggedIn = Boolean(localStorage.getItem('authToken')); |
105 | if (isLoggedIn && this.all.app.lockingFeatureEnabled) { | ||
86 | // Disable lock first - otherwise the lock might not get activated corrently | 106 | // Disable lock first - otherwise the lock might not get activated corrently |
87 | this.actions.settings.update({ | 107 | this.actions.settings.update({ |
88 | type: 'app', | 108 | type: 'app', |
diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js index 44bc7c974..6941cf086 100644 --- a/src/stores/UIStore.js +++ b/src/stores/UIStore.js | |||
@@ -1,8 +1,5 @@ | |||
1 | import { | 1 | import { |
2 | action, | 2 | action, observable, computed, reaction, |
3 | observable, | ||
4 | computed, | ||
5 | reaction, | ||
6 | } from 'mobx'; | 3 | } from 'mobx'; |
7 | import { theme } from '@meetfranz/theme'; | 4 | import { theme } from '@meetfranz/theme'; |
8 | import { remote } from 'electron'; | 5 | import { remote } from 'electron'; |
@@ -10,12 +7,14 @@ import { remote } from 'electron'; | |||
10 | import Store from './lib/Store'; | 7 | import Store from './lib/Store'; |
11 | import { isMac } from '../environment'; | 8 | import { isMac } from '../environment'; |
12 | 9 | ||
13 | const { systemPreferences } = remote; | 10 | const { nativeTheme, systemPreferences } = remote; |
14 | 11 | ||
15 | export default class UIStore extends Store { | 12 | export default class UIStore extends Store { |
16 | @observable showServicesUpdatedInfoBar = false; | 13 | @observable showServicesUpdatedInfoBar = false; |
17 | 14 | ||
18 | @observable isOsDarkThemeActive = isMac ? systemPreferences.isDarkMode() : false; | 15 | @observable isOsDarkThemeActive = isMac |
16 | ? nativeTheme.shouldUseDarkColors | ||
17 | : false; | ||
19 | 18 | ||
20 | constructor(...args) { | 19 | constructor(...args) { |
21 | super(...args); | 20 | super(...args); |
@@ -23,13 +22,19 @@ export default class UIStore extends Store { | |||
23 | // Register action handlers | 22 | // Register action handlers |
24 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); | 23 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); |
25 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); | 24 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); |
26 | this.actions.ui.toggleServiceUpdatedInfoBar.listen(this._toggleServiceUpdatedInfoBar.bind(this)); | 25 | this.actions.ui.toggleServiceUpdatedInfoBar.listen( |
26 | this._toggleServiceUpdatedInfoBar.bind(this), | ||
27 | ); | ||
27 | 28 | ||
28 | // Listen for theme change on MacOS | 29 | // Listen for theme change on MacOS |
29 | if (isMac) { | 30 | if (isMac) { |
30 | systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => { | 31 | systemPreferences.subscribeNotification( |
31 | this.isOsDarkThemeActive = systemPreferences.isDarkMode(); | 32 | 'AppleInterfaceThemeChangedNotification', |
32 | }); | 33 | () => { |
34 | this.isOsDarkThemeActive = nativeTheme.shouldUseDarkColors; | ||
35 | this.actions.service.shareSettingsWithServiceProcess(); | ||
36 | }, | ||
37 | ); | ||
33 | } | 38 | } |
34 | } | 39 | } |
35 | 40 | ||
@@ -44,11 +49,23 @@ export default class UIStore extends Store { | |||
44 | @computed get showMessageBadgesEvenWhenMuted() { | 49 | @computed get showMessageBadgesEvenWhenMuted() { |
45 | const settings = this.stores.settings.all; | 50 | const settings = this.stores.settings.all; |
46 | 51 | ||
47 | return (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) || !settings.app.isAppMuted; | 52 | return ( |
53 | (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) | ||
54 | || !settings.app.isAppMuted | ||
55 | ); | ||
48 | } | 56 | } |
49 | 57 | ||
50 | @computed get isDarkThemeActive() { | 58 | @computed get isDarkThemeActive() { |
51 | return this.stores.settings.all.app.darkMode || (this.stores.settings.all.app.adaptableDarkMode && this.isOsDarkThemeActive); | 59 | const isMacWithAdaptableInDarkMode = isMac |
60 | && this.stores.settings.all.app.adaptableDarkMode | ||
61 | && this.isOsDarkThemeActive; | ||
62 | const isMacWithoutAdaptableInDarkMode = isMac | ||
63 | && this.stores.settings.all.app.darkMode | ||
64 | && !this.stores.settings.all.app.adaptableDarkMode; | ||
65 | const isNotMacInDarkMode = !isMac && this.stores.settings.all.app.darkMode; | ||
66 | return !!(isMacWithAdaptableInDarkMode | ||
67 | || isMacWithoutAdaptableInDarkMode | ||
68 | || isNotMacInDarkMode); | ||
52 | } | 69 | } |
53 | 70 | ||
54 | @computed get theme() { | 71 | @computed get theme() { |
diff --git a/src/stores/lib/Request.js b/src/stores/lib/Request.js index 486de8a49..cfc857c2e 100644 --- a/src/stores/lib/Request.js +++ b/src/stores/lib/Request.js | |||
@@ -82,7 +82,8 @@ export default class Request { | |||
82 | } | 82 | } |
83 | 83 | ||
84 | reload() { | 84 | reload() { |
85 | return this.execute(...this._currentApiCall.args); | 85 | const args = this._currentApiCall ? this._currentApiCall.args : []; |
86 | return this.execute(...args); | ||
86 | } | 87 | } |
87 | 88 | ||
88 | retry = () => this.reload(); | 89 | retry = () => this.reload(); |