diff options
author | 2020-01-31 21:03:49 +0100 | |
---|---|---|
committer | 2020-01-31 21:03:49 +0100 | |
commit | d54ceb639862788c053e21f217ca39ac36003db6 (patch) | |
tree | 40bfd8bb6a8a85c222f9c67d7dd862a835394e80 /src/stores | |
parent | Add publish debug log option (diff) | |
parent | Merge branch 'develop' of https://github.com/getferdi/ferdi into develop (diff) | |
download | ferdium-app-d54ceb639862788c053e21f217ca39ac36003db6.tar.gz ferdium-app-d54ceb639862788c053e21f217ca39ac36003db6.tar.zst ferdium-app-d54ceb639862788c053e21f217ca39ac36003db6.zip |
Merge branch 'develop' into publish-debug
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 | 11 | ||||
-rw-r--r-- | src/stores/SettingsStore.js | 24 | ||||
-rw-r--r-- | src/stores/UIStore.js | 44 | ||||
-rw-r--r-- | src/stores/lib/Request.js | 3 |
7 files changed, 103 insertions, 16 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 aa9fa4062..8a279bc8a 100644 --- a/src/stores/FeaturesStore.js +++ b/src/stores/FeaturesStore.js | |||
@@ -21,7 +21,7 @@ import settingsWS from '../features/settingsWS'; | |||
21 | import serviceLimit from '../features/serviceLimit'; | 21 | import serviceLimit from '../features/serviceLimit'; |
22 | import communityRecipes from '../features/communityRecipes'; | 22 | import communityRecipes from '../features/communityRecipes'; |
23 | import todos from '../features/todos'; | 23 | import todos from '../features/todos'; |
24 | import accentColor from '../features/accentColor'; | 24 | import appearance from '../features/appearance'; |
25 | import planSelection from '../features/planSelection'; | 25 | import planSelection from '../features/planSelection'; |
26 | import trialStatusBar from '../features/trialStatusBar'; | 26 | import trialStatusBar from '../features/trialStatusBar'; |
27 | 27 | ||
@@ -92,7 +92,7 @@ export default class FeaturesStore extends Store { | |||
92 | serviceLimit(this.stores, this.actions); | 92 | serviceLimit(this.stores, this.actions); |
93 | communityRecipes(this.stores, this.actions); | 93 | communityRecipes(this.stores, this.actions); |
94 | todos(this.stores, this.actions); | 94 | todos(this.stores, this.actions); |
95 | accentColor(this.stores, this.actions); | 95 | appearance(this.stores, this.actions); |
96 | planSelection(this.stores, this.actions); | 96 | planSelection(this.stores, this.actions); |
97 | trialStatusBar(this.stores, this.actions); | 97 | trialStatusBar(this.stores, this.actions); |
98 | } | 98 | } |
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 f65faa5a5..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), |
@@ -116,6 +117,11 @@ export default class ServicesStore extends Store { | |||
116 | ); | 117 | ); |
117 | 118 | ||
118 | reaction( | 119 | reaction( |
120 | () => this.stores.settings.app.adaptableDarkMode, | ||
121 | () => this._shareSettingsWithServiceProcess(), | ||
122 | ); | ||
123 | |||
124 | reaction( | ||
119 | () => this.stores.settings.app.universalDarkMode, | 125 | () => this.stores.settings.app.universalDarkMode, |
120 | () => this._shareSettingsWithServiceProcess(), | 126 | () => this._shareSettingsWithServiceProcess(), |
121 | ); | 127 | ); |
@@ -766,7 +772,10 @@ export default class ServicesStore extends Store { | |||
766 | } | 772 | } |
767 | 773 | ||
768 | _shareSettingsWithServiceProcess() { | 774 | _shareSettingsWithServiceProcess() { |
769 | const settings = this.stores.settings.app; | 775 | const settings = { |
776 | ...this.stores.settings.app, | ||
777 | isDarkThemeActive: this.stores.ui.isDarkThemeActive, | ||
778 | }; | ||
770 | this.actions.service.sendIPCMessageToAllServices({ | 779 | this.actions.service.sendIPCMessageToAllServices({ |
771 | channel: 'settings-update', | 780 | channel: 'settings-update', |
772 | 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 9680c5bcc..6941cf086 100644 --- a/src/stores/UIStore.js +++ b/src/stores/UIStore.js | |||
@@ -1,23 +1,41 @@ | |||
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'; |
5 | import { remote } from 'electron'; | ||
8 | 6 | ||
9 | import Store from './lib/Store'; | 7 | import Store from './lib/Store'; |
8 | import { isMac } from '../environment'; | ||
9 | |||
10 | const { nativeTheme, systemPreferences } = remote; | ||
10 | 11 | ||
11 | export default class UIStore extends Store { | 12 | export default class UIStore extends Store { |
12 | @observable showServicesUpdatedInfoBar = false; | 13 | @observable showServicesUpdatedInfoBar = false; |
13 | 14 | ||
15 | @observable isOsDarkThemeActive = isMac | ||
16 | ? nativeTheme.shouldUseDarkColors | ||
17 | : false; | ||
18 | |||
14 | constructor(...args) { | 19 | constructor(...args) { |
15 | super(...args); | 20 | super(...args); |
16 | 21 | ||
17 | // Register action handlers | 22 | // Register action handlers |
18 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); | 23 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); |
19 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); | 24 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); |
20 | this.actions.ui.toggleServiceUpdatedInfoBar.listen(this._toggleServiceUpdatedInfoBar.bind(this)); | 25 | this.actions.ui.toggleServiceUpdatedInfoBar.listen( |
26 | this._toggleServiceUpdatedInfoBar.bind(this), | ||
27 | ); | ||
28 | |||
29 | // Listen for theme change on MacOS | ||
30 | if (isMac) { | ||
31 | systemPreferences.subscribeNotification( | ||
32 | 'AppleInterfaceThemeChangedNotification', | ||
33 | () => { | ||
34 | this.isOsDarkThemeActive = nativeTheme.shouldUseDarkColors; | ||
35 | this.actions.service.shareSettingsWithServiceProcess(); | ||
36 | }, | ||
37 | ); | ||
38 | } | ||
21 | } | 39 | } |
22 | 40 | ||
23 | setup() { | 41 | setup() { |
@@ -31,11 +49,23 @@ export default class UIStore extends Store { | |||
31 | @computed get showMessageBadgesEvenWhenMuted() { | 49 | @computed get showMessageBadgesEvenWhenMuted() { |
32 | const settings = this.stores.settings.all; | 50 | const settings = this.stores.settings.all; |
33 | 51 | ||
34 | return (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) || !settings.app.isAppMuted; | 52 | return ( |
53 | (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) | ||
54 | || !settings.app.isAppMuted | ||
55 | ); | ||
35 | } | 56 | } |
36 | 57 | ||
37 | @computed get isDarkThemeActive() { | 58 | @computed get isDarkThemeActive() { |
38 | return this.stores.settings.all.app.darkMode; | 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); | ||
39 | } | 69 | } |
40 | 70 | ||
41 | @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(); |