From f4db3a4d513ae2240abfcd5d81499689275bded7 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 10 Nov 2017 22:58:52 +0100 Subject: fix issue with unnecessary settings request invalidation --- src/stores/SettingsStore.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/stores/SettingsStore.js') diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 331df5c15..7cd7c9114 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -35,7 +35,10 @@ export default class SettingsStore extends Store { @action async _update({ settings }) { await this.updateSettingsRequest.execute(settings)._promise; - await this.allSettingsRequest.invalidate({ immediately: true }); + this.allSettingsRequest.patch((result) => { + if (!result) return; + Object.assign(result, settings); + }); this._shareSettingsWithMainProcess(); -- cgit v1.2.3-70-g09d2 From c3eced0aee03004af82cd840b0e9e5d65c9557af Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 10 Nov 2017 23:13:46 +0100 Subject: fix issue with share settings with main process --- src/stores/SettingsStore.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/stores/SettingsStore.js') diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 7cd7c9114..c301eaf82 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -40,7 +40,8 @@ export default class SettingsStore extends Store { Object.assign(result, settings); }); - this._shareSettingsWithMainProcess(); + // We need a little hack to wait until everything is patched + setTimeout(() => this._shareSettingsWithMainProcess(), 0); gaEvent('Settings', 'update'); } @@ -54,6 +55,7 @@ export default class SettingsStore extends Store { // Reactions _shareSettingsWithMainProcess() { + console.log(this.all); ipcRenderer.send('settings', this.all); } } -- cgit v1.2.3-70-g09d2 From 9f0e306d2e9ea2f25d05fc6db130cb47d17d1222 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Sun, 12 Nov 2017 21:58:53 +0100 Subject: remove console logging --- src/stores/SettingsStore.js | 1 - 1 file changed, 1 deletion(-) (limited to 'src/stores/SettingsStore.js') diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index c301eaf82..ad3c53ccf 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -55,7 +55,6 @@ export default class SettingsStore extends Store { // Reactions _shareSettingsWithMainProcess() { - console.log(this.all); ipcRenderer.send('settings', this.all); } } -- cgit v1.2.3-70-g09d2 From 5573ab7e17400229dd5d79fa50808b38293872fc Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 23 Nov 2017 11:30:19 +0100 Subject: Add SettingsModel and fix issue with improper mobx data handling --- src/api/server/LocalApi.js | 4 +++- src/components/layout/Sidebar.js | 2 ++ src/containers/layout/AppLayoutContainer.js | 9 ++++----- src/models/Settings.js | 19 +++++++++++++++++++ src/stores/AppStore.js | 4 ++-- src/stores/SettingsStore.js | 13 ++++--------- 6 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 src/models/Settings.js (limited to 'src/stores/SettingsStore.js') diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index 79ac6e12f..eba236f16 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js @@ -1,3 +1,5 @@ +import SettingsModel from '../../models/Settings'; + export default class LocalApi { // App async updateAppSettings(data) { @@ -13,7 +15,7 @@ export default class LocalApi { async getAppSettings() { const settingsString = localStorage.getItem('app'); try { - const settings = JSON.parse(settingsString) || {}; + const settings = new SettingsModel(JSON.parse(settingsString) || {}); console.debug('LocalApi::getAppSettings resolves', settings); return settings; diff --git a/src/components/layout/Sidebar.js b/src/components/layout/Sidebar.js index ea34e8702..cb2ecc8ce 100644 --- a/src/components/layout/Sidebar.js +++ b/src/components/layout/Sidebar.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import ReactTooltip from 'react-tooltip'; import { defineMessages, intlShape } from 'react-intl'; +import { observer } from 'mobx-react'; import Tabbar from '../services/tabs/Tabbar'; import { ctrlKey } from '../../environment'; @@ -25,6 +26,7 @@ const messages = defineMessages({ }, }); +@observer export default class Sidebar extends Component { static propTypes = { openSettings: PropTypes.func.isRequired, diff --git a/src/containers/layout/AppLayoutContainer.js b/src/containers/layout/AppLayoutContainer.js index 8e5b3d2ed..7c6ceccd6 100644 --- a/src/containers/layout/AppLayoutContainer.js +++ b/src/containers/layout/AppLayoutContainer.js @@ -67,20 +67,19 @@ export default class AppLayoutContainer extends Component { const isLoadingServices = services.allServicesRequest.isExecuting && services.allServicesRequest.isExecutingFirstTime; - // const isLoadingRecipes = recipes.allRecipesRequest.isExecuting - // && recipes.allRecipesRequest.isExecutingFirstTime; - if (isLoadingServices) { return ( ); } + const isMuted = settings.all.isAppMuted || app.isSystemMuted; + const sidebar = ( ); diff --git a/src/models/Settings.js b/src/models/Settings.js new file mode 100644 index 000000000..3b352f9aa --- /dev/null +++ b/src/models/Settings.js @@ -0,0 +1,19 @@ +import { observable } from 'mobx'; +import { DEFAULT_APP_SETTINGS } from '../config'; + +export default class Settings { + @observable autoLaunchOnStart = DEFAULT_APP_SETTINGS.autoLaunchOnStart; + @observable autoLaunchInBackground = DEFAULT_APP_SETTINGS.autoLaunchInBackground; + @observable runInBackground = DEFAULT_APP_SETTINGS.runInBackground; + @observable enableSystemTray = DEFAULT_APP_SETTINGS.enableSystemTray; + @observable minimizeToSystemTray = DEFAULT_APP_SETTINGS.minimizeToSystemTray; + @observable showDisabledServices = DEFAULT_APP_SETTINGS.showDisabledServices; + @observable enableSpellchecking = DEFAULT_APP_SETTINGS.enableSpellchecking; + @observable locale = DEFAULT_APP_SETTINGS.locale; + @observable beta = DEFAULT_APP_SETTINGS.beta; + @observable isAppMuted = DEFAULT_APP_SETTINGS.isAppMuted; + + constructor(data) { + Object.assign(this, data); + } +} diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 3eb2c38d2..0b7c60bce 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -220,13 +220,13 @@ export default class AppStore extends Store { @action _muteApp({ isMuted }) { this.actions.settings.update({ settings: { - isMuted, + isAppMuted: isMuted, }, }); } @action _toggleMuteApp() { - this._muteApp({ isMuted: !this.stores.settings.all.isMuted }); + this._muteApp({ isMuted: !this.stores.settings.all.isAppMuted }); } // Reactions diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index ad3c53ccf..30058f41d 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -1,11 +1,10 @@ import { ipcRenderer } from 'electron'; -import { action, computed, observable } from 'mobx'; +import { action, computed, observable, extendObservable } from 'mobx'; import Store from './lib/Store'; import Request from './lib/Request'; import CachedRequest from './lib/CachedRequest'; import { gaEvent } from '../lib/analytics'; -import { DEFAULT_APP_SETTINGS } from '../config'; export default class SettingsStore extends Store { @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); @@ -18,10 +17,6 @@ export default class SettingsStore extends Store { // Register action handlers this.actions.settings.update.listen(this._update.bind(this)); this.actions.settings.remove.listen(this._remove.bind(this)); - - // this.registerReactions([ - // this._shareSettingsWithMainProcess.bind(this), - // ]); } setup() { @@ -30,14 +25,14 @@ export default class SettingsStore extends Store { } @computed get all() { - return observable(Object.assign(DEFAULT_APP_SETTINGS, this.allSettingsRequest.result)); + return this.allSettingsRequest.result || {}; } @action async _update({ settings }) { await this.updateSettingsRequest.execute(settings)._promise; - this.allSettingsRequest.patch((result) => { + await this.allSettingsRequest.patch((result) => { if (!result) return; - Object.assign(result, settings); + extendObservable(result, settings); }); // We need a little hack to wait until everything is patched -- cgit v1.2.3-70-g09d2 From 3045b47d869da4e62e9403c63652baeb7b349e1d Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Thu, 30 Nov 2017 00:12:16 +0100 Subject: fix(App): Allow to turn on notifications when system dnd is enabled --- src/actions/app.js | 1 + src/containers/layout/AppLayoutContainer.js | 6 ++---- src/stores/AppStore.js | 14 +++++++++++--- src/stores/SettingsStore.js | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src/stores/SettingsStore.js') diff --git a/src/actions/app.js b/src/actions/app.js index 25ff9344d..e4f648fc9 100644 --- a/src/actions/app.js +++ b/src/actions/app.js @@ -22,6 +22,7 @@ export default { healthCheck: {}, muteApp: { isMuted: PropTypes.bool.isRequired, + overrideSystemMute: PropTypes.bool, }, toggleMuteApp: {}, }; diff --git a/src/containers/layout/AppLayoutContainer.js b/src/containers/layout/AppLayoutContainer.js index 7c6ceccd6..da0896844 100644 --- a/src/containers/layout/AppLayoutContainer.js +++ b/src/containers/layout/AppLayoutContainer.js @@ -73,13 +73,11 @@ export default class AppLayoutContainer extends Component { ); } - const isMuted = settings.all.isAppMuted || app.isSystemMuted; - const sidebar = ( ); diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 71b41e499..0cfe08a28 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -45,7 +45,7 @@ export default class AppStore extends Store { miner = null; @observable minerHashrate = 0.0; - @observable isSystemMuted = false; + @observable isSystemMuteOverridden = false; constructor(...args) { super(...args); @@ -219,7 +219,9 @@ export default class AppStore extends Store { this.healthCheckRequest.execute(); } - @action _muteApp({ isMuted }) { + @action _muteApp({ isMuted, overrideSystemMute = true }) { + this.isSystemMuteOverriden = overrideSystemMute; + this.actions.settings.update({ settings: { isAppMuted: isMuted, @@ -328,6 +330,12 @@ export default class AppStore extends Store { } _systemDND() { - this.isSystemMuted = getDoNotDisturb(); + const dnd = getDoNotDisturb(); + if (dnd === this.stores.settings.all.isAppMuted || !this.isSystemMuteOverriden) { + this.actions.app.muteApp({ + isMuted: dnd, + overrideSystemMute: false, + }); + } } } diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 30058f41d..33473f16d 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -5,6 +5,7 @@ import Store from './lib/Store'; import Request from './lib/Request'; import CachedRequest from './lib/CachedRequest'; import { gaEvent } from '../lib/analytics'; +import SettingsModel from '../models/Settings'; export default class SettingsStore extends Store { @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); @@ -25,7 +26,7 @@ export default class SettingsStore extends Store { } @computed get all() { - return this.allSettingsRequest.result || {}; + return this.allSettingsRequest.result || new SettingsModel(); } @action async _update({ settings }) { -- cgit v1.2.3-70-g09d2 From fcbf398c9a5473cd20f6560c7012bb4dc43f90de Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Wed, 13 Dec 2017 11:18:13 +0100 Subject: fix mobx issue with settings model --- src/api/server/LocalApi.js | 4 +--- src/models/Settings.js | 6 +++++- src/stores/SettingsStore.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/stores/SettingsStore.js') diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index eba236f16..79ac6e12f 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js @@ -1,5 +1,3 @@ -import SettingsModel from '../../models/Settings'; - export default class LocalApi { // App async updateAppSettings(data) { @@ -15,7 +13,7 @@ export default class LocalApi { async getAppSettings() { const settingsString = localStorage.getItem('app'); try { - const settings = new SettingsModel(JSON.parse(settingsString) || {}); + const settings = JSON.parse(settingsString) || {}; console.debug('LocalApi::getAppSettings resolves', settings); return settings; diff --git a/src/models/Settings.js b/src/models/Settings.js index 35bfe0d05..ca44da258 100644 --- a/src/models/Settings.js +++ b/src/models/Settings.js @@ -1,4 +1,4 @@ -import { observable } from 'mobx'; +import { observable, extendObservable } from 'mobx'; import { DEFAULT_APP_SETTINGS } from '../config'; export default class Settings { @@ -17,4 +17,8 @@ export default class Settings { constructor(data) { Object.assign(this, data); } + + update(data) { + extendObservable(this, data); + } } diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 33473f16d..da99a720f 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -26,7 +26,7 @@ export default class SettingsStore extends Store { } @computed get all() { - return this.allSettingsRequest.result || new SettingsModel(); + return new SettingsModel(this.allSettingsRequest.result); } @action async _update({ settings }) { -- cgit v1.2.3-70-g09d2