aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/SettingsStore.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-11-15 21:26:45 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-11-15 21:26:45 +0100
commit1483b63d34aa9b0eadcebe6e068efc3ce1aa7460 (patch)
tree41423e990decbfd13aa608d99c110a360419b380 /src/stores/SettingsStore.js
parentSet background color based on darkMode (diff)
downloadferdium-app-1483b63d34aa9b0eadcebe6e068efc3ce1aa7460.tar.gz
ferdium-app-1483b63d34aa9b0eadcebe6e068efc3ce1aa7460.tar.zst
ferdium-app-1483b63d34aa9b0eadcebe6e068efc3ce1aa7460.zip
Add migration task to initially set darkMode
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r--src/stores/SettingsStore.js26
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 @@
1import { action, computed, observable } from 'mobx'; 1import { action, computed, observable } from 'mobx';
2import localStorage from 'mobx-localstorage'; 2import localStorage from 'mobx-localstorage';
3import isDarkMode from '@adlk/mojave-isdarkmode';
3 4
4import Store from './lib/Store'; 5import Store from './lib/Store';
5import SettingsModel from '../models/Settings'; 6import 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}