diff options
-rw-r--r-- | src/stores/SettingsStore.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 9270a6481..019ec12bb 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,5 +1,6 @@ | |||
1 | import { action, computed, observable } from 'mobx'; | 1 | import { action, computed, observable } from 'mobx'; |
2 | import localStorage from 'mobx-localstorage'; | 2 | import localStorage from 'mobx-localstorage'; |
3 | import isDarkMode from '@adlk/mojave-isdarkmode'; | ||
3 | 4 | ||
4 | import Store from './lib/Store'; | 5 | import Store from './lib/Store'; |
5 | import SettingsModel from '../models/Settings'; | 6 | import SettingsModel from '../models/Settings'; |
@@ -23,7 +24,7 @@ export default class SettingsStore extends Store { | |||
23 | async setup() { | 24 | async setup() { |
24 | // We need to wait until `appSettingsRequest` has been executed once, otherwise we can't patch the result. If we don't wait we'd run into an issue with mobx not reacting to changes of previously not existing keys | 25 | // We need to wait until `appSettingsRequest` has been executed once, otherwise we can't patch the result. If we don't wait we'd run into an issue with mobx not reacting to changes of previously not existing keys |
25 | await this.appSettingsRequest._promise; | 26 | await this.appSettingsRequest._promise; |
26 | this._migrate(); | 27 | await this._migrate(); |
27 | } | 28 | } |
28 | 29 | ||
29 | @computed get all() { | 30 | @computed get all() { |
@@ -67,7 +68,7 @@ export default class SettingsStore extends Store { | |||
67 | } | 68 | } |
68 | 69 | ||
69 | // Helper | 70 | // Helper |
70 | _migrate() { | 71 | async _migrate() { |
71 | const legacySettings = localStorage.getItem('app') || {}; | 72 | const legacySettings = localStorage.getItem('app') || {}; |
72 | 73 | ||
73 | if (!this.all.migration['5.0.0-beta.17-settings']) { | 74 | if (!this.all.migration['5.0.0-beta.17-settings']) { |
@@ -104,5 +105,26 @@ export default class SettingsStore extends Store { | |||
104 | 105 | ||
105 | debug('Migrated settings to split stores'); | 106 | debug('Migrated settings to split stores'); |
106 | } | 107 | } |
108 | |||
109 | // Enable dark mode once | ||
110 | if (!this.all.migration['5.0.0-beta.19-settings']) { | ||
111 | this.actions.settings.update({ | ||
112 | type: 'app', | ||
113 | data: { | ||
114 | darkMode: await isDarkMode(), | ||
115 | }, | ||
116 | }); | ||
117 | |||
118 | this.actions.settings.update({ | ||
119 | type: 'migration', | ||
120 | data: { | ||
121 | '5.0.0-beta.19-settings': true, | ||
122 | }, | ||
123 | }); | ||
124 | |||
125 | localStorage.removeItem('app'); | ||
126 | |||
127 | debug('Set up dark mode'); | ||
128 | } | ||
107 | } | 129 | } |
108 | } | 130 | } |