diff options
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r-- | src/stores/SettingsStore.js | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 9aade974c..690a18374 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,11 +1,11 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { getCurrentWindow } from '@electron/remote'; | 2 | import { getCurrentWindow } from '@electron/remote'; |
3 | import { | 3 | import { action, computed, observable, reaction } from 'mobx'; |
4 | action, computed, observable, reaction, | ||
5 | } from 'mobx'; | ||
6 | import localStorage from 'mobx-localstorage'; | 4 | import localStorage from 'mobx-localstorage'; |
7 | import { | 5 | import { |
8 | FILE_SYSTEM_SETTINGS_TYPES, LOCAL_SERVER, SEARCH_ENGINE_DDG, | 6 | FILE_SYSTEM_SETTINGS_TYPES, |
7 | LOCAL_SERVER, | ||
8 | SEARCH_ENGINE_DDG, | ||
9 | } from '../config'; | 9 | } from '../config'; |
10 | import { API, DEFAULT_APP_SETTINGS } from '../environment'; | 10 | import { API, DEFAULT_APP_SETTINGS } from '../environment'; |
11 | import { getLocale } from '../helpers/i18n-helpers'; | 11 | import { getLocale } from '../helpers/i18n-helpers'; |
@@ -17,7 +17,10 @@ import Store from './lib/Store'; | |||
17 | const debug = require('debug')('Ferdi:SettingsStore'); | 17 | const debug = require('debug')('Ferdi:SettingsStore'); |
18 | 18 | ||
19 | export default class SettingsStore extends Store { | 19 | export default class SettingsStore extends Store { |
20 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); | 20 | @observable updateAppSettingsRequest = new Request( |
21 | this.api.local, | ||
22 | 'updateAppSettings', | ||
23 | ); | ||
21 | 24 | ||
22 | startup = true; | 25 | startup = true; |
23 | 26 | ||
@@ -40,9 +43,7 @@ export default class SettingsStore extends Store { | |||
40 | await this._migrate(); | 43 | await this._migrate(); |
41 | 44 | ||
42 | reaction( | 45 | reaction( |
43 | () => ( | 46 | () => this.all.app.autohideMenuBar, |
44 | this.all.app.autohideMenuBar | ||
45 | ), | ||
46 | () => { | 47 | () => { |
47 | const currentWindow = getCurrentWindow(); | 48 | const currentWindow = getCurrentWindow(); |
48 | currentWindow.setMenuBarVisibility(!this.all.app.autohideMenuBar); | 49 | currentWindow.setMenuBarVisibility(!this.all.app.autohideMenuBar); |
@@ -51,10 +52,8 @@ export default class SettingsStore extends Store { | |||
51 | ); | 52 | ); |
52 | 53 | ||
53 | reaction( | 54 | reaction( |
54 | () => ( | 55 | () => this.all.app.server, |
55 | this.all.app.server | 56 | server => { |
56 | ), | ||
57 | (server) => { | ||
58 | if (server === LOCAL_SERVER) { | 57 | if (server === LOCAL_SERVER) { |
59 | ipcRenderer.send('startLocalServer'); | 58 | ipcRenderer.send('startLocalServer'); |
60 | } | 59 | } |
@@ -65,7 +64,10 @@ export default class SettingsStore extends Store { | |||
65 | // Inactivity lock timer | 64 | // Inactivity lock timer |
66 | let inactivityTimer; | 65 | let inactivityTimer; |
67 | getCurrentWindow().on('blur', () => { | 66 | getCurrentWindow().on('blur', () => { |
68 | if (this.all.app.lockingFeatureEnabled && this.all.app.inactivityLock !== 0) { | 67 | if ( |
68 | this.all.app.lockingFeatureEnabled && | ||
69 | this.all.app.inactivityLock !== 0 | ||
70 | ) { | ||
69 | inactivityTimer = setTimeout(() => { | 71 | inactivityTimer = setTimeout(() => { |
70 | this.actions.settings.update({ | 72 | this.actions.settings.update({ |
71 | type: 'app', | 73 | type: 'app', |
@@ -84,7 +86,11 @@ export default class SettingsStore extends Store { | |||
84 | 86 | ||
85 | ipcRenderer.on('appSettings', (event, resp) => { | 87 | ipcRenderer.on('appSettings', (event, resp) => { |
86 | // Lock on startup if enabled in settings | 88 | // Lock on startup if enabled in settings |
87 | if (this.startup && resp.type === 'app' && resp.data.lockingFeatureEnabled) { | 89 | if ( |
90 | this.startup && | ||
91 | resp.type === 'app' && | ||
92 | resp.data.lockingFeatureEnabled | ||
93 | ) { | ||
88 | this.startup = false; | 94 | this.startup = false; |
89 | process.nextTick(() => { | 95 | process.nextTick(() => { |
90 | if (!this.all.app.locked) { | 96 | if (!this.all.app.locked) { |
@@ -97,9 +103,9 @@ export default class SettingsStore extends Store { | |||
97 | ipcRenderer.send('initialAppSettings', resp); | 103 | ipcRenderer.send('initialAppSettings', resp); |
98 | }); | 104 | }); |
99 | 105 | ||
100 | this.fileSystemSettingsTypes.forEach((type) => { | 106 | for (const type of this.fileSystemSettingsTypes) { |
101 | ipcRenderer.send('getAppSettings', type); | 107 | ipcRenderer.send('getAppSettings', type); |
102 | }); | 108 | } |
103 | } | 109 | } |
104 | 110 | ||
105 | @computed get app() { | 111 | @computed get app() { |
@@ -111,15 +117,19 @@ export default class SettingsStore extends Store { | |||
111 | } | 117 | } |
112 | 118 | ||
113 | @computed get service() { | 119 | @computed get service() { |
114 | return localStorage.getItem('service') || { | 120 | return ( |
115 | activeService: '', | 121 | localStorage.getItem('service') || { |
116 | }; | 122 | activeService: '', |
123 | } | ||
124 | ); | ||
117 | } | 125 | } |
118 | 126 | ||
119 | @computed get stats() { | 127 | @computed get stats() { |
120 | return localStorage.getItem('stats') || { | 128 | return ( |
121 | activeService: '', | 129 | localStorage.getItem('stats') || { |
122 | }; | 130 | activeService: '', |
131 | } | ||
132 | ); | ||
123 | } | 133 | } |
124 | 134 | ||
125 | @computed get migration() { | 135 | @computed get migration() { |
@@ -230,9 +240,7 @@ export default class SettingsStore extends Store { | |||
230 | }); | 240 | }); |
231 | 241 | ||
232 | this._ensureMigrationAndMarkDone('5.4.4-beta.2-settings', () => { | 242 | this._ensureMigrationAndMarkDone('5.4.4-beta.2-settings', () => { |
233 | const { | 243 | const { showServiceNavigationBar } = this.all.app; |
234 | showServiceNavigationBar, | ||
235 | } = this.all.app; | ||
236 | 244 | ||
237 | this.actions.settings.update({ | 245 | this.actions.settings.update({ |
238 | type: 'app', | 246 | type: 'app', |
@@ -248,7 +256,7 @@ export default class SettingsStore extends Store { | |||
248 | data: { | 256 | data: { |
249 | todoServer: 'isUsingCustomTodoService', | 257 | todoServer: 'isUsingCustomTodoService', |
250 | customTodoServer: legacySettings.todoServer, | 258 | customTodoServer: legacySettings.todoServer, |
251 | automaticUpdates: !(legacySettings.noUpdates), | 259 | automaticUpdates: !legacySettings.noUpdates, |
252 | }, | 260 | }, |
253 | }); | 261 | }); |
254 | 262 | ||