diff options
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r-- | src/stores/SettingsStore.js | 68 |
1 files changed, 29 insertions, 39 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 43f00b723..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() { |
@@ -101,27 +88,30 @@ export default class SettingsStore extends Store { | |||
101 | } | 88 | } |
102 | }); | 89 | }); |
103 | 90 | ||
104 | // Make sure to lock app on launch if locking feature is enabled | 91 | ipcRenderer.on('appSettings', (event, resp) => { |
105 | setTimeout(() => { | 92 | // Lock on startup if enabled in settings |
106 | const isLoggedIn = Boolean(localStorage.getItem('authToken')); | 93 | if (this.startup && resp.type === 'app' && resp.data.lockingFeatureEnabled) { |
107 | if (isLoggedIn && this.all.app.lockingFeatureEnabled) { | 94 | this.startup = false; |
108 | // Disable lock first - otherwise the lock might not get activated corrently | 95 | process.nextTick(() => { |
109 | this.actions.settings.update({ | 96 | // If the app was previously closed unlocked |
110 | type: 'app', | 97 | // we can update the `locked` setting and rely on the reaction to lock at startup |
111 | data: { | 98 | if (!this.all.app.locked) { |
112 | locked: false, | 99 | this.all.app.locked = true; |
113 | }, | 100 | } else { |
114 | }); | 101 | // Otherwise the app previously closed in a locked state |
115 | setTimeout(() => { | 102 | // We can't rely on updating the locked setting for the reaction to be triggered |
116 | this.actions.settings.update({ | 103 | // So we lock manually |
117 | type: 'app', | 104 | window.ferdi.stores.router.push('/auth/locked'); |
118 | data: { | 105 | } |
119 | locked: true, | 106 | }) |
120 | }, | ||
121 | }); | ||
122 | }, 0); | ||
123 | } | 107 | } |
124 | }, 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 | }); | ||
125 | } | 115 | } |
126 | 116 | ||
127 | @computed get app() { | 117 | @computed get app() { |