diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api/server/LocalApi.js | 4 | ||||
-rw-r--r-- | src/components/layout/Sidebar.js | 2 | ||||
-rw-r--r-- | src/containers/layout/AppLayoutContainer.js | 9 | ||||
-rw-r--r-- | src/models/News.js | 2 | ||||
-rw-r--r-- | src/models/Plan.js | 2 | ||||
-rw-r--r-- | src/models/RecipePreview.js | 2 | ||||
-rw-r--r-- | src/models/Settings.js | 19 | ||||
-rw-r--r-- | src/models/User.js | 2 | ||||
-rw-r--r-- | src/stores/AppStore.js | 4 | ||||
-rw-r--r-- | src/stores/SettingsStore.js | 13 |
10 files changed, 38 insertions, 21 deletions
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 @@ | |||
1 | import SettingsModel from '../../models/Settings'; | ||
2 | |||
1 | export default class LocalApi { | 3 | export default class LocalApi { |
2 | // App | 4 | // App |
3 | async updateAppSettings(data) { | 5 | async updateAppSettings(data) { |
@@ -13,7 +15,7 @@ export default class LocalApi { | |||
13 | async getAppSettings() { | 15 | async getAppSettings() { |
14 | const settingsString = localStorage.getItem('app'); | 16 | const settingsString = localStorage.getItem('app'); |
15 | try { | 17 | try { |
16 | const settings = JSON.parse(settingsString) || {}; | 18 | const settings = new SettingsModel(JSON.parse(settingsString) || {}); |
17 | console.debug('LocalApi::getAppSettings resolves', settings); | 19 | console.debug('LocalApi::getAppSettings resolves', settings); |
18 | 20 | ||
19 | return settings; | 21 | 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'; | |||
2 | import PropTypes from 'prop-types'; | 2 | import PropTypes from 'prop-types'; |
3 | import ReactTooltip from 'react-tooltip'; | 3 | import ReactTooltip from 'react-tooltip'; |
4 | import { defineMessages, intlShape } from 'react-intl'; | 4 | import { defineMessages, intlShape } from 'react-intl'; |
5 | import { observer } from 'mobx-react'; | ||
5 | 6 | ||
6 | import Tabbar from '../services/tabs/Tabbar'; | 7 | import Tabbar from '../services/tabs/Tabbar'; |
7 | import { ctrlKey } from '../../environment'; | 8 | import { ctrlKey } from '../../environment'; |
@@ -25,6 +26,7 @@ const messages = defineMessages({ | |||
25 | }, | 26 | }, |
26 | }); | 27 | }); |
27 | 28 | ||
29 | @observer | ||
28 | export default class Sidebar extends Component { | 30 | export default class Sidebar extends Component { |
29 | static propTypes = { | 31 | static propTypes = { |
30 | openSettings: PropTypes.func.isRequired, | 32 | 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 { | |||
67 | const isLoadingServices = services.allServicesRequest.isExecuting | 67 | const isLoadingServices = services.allServicesRequest.isExecuting |
68 | && services.allServicesRequest.isExecutingFirstTime; | 68 | && services.allServicesRequest.isExecutingFirstTime; |
69 | 69 | ||
70 | // const isLoadingRecipes = recipes.allRecipesRequest.isExecuting | ||
71 | // && recipes.allRecipesRequest.isExecutingFirstTime; | ||
72 | |||
73 | if (isLoadingServices) { | 70 | if (isLoadingServices) { |
74 | return ( | 71 | return ( |
75 | <AppLoader /> | 72 | <AppLoader /> |
76 | ); | 73 | ); |
77 | } | 74 | } |
78 | 75 | ||
76 | const isMuted = settings.all.isAppMuted || app.isSystemMuted; | ||
77 | |||
79 | const sidebar = ( | 78 | const sidebar = ( |
80 | <Sidebar | 79 | <Sidebar |
81 | services={services.allDisplayed} | 80 | services={services.allDisplayed} |
82 | setActive={setActive} | 81 | setActive={setActive} |
83 | isAppMuted={Boolean(app.isSystemMuted) || Boolean(settings.all.isMuted)} | 82 | isAppMuted={isMuted} |
84 | openSettings={openSettings} | 83 | openSettings={openSettings} |
85 | closeSettings={closeSettings} | 84 | closeSettings={closeSettings} |
86 | reorder={reorder} | 85 | reorder={reorder} |
@@ -100,7 +99,7 @@ export default class AppLayoutContainer extends Component { | |||
100 | setWebviewReference={setWebviewReference} | 99 | setWebviewReference={setWebviewReference} |
101 | openWindow={openWindow} | 100 | openWindow={openWindow} |
102 | reload={reload} | 101 | reload={reload} |
103 | isAppMuted={settings.all.isMuted || false} | 102 | isAppMuted={isMuted} |
104 | update={updateService} | 103 | update={updateService} |
105 | /> | 104 | /> |
106 | ); | 105 | ); |
diff --git a/src/models/News.js b/src/models/News.js index e8953ff8c..a96e6550f 100644 --- a/src/models/News.js +++ b/src/models/News.js | |||
@@ -6,7 +6,7 @@ export default class News { | |||
6 | type: string = 'primary'; | 6 | type: string = 'primary'; |
7 | sticky: bool = false; | 7 | sticky: bool = false; |
8 | 8 | ||
9 | constructor(data: Object) { | 9 | constructor(data) { |
10 | if (!data.id) { | 10 | if (!data.id) { |
11 | throw Error('News requires Id'); | 11 | throw Error('News requires Id'); |
12 | } | 12 | } |
diff --git a/src/models/Plan.js b/src/models/Plan.js index 1f2a44902..e77353824 100644 --- a/src/models/Plan.js +++ b/src/models/Plan.js | |||
@@ -10,7 +10,7 @@ export default class Plan { | |||
10 | price: 0, | 10 | price: 0, |
11 | } | 11 | } |
12 | 12 | ||
13 | constructor(data: Object) { | 13 | constructor(data) { |
14 | Object.assign(this, data); | 14 | Object.assign(this, data); |
15 | } | 15 | } |
16 | } | 16 | } |
diff --git a/src/models/RecipePreview.js b/src/models/RecipePreview.js index 7b497edf3..525a5c4b5 100644 --- a/src/models/RecipePreview.js +++ b/src/models/RecipePreview.js | |||
@@ -6,7 +6,7 @@ export default class RecipePreview { | |||
6 | icon: string = ''; // TODO: check if this isn't replaced by `icons` | 6 | icon: string = ''; // TODO: check if this isn't replaced by `icons` |
7 | featured: bool = false; | 7 | featured: bool = false; |
8 | 8 | ||
9 | constructor(data: Object) { | 9 | constructor(data) { |
10 | if (!data.id) { | 10 | if (!data.id) { |
11 | throw Error('RecipePreview requires Id'); | 11 | throw Error('RecipePreview requires Id'); |
12 | } | 12 | } |
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 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | import { DEFAULT_APP_SETTINGS } from '../config'; | ||
3 | |||
4 | export default class Settings { | ||
5 | @observable autoLaunchOnStart = DEFAULT_APP_SETTINGS.autoLaunchOnStart; | ||
6 | @observable autoLaunchInBackground = DEFAULT_APP_SETTINGS.autoLaunchInBackground; | ||
7 | @observable runInBackground = DEFAULT_APP_SETTINGS.runInBackground; | ||
8 | @observable enableSystemTray = DEFAULT_APP_SETTINGS.enableSystemTray; | ||
9 | @observable minimizeToSystemTray = DEFAULT_APP_SETTINGS.minimizeToSystemTray; | ||
10 | @observable showDisabledServices = DEFAULT_APP_SETTINGS.showDisabledServices; | ||
11 | @observable enableSpellchecking = DEFAULT_APP_SETTINGS.enableSpellchecking; | ||
12 | @observable locale = DEFAULT_APP_SETTINGS.locale; | ||
13 | @observable beta = DEFAULT_APP_SETTINGS.beta; | ||
14 | @observable isAppMuted = DEFAULT_APP_SETTINGS.isAppMuted; | ||
15 | |||
16 | constructor(data) { | ||
17 | Object.assign(this, data); | ||
18 | } | ||
19 | } | ||
diff --git a/src/models/User.js b/src/models/User.js index 94b579928..e2d2fc0c8 100644 --- a/src/models/User.js +++ b/src/models/User.js | |||
@@ -16,7 +16,7 @@ export default class User { | |||
16 | @observable isDonor = false; | 16 | @observable isDonor = false; |
17 | @observable isMiner = false; | 17 | @observable isMiner = false; |
18 | 18 | ||
19 | constructor(data: Object) { | 19 | constructor(data) { |
20 | if (!data.id) { | 20 | if (!data.id) { |
21 | throw Error('User requires Id'); | 21 | throw Error('User requires Id'); |
22 | } | 22 | } |
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 { | |||
220 | @action _muteApp({ isMuted }) { | 220 | @action _muteApp({ isMuted }) { |
221 | this.actions.settings.update({ | 221 | this.actions.settings.update({ |
222 | settings: { | 222 | settings: { |
223 | isMuted, | 223 | isAppMuted: isMuted, |
224 | }, | 224 | }, |
225 | }); | 225 | }); |
226 | } | 226 | } |
227 | 227 | ||
228 | @action _toggleMuteApp() { | 228 | @action _toggleMuteApp() { |
229 | this._muteApp({ isMuted: !this.stores.settings.all.isMuted }); | 229 | this._muteApp({ isMuted: !this.stores.settings.all.isAppMuted }); |
230 | } | 230 | } |
231 | 231 | ||
232 | // Reactions | 232 | // 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 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { action, computed, observable } from 'mobx'; | 2 | import { action, computed, observable, extendObservable } from 'mobx'; |
3 | 3 | ||
4 | import Store from './lib/Store'; | 4 | import Store from './lib/Store'; |
5 | import Request from './lib/Request'; | 5 | import Request from './lib/Request'; |
6 | import CachedRequest from './lib/CachedRequest'; | 6 | import CachedRequest from './lib/CachedRequest'; |
7 | import { gaEvent } from '../lib/analytics'; | 7 | import { gaEvent } from '../lib/analytics'; |
8 | import { DEFAULT_APP_SETTINGS } from '../config'; | ||
9 | 8 | ||
10 | export default class SettingsStore extends Store { | 9 | export default class SettingsStore extends Store { |
11 | @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); | 10 | @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings'); |
@@ -18,10 +17,6 @@ export default class SettingsStore extends Store { | |||
18 | // Register action handlers | 17 | // Register action handlers |
19 | this.actions.settings.update.listen(this._update.bind(this)); | 18 | this.actions.settings.update.listen(this._update.bind(this)); |
20 | this.actions.settings.remove.listen(this._remove.bind(this)); | 19 | this.actions.settings.remove.listen(this._remove.bind(this)); |
21 | |||
22 | // this.registerReactions([ | ||
23 | // this._shareSettingsWithMainProcess.bind(this), | ||
24 | // ]); | ||
25 | } | 20 | } |
26 | 21 | ||
27 | setup() { | 22 | setup() { |
@@ -30,14 +25,14 @@ export default class SettingsStore extends Store { | |||
30 | } | 25 | } |
31 | 26 | ||
32 | @computed get all() { | 27 | @computed get all() { |
33 | return observable(Object.assign(DEFAULT_APP_SETTINGS, this.allSettingsRequest.result)); | 28 | return this.allSettingsRequest.result || {}; |
34 | } | 29 | } |
35 | 30 | ||
36 | @action async _update({ settings }) { | 31 | @action async _update({ settings }) { |
37 | await this.updateSettingsRequest.execute(settings)._promise; | 32 | await this.updateSettingsRequest.execute(settings)._promise; |
38 | this.allSettingsRequest.patch((result) => { | 33 | await this.allSettingsRequest.patch((result) => { |
39 | if (!result) return; | 34 | if (!result) return; |
40 | Object.assign(result, settings); | 35 | extendObservable(result, settings); |
41 | }); | 36 | }); |
42 | 37 | ||
43 | // We need a little hack to wait until everything is patched | 38 | // We need a little hack to wait until everything is patched |