diff options
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r-- | src/stores/SettingsStore.js | 96 |
1 files changed, 54 insertions, 42 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 8a5ee7204..26e83b725 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,21 +1,18 @@ | |||
1 | import { ipcRenderer, remote } from 'electron'; | 1 | import { ipcRenderer, remote } from 'electron'; |
2 | import { | 2 | import { action, computed, observable, reaction } from 'mobx'; |
3 | action, computed, observable, reaction, | ||
4 | } from 'mobx'; | ||
5 | import localStorage from 'mobx-localstorage'; | 3 | import localStorage from 'mobx-localstorage'; |
6 | |||
7 | import Store from './lib/Store'; | ||
8 | import Request from './lib/Request'; | ||
9 | import { getLocale } from '../helpers/i18n-helpers'; | ||
10 | import { API } from '../environment'; | ||
11 | |||
12 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config'; | 4 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config'; |
5 | import { API } from '../environment'; | ||
6 | import { getLocale } from '../helpers/i18n-helpers'; | ||
13 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 7 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
8 | import Request from './lib/Request'; | ||
9 | import Store from './lib/Store'; | ||
14 | 10 | ||
15 | const debug = require('debug')('Ferdi:SettingsStore'); | 11 | const debug = require('debug')('Ferdi:SettingsStore'); |
16 | 12 | ||
17 | export default class SettingsStore extends Store { | 13 | export default class SettingsStore extends Store { |
18 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); | 14 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); |
15 | startup = true; | ||
19 | 16 | ||
20 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; | 17 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; |
21 | 18 | ||
@@ -30,16 +27,6 @@ export default class SettingsStore extends Store { | |||
30 | // Register action handlers | 27 | // Register action handlers |
31 | this.actions.settings.update.listen(this._update.bind(this)); | 28 | this.actions.settings.update.listen(this._update.bind(this)); |
32 | this.actions.settings.remove.listen(this._remove.bind(this)); | 29 | this.actions.settings.remove.listen(this._remove.bind(this)); |
33 | |||
34 | ipcRenderer.on('appSettings', (event, resp) => { | ||
35 | debug('Get appSettings resolves', resp.type, resp.data); | ||
36 | |||
37 | Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); | ||
38 | }); | ||
39 | |||
40 | this.fileSystemSettingsTypes.forEach((type) => { | ||
41 | ipcRenderer.send('getAppSettings', type); | ||
42 | }); | ||
43 | } | 30 | } |
44 | 31 | ||
45 | async setup() { | 32 | async setup() { |
@@ -47,9 +34,11 @@ export default class SettingsStore extends Store { | |||
47 | 34 | ||
48 | reaction( | 35 | reaction( |
49 | () => this.all.app.autohideMenuBar, | 36 | () => this.all.app.autohideMenuBar, |
50 | () => remote.getCurrentWindow().setAutoHideMenuBar( | 37 | () => { |
51 | this.all.app.autohideMenuBar, | 38 | const currentWindow = remote.getCurrentWindow(); |
52 | ), | 39 | currentWindow.setMenuBarVisibility(!this.all.app.autohideMenuBar); |
40 | currentWindow.autoHideMenuBar = this.all.app.autohideMenuBar; | ||
41 | }, | ||
53 | ); | 42 | ); |
54 | 43 | ||
55 | reaction( | 44 | reaction( |
@@ -99,27 +88,30 @@ export default class SettingsStore extends Store { | |||
99 | } | 88 | } |
100 | }); | 89 | }); |
101 | 90 | ||
102 | // Make sure to lock app on launch if locking feature is enabled | 91 | ipcRenderer.on('appSettings', (event, resp) => { |
103 | setTimeout(() => { | 92 | // Lock on startup if enabled in settings |
104 | const isLoggedIn = Boolean(localStorage.getItem('authToken')); | 93 | if (this.startup && resp.type === 'app' && resp.data.lockingFeatureEnabled) { |
105 | if (isLoggedIn && this.all.app.lockingFeatureEnabled) { | 94 | this.startup = false; |
106 | // Disable lock first - otherwise the lock might not get activated corrently | 95 | process.nextTick(() => { |
107 | this.actions.settings.update({ | 96 | // If the app was previously closed unlocked |
108 | type: 'app', | 97 | // we can update the `locked` setting and rely on the reaction to lock at startup |
109 | data: { | 98 | if (!this.all.app.locked) { |
110 | locked: false, | 99 | this.all.app.locked = true; |
111 | }, | 100 | } else { |
112 | }); | 101 | // Otherwise the app previously closed in a locked state |
113 | setTimeout(() => { | 102 | // We can't rely on updating the locked setting for the reaction to be triggered |
114 | this.actions.settings.update({ | 103 | // So we lock manually |
115 | type: 'app', | 104 | window.ferdi.stores.router.push('/auth/locked'); |
116 | data: { | 105 | } |
117 | locked: true, | 106 | }) |
118 | }, | ||
119 | }); | ||
120 | }, 0); | ||
121 | } | 107 | } |
122 | }, 1000); | 108 | debug('Get appSettings resolves', resp.type, resp.data); |
109 | Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); | ||
110 | }); | ||
111 | |||
112 | this.fileSystemSettingsTypes.forEach((type) => { | ||
113 | ipcRenderer.send('getAppSettings', type); | ||
114 | }); | ||
123 | } | 115 | } |
124 | 116 | ||
125 | @computed get app() { | 117 | @computed get app() { |
@@ -248,5 +240,25 @@ export default class SettingsStore extends Store { | |||
248 | }, | 240 | }, |
249 | }); | 241 | }); |
250 | } | 242 | } |
243 | |||
244 | if (!this.all.migration['5.4.4-beta.2-settings']) { | ||
245 | const { | ||
246 | showServiceNavigationBar, | ||
247 | } = this.all.app; | ||
248 | |||
249 | this.actions.settings.update({ | ||
250 | type: 'app', | ||
251 | data: { | ||
252 | navigationBarBehaviour: showServiceNavigationBar ? 'custom' : 'never', | ||
253 | }, | ||
254 | }); | ||
255 | |||
256 | this.actions.settings.update({ | ||
257 | type: 'migration', | ||
258 | data: { | ||
259 | '5.4.4-beta.2-settings': true, | ||
260 | }, | ||
261 | }); | ||
262 | } | ||
251 | } | 263 | } |
252 | } | 264 | } |