diff options
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r-- | src/stores/SettingsStore.js | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 75bb38fe0..df0fc77e9 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,17 +1,18 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer, remote } from 'electron'; |
2 | import { | 2 | import { |
3 | action, computed, observable, | 3 | action, computed, observable, reaction, |
4 | } from 'mobx'; | 4 | } from 'mobx'; |
5 | import localStorage from 'mobx-localstorage'; | 5 | import localStorage from 'mobx-localstorage'; |
6 | 6 | ||
7 | import Store from './lib/Store'; | 7 | import Store from './lib/Store'; |
8 | import Request from './lib/Request'; | 8 | import Request from './lib/Request'; |
9 | import { getLocale } from '../helpers/i18n-helpers'; | 9 | import { getLocale } from '../helpers/i18n-helpers'; |
10 | import { API } from '../environment'; | ||
10 | 11 | ||
11 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; | 12 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER } from '../config'; |
12 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 13 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
13 | 14 | ||
14 | const debug = require('debug')('Franz:SettingsStore'); | 15 | const debug = require('debug')('Ferdi:SettingsStore'); |
15 | 16 | ||
16 | export default class SettingsStore extends Store { | 17 | export default class SettingsStore extends Store { |
17 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); | 18 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); |
@@ -43,6 +44,62 @@ export default class SettingsStore extends Store { | |||
43 | 44 | ||
44 | async setup() { | 45 | async setup() { |
45 | await this._migrate(); | 46 | await this._migrate(); |
47 | |||
48 | reaction( | ||
49 | () => this.all.app.autohideMenuBar, | ||
50 | () => remote.getCurrentWindow().setAutoHideMenuBar( | ||
51 | this.all.app.autohideMenuBar, | ||
52 | ), | ||
53 | ); | ||
54 | |||
55 | reaction( | ||
56 | () => this.all.app.server, | ||
57 | (server) => { | ||
58 | if (server === LOCAL_SERVER) { | ||
59 | ipcRenderer.send('startLocalServer'); | ||
60 | } | ||
61 | }, | ||
62 | { | ||
63 | fireImmediately: true, | ||
64 | }, | ||
65 | ); | ||
66 | |||
67 | reaction( | ||
68 | () => this.all.app.locked, | ||
69 | () => { | ||
70 | const { router } = window.ferdi.stores; | ||
71 | |||
72 | if (this.all.app.locked && this.all.app.lockingFeatureEnabled) { | ||
73 | // App just got locked, redirect to unlock screen | ||
74 | router.push('/auth/locked'); | ||
75 | } else if (router.location.pathname.includes('/auth/locked')) { | ||
76 | // App is unlocked but user is still on locked screen | ||
77 | // Redirect to homepage | ||
78 | router.push('/'); | ||
79 | } | ||
80 | }, | ||
81 | ); | ||
82 | |||
83 | // Make sure to lock app on launch if locking feature is enabled | ||
84 | setTimeout(() => { | ||
85 | if (this.all.app.lockingFeatureEnabled) { | ||
86 | // Disable lock first - otherwise the lock might not get activated corrently | ||
87 | this.actions.settings.update({ | ||
88 | type: 'app', | ||
89 | data: { | ||
90 | locked: false, | ||
91 | }, | ||
92 | }); | ||
93 | setTimeout(() => { | ||
94 | this.actions.settings.update({ | ||
95 | type: 'app', | ||
96 | data: { | ||
97 | locked: true, | ||
98 | }, | ||
99 | }); | ||
100 | }, 0); | ||
101 | } | ||
102 | }, 1000); | ||
46 | } | 103 | } |
47 | 104 | ||
48 | @computed get app() { | 105 | @computed get app() { |
@@ -121,6 +178,7 @@ export default class SettingsStore extends Store { | |||
121 | runInBackground: legacySettings.runInBackground, | 178 | runInBackground: legacySettings.runInBackground, |
122 | enableSystemTray: legacySettings.enableSystemTray, | 179 | enableSystemTray: legacySettings.enableSystemTray, |
123 | minimizeToSystemTray: legacySettings.minimizeToSystemTray, | 180 | minimizeToSystemTray: legacySettings.minimizeToSystemTray, |
181 | server: API, | ||
124 | isAppMuted: legacySettings.isAppMuted, | 182 | isAppMuted: legacySettings.isAppMuted, |
125 | enableGPUAcceleration: legacySettings.enableGPUAcceleration, | 183 | enableGPUAcceleration: legacySettings.enableGPUAcceleration, |
126 | showMessageBadgeWhenMuted: legacySettings.showMessageBadgeWhenMuted, | 184 | showMessageBadgeWhenMuted: legacySettings.showMessageBadgeWhenMuted, |