aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/SettingsStore.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-03-28 10:03:34 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-03-28 10:03:34 +0200
commitca66ab1a3b53ec677e0eba69e9feea3ad777c3bf (patch)
treeacaf55edae05a485d56d164386e6f3f9603ecda6 /src/stores/SettingsStore.js
parentSplit settings into multiple stores; app specific settings are now stored in ... (diff)
downloadferdium-app-ca66ab1a3b53ec677e0eba69e9feea3ad777c3bf.tar.gz
ferdium-app-ca66ab1a3b53ec677e0eba69e9feea3ad777c3bf.tar.zst
ferdium-app-ca66ab1a3b53ec677e0eba69e9feea3ad777c3bf.zip
Add settings migration
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r--src/stores/SettingsStore.js65
1 files changed, 58 insertions, 7 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index b3f5d3eaf..075cb6482 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -21,22 +21,27 @@ export default class SettingsStore extends Store {
21 this.actions.settings.remove.listen(this._remove.bind(this)); 21 this.actions.settings.remove.listen(this._remove.bind(this));
22 } 22 }
23 23
24 setup() {
25 this._migrate();
26 }
27
24 @computed get all() { 28 @computed get all() {
25 return new SettingsModel({ 29 return new SettingsModel({
26 app: this.appSettingsRequest.execute().result || {}, 30 app: this.appSettingsRequest.execute().result || {},
27 service: localStorage.getItem('service') || {}, 31 service: localStorage.getItem('service') || {},
28 group: localStorage.getItem('group') || {}, 32 group: localStorage.getItem('group') || {},
29 stats: localStorage.getItem('stats') || {}, 33 stats: localStorage.getItem('stats') || {},
34 migration: localStorage.getItem('migration') || {},
30 }); 35 });
31 } 36 }
32 37
33 @action async _update({ type, data }) { 38 @action async _update({ type, data }) {
34 debug('Update settings', type, data, this.all);
35 const appSettings = this.all; 39 const appSettings = this.all;
36 if (type !== 'app') { 40 if (type !== 'app') {
41 debug('Update settings', type, data, this.all);
37 localStorage.setItem(type, Object.assign(appSettings[type], data)); 42 localStorage.setItem(type, Object.assign(appSettings[type], data));
38 } else { 43 } else {
39 debug('Store app settings on file system', type, data); 44 debug('Update settings on file system', type, data);
40 this.updateAppSettingsRequest.execute(data); 45 this.updateAppSettingsRequest.execute(data);
41 46
42 this.appSettingsRequest.patch((result) => { 47 this.appSettingsRequest.patch((result) => {
@@ -46,18 +51,64 @@ export default class SettingsStore extends Store {
46 } 51 }
47 } 52 }
48 53
49 @action async _remove({ key }) { 54 @action async _remove({ type, key }) {
50 const appSettings = this.all; 55 if (type === 'app') return; // app keys can't be deleted
56
57 const appSettings = this.all[type];
51 if (Object.hasOwnProperty.call(appSettings, key)) { 58 if (Object.hasOwnProperty.call(appSettings, key)) {
52 delete appSettings[key]; 59 delete appSettings[key];
53 localStorage.setItem('app', appSettings);
54 }
55 60
56 this._shareSettingsWithMainProcess(); 61 this.actions.settings.update({
62 type,
63 data: appSettings,
64 });
65 }
57 } 66 }
58 67
59 // Reactions 68 // Reactions
60 _shareSettingsWithMainProcess() { 69 _shareSettingsWithMainProcess() {
61 ipcRenderer.send('settings', this.all); 70 ipcRenderer.send('settings', this.all);
62 } 71 }
72
73 // Helper
74 _migrate() {
75 const legacySettings = localStorage.getItem('app');
76
77 if (!this.all.migration['5.0.0-beta.17-settings']) {
78 this.actions.settings.update({
79 type: 'app',
80 data: {
81 autoLaunchInBackground: legacySettings.autoLaunchInBackground,
82 runInBackground: legacySettings.runInBackground,
83 enableSystemTray: legacySettings.enableSystemTray,
84 minimizeToSystemTray: legacySettings.minimizeToSystemTray,
85 isAppMuted: legacySettings.isAppMuted,
86 enableGPUAcceleration: legacySettings.enableGPUAcceleration,
87 showMessageBadgeWhenMuted: legacySettings.showMessageBadgeWhenMuted,
88 showDisabledServices: legacySettings.showDisabledServices,
89 enableSpellchecking: legacySettings.enableSpellchecking,
90 locale: legacySettings.locale,
91 beta: legacySettings.beta,
92 },
93 });
94
95 this.actions.settings.update({
96 type: 'service',
97 data: {
98 activeService: legacySettings.activeService,
99 },
100 });
101
102 this.actions.settings.update({
103 type: 'migration',
104 data: {
105 '5.0.0-beta.17-settings': true,
106 },
107 });
108
109 localStorage.removeItem('app');
110
111 debug('Migrated settings to split stores');
112 }
113 }
63} 114}