From 1483b63d34aa9b0eadcebe6e068efc3ce1aa7460 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 15 Nov 2018 21:26:45 +0100 Subject: Add migration task to initially set darkMode --- src/stores/SettingsStore.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/stores/SettingsStore.js') 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 @@ import { action, computed, observable } from 'mobx'; import localStorage from 'mobx-localstorage'; +import isDarkMode from '@adlk/mojave-isdarkmode'; import Store from './lib/Store'; import SettingsModel from '../models/Settings'; @@ -23,7 +24,7 @@ export default class SettingsStore extends Store { async setup() { // 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 await this.appSettingsRequest._promise; - this._migrate(); + await this._migrate(); } @computed get all() { @@ -67,7 +68,7 @@ export default class SettingsStore extends Store { } // Helper - _migrate() { + async _migrate() { const legacySettings = localStorage.getItem('app') || {}; if (!this.all.migration['5.0.0-beta.17-settings']) { @@ -104,5 +105,26 @@ export default class SettingsStore extends Store { debug('Migrated settings to split stores'); } + + // Enable dark mode once + if (!this.all.migration['5.0.0-beta.19-settings']) { + this.actions.settings.update({ + type: 'app', + data: { + darkMode: await isDarkMode(), + }, + }); + + this.actions.settings.update({ + type: 'migration', + data: { + '5.0.0-beta.19-settings': true, + }, + }); + + localStorage.removeItem('app'); + + debug('Set up dark mode'); + } } } -- cgit v1.2.3-54-g00ecf