aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-03-27 21:25:56 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-03-27 21:25:56 +0200
commit8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d (patch)
tree9b853e0d343f4bf2f60625431275bdc2dd08e027 /src/stores
parentMove "locale" to user data (diff)
downloadferdium-app-8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d.tar.gz
ferdium-app-8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d.tar.zst
ferdium-app-8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d.zip
Split settings into multiple stores; app specific settings are now stored in config file
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js17
-rw-r--r--src/stores/ServicesStore.js15
-rw-r--r--src/stores/SettingsStore.js41
-rw-r--r--src/stores/UIStore.js2
4 files changed, 46 insertions, 29 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 94ed308f3..3c6c24b59 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -159,7 +159,7 @@ export default class AppStore extends Store {
159 159
160 // Actions 160 // Actions
161 @action _notify({ title, options, notificationId, serviceId = null }) { 161 @action _notify({ title, options, notificationId, serviceId = null }) {
162 if (this.stores.settings.all.isAppMuted) return; 162 if (this.stores.settings.all.app.isAppMuted) return;
163 163
164 const notification = new window.Notification(title, options); 164 const notification = new window.Notification(title, options);
165 notification.onclick = (e) => { 165 notification.onclick = (e) => {
@@ -240,14 +240,15 @@ export default class AppStore extends Store {
240 this.isSystemMuteOverridden = overrideSystemMute; 240 this.isSystemMuteOverridden = overrideSystemMute;
241 241
242 this.actions.settings.update({ 242 this.actions.settings.update({
243 settings: { 243 type: 'app',
244 data: {
244 isAppMuted: isMuted, 245 isAppMuted: isMuted,
245 }, 246 },
246 }); 247 });
247 } 248 }
248 249
249 @action _toggleMuteApp() { 250 @action _toggleMuteApp() {
250 this._muteApp({ isMuted: !this.stores.settings.all.isAppMuted }); 251 this._muteApp({ isMuted: !this.stores.settings.all.app.isAppMuted });
251 } 252 }
252 253
253 @action async _clearAllCache() { 254 @action async _clearAllCache() {
@@ -331,8 +332,9 @@ export default class AppStore extends Store {
331 // Helpers 332 // Helpers
332 _appStartsCounter() { 333 _appStartsCounter() {
333 this.actions.settings.update({ 334 this.actions.settings.update({
334 settings: { 335 type: 'stats',
335 appStarts: (this.stores.settings.all.appStarts || 0) + 1, 336 data: {
337 appStarts: (this.stores.settings.all.stats.appStarts || 0) + 1,
336 }, 338 },
337 }); 339 });
338 } 340 }
@@ -340,7 +342,8 @@ export default class AppStore extends Store {
340 async _autoStart() { 342 async _autoStart() {
341 this.autoLaunchOnStart = await this._checkAutoStart(); 343 this.autoLaunchOnStart = await this._checkAutoStart();
342 344
343 if (this.stores.settings.all.appStarts === 1) { 345 if (this.stores.settings.all.stats.appStarts === 1) {
346 debug('Set app to launch on start');
344 this.actions.app.launchOnStartup({ 347 this.actions.app.launchOnStartup({
345 enable: true, 348 enable: true,
346 }); 349 });
@@ -353,7 +356,7 @@ export default class AppStore extends Store {
353 356
354 _systemDND() { 357 _systemDND() {
355 const dnd = getDoNotDisturb(); 358 const dnd = getDoNotDisturb();
356 if (dnd !== this.stores.settings.all.isAppMuted && !this.isSystemMuteOverridden) { 359 if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) {
357 this.actions.app.muteApp({ 360 this.actions.app.muteApp({
358 isMuted: dnd, 361 isMuted: dnd,
359 overrideSystemMute: false, 362 overrideSystemMute: false,
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index f7d92b1ff..b96bc506b 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -86,13 +86,13 @@ export default class ServicesStore extends Store {
86 } 86 }
87 87
88 @computed get allDisplayed() { 88 @computed get allDisplayed() {
89 return this.stores.settings.all.showDisabledServices ? this.all : this.enabled; 89 return this.stores.settings.all.service.showDisabledServices ? this.all : this.enabled;
90 } 90 }
91 91
92 // This is just used to avoid unnecessary rerendering of resource-heavy webviews 92 // This is just used to avoid unnecessary rerendering of resource-heavy webviews
93 @computed get allDisplayedUnordered() { 93 @computed get allDisplayedUnordered() {
94 const services = this.allServicesRequest.execute().result || []; 94 const services = this.allServicesRequest.execute().result || [];
95 return this.stores.settings.all.showDisabledServices ? services : services.filter(service => service.isEnabled); 95 return this.stores.settings.all.service.showDisabledServices ? services : services.filter(service => service.isEnabled);
96 } 96 }
97 97
98 @computed get filtered() { 98 @computed get filtered() {
@@ -334,7 +334,7 @@ export default class ServicesStore extends Store {
334 }); 334 });
335 } else if (channel === 'notification') { 335 } else if (channel === 'notification') {
336 const options = args[0].options; 336 const options = args[0].options;
337 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.isAppMuted) { 337 if (service.recipe.hasNotificationSound || service.isMuted || this.stores.settings.all.app.isAppMuted) {
338 Object.assign(options, { 338 Object.assign(options, {
339 silent: true, 339 silent: true,
340 }); 340 });
@@ -434,7 +434,7 @@ export default class ServicesStore extends Store {
434 } 434 }
435 435
436 @action _reorder({ oldIndex, newIndex }) { 436 @action _reorder({ oldIndex, newIndex }) {
437 const showDisabledServices = this.stores.settings.all.showDisabledServices; 437 const showDisabledServices = this.stores.settings.all.service.showDisabledServices;
438 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); 438 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]);
439 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); 439 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]);
440 440
@@ -512,7 +512,8 @@ export default class ServicesStore extends Store {
512 512
513 if (service) { 513 if (service) {
514 this.actions.settings.update({ 514 this.actions.settings.update({
515 settings: { 515 type: 'service',
516 data: {
516 activeService: service.id, 517 activeService: service.id,
517 }, 518 },
518 }); 519 });
@@ -520,7 +521,7 @@ export default class ServicesStore extends Store {
520 } 521 }
521 522
522 _mapActiveServiceToServiceModelReaction() { 523 _mapActiveServiceToServiceModelReaction() {
523 const { activeService } = this.stores.settings.all; 524 const { activeService } = this.stores.settings.all.service;
524 if (this.allDisplayed.length) { 525 if (this.allDisplayed.length) {
525 this.allDisplayed.map(service => Object.assign(service, { 526 this.allDisplayed.map(service => Object.assign(service, {
526 isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id, 527 isActive: activeService ? activeService === service.id : this.allDisplayed[0].id === service.id,
@@ -529,7 +530,7 @@ export default class ServicesStore extends Store {
529 } 530 }
530 531
531 _getUnreadMessageCountReaction() { 532 _getUnreadMessageCountReaction() {
532 const showMessageBadgeWhenMuted = this.stores.settings.all.showMessageBadgeWhenMuted; 533 const showMessageBadgeWhenMuted = this.stores.settings.all.app.showMessageBadgeWhenMuted;
533 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; 534 const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted;
534 535
535 const unreadDirectMessageCount = this.allDisplayed 536 const unreadDirectMessageCount = this.allDisplayed
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index b7d803398..b3f5d3eaf 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -1,12 +1,18 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { action, computed } from 'mobx'; 2import { action, computed, observable } from 'mobx';
3import localStorage from 'mobx-localstorage'; 3import localStorage from 'mobx-localstorage';
4 4
5import Store from './lib/Store'; 5import Store from './lib/Store';
6import { gaEvent } from '../lib/analytics';
7import SettingsModel from '../models/Settings'; 6import SettingsModel from '../models/Settings';
7import Request from './lib/Request';
8import CachedRequest from './lib/CachedRequest';
9
10const debug = require('debug')('SettingsStore');
8 11
9export default class SettingsStore extends Store { 12export default class SettingsStore extends Store {
13 @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings');
14 @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings');
15
10 constructor(...args) { 16 constructor(...args) {
11 super(...args); 17 super(...args);
12 18
@@ -15,22 +21,29 @@ export default class SettingsStore extends Store {
15 this.actions.settings.remove.listen(this._remove.bind(this)); 21 this.actions.settings.remove.listen(this._remove.bind(this));
16 } 22 }
17 23
18 setup() {
19 this._shareSettingsWithMainProcess();
20 }
21
22 @computed get all() { 24 @computed get all() {
23 return new SettingsModel(localStorage.getItem('app') || {}); 25 return new SettingsModel({
26 app: this.appSettingsRequest.execute().result || {},
27 service: localStorage.getItem('service') || {},
28 group: localStorage.getItem('group') || {},
29 stats: localStorage.getItem('stats') || {},
30 });
24 } 31 }
25 32
26 @action async _update({ settings }) { 33 @action async _update({ type, data }) {
34 debug('Update settings', type, data, this.all);
27 const appSettings = this.all; 35 const appSettings = this.all;
28 localStorage.setItem('app', Object.assign(appSettings, settings)); 36 if (type !== 'app') {
29 37 localStorage.setItem(type, Object.assign(appSettings[type], data));
30 // We need a little hack to wait until everything is patched 38 } else {
31 setTimeout(() => this._shareSettingsWithMainProcess(), 0); 39 debug('Store app settings on file system', type, data);
32 40 this.updateAppSettingsRequest.execute(data);
33 gaEvent('Settings', 'update'); 41
42 this.appSettingsRequest.patch((result) => {
43 if (!result) return;
44 Object.assign(result, data);
45 });
46 }
34 } 47 }
35 48
36 @action async _remove({ key }) { 49 @action async _remove({ key }) {
diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js
index 5e9cc9ba7..b391bdcae 100644
--- a/src/stores/UIStore.js
+++ b/src/stores/UIStore.js
@@ -17,7 +17,7 @@ export default class UIStore extends Store {
17 @computed get showMessageBadgesEvenWhenMuted() { 17 @computed get showMessageBadgesEvenWhenMuted() {
18 const settings = this.stores.settings.all; 18 const settings = this.stores.settings.all;
19 19
20 return (settings.isAppMuted && settings.showMessageBadgeWhenMuted) || !settings.isAppMuted; 20 return (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) || !settings.isAppMuted;
21 } 21 }
22 22
23 // Actions 23 // Actions