diff options
author | 2018-11-27 18:06:14 +0100 | |
---|---|---|
committer | 2018-11-27 18:06:14 +0100 | |
commit | 62972747866740dae84fc7b519fcedd731572329 (patch) | |
tree | 3a74610caa47350ff6b3cc07482f8472f18c1764 /src/stores | |
parent | Fix listening key (diff) | |
download | ferdium-app-62972747866740dae84fc7b519fcedd731572329.tar.gz ferdium-app-62972747866740dae84fc7b519fcedd731572329.tar.zst ferdium-app-62972747866740dae84fc7b519fcedd731572329.zip |
feat(App): Add proxy support for services
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/FeaturesStore.js | 2 | ||||
-rw-r--r-- | src/stores/ServicesStore.js | 15 | ||||
-rw-r--r-- | src/stores/SettingsStore.js | 81 |
3 files changed, 84 insertions, 14 deletions
diff --git a/src/stores/FeaturesStore.js b/src/stores/FeaturesStore.js index dd4827221..59abeb218 100644 --- a/src/stores/FeaturesStore.js +++ b/src/stores/FeaturesStore.js | |||
@@ -5,6 +5,7 @@ import CachedRequest from './lib/CachedRequest'; | |||
5 | 5 | ||
6 | import delayApp from '../features/delayApp'; | 6 | import delayApp from '../features/delayApp'; |
7 | import spellchecker from '../features/spellchecker'; | 7 | import spellchecker from '../features/spellchecker'; |
8 | import serviceProxy from '../features/serviceProxy'; | ||
8 | 9 | ||
9 | export default class FeaturesStore extends Store { | 10 | export default class FeaturesStore extends Store { |
10 | @observable defaultFeaturesRequest = new CachedRequest(this.api.features, 'default'); | 11 | @observable defaultFeaturesRequest = new CachedRequest(this.api.features, 'default'); |
@@ -38,5 +39,6 @@ export default class FeaturesStore extends Store { | |||
38 | _enableFeatures() { | 39 | _enableFeatures() { |
39 | delayApp(this.stores, this.actions); | 40 | delayApp(this.stores, this.actions); |
40 | spellchecker(this.stores, this.actions); | 41 | spellchecker(this.stores, this.actions); |
42 | serviceProxy(this.stores, this.actions); | ||
41 | } | 43 | } |
42 | } | 44 | } |
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index cdb2db142..e22b343e7 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -143,6 +143,7 @@ export default class ServicesStore extends Store { | |||
143 | // Actions | 143 | // Actions |
144 | @action async _createService({ recipeId, serviceData, redirect = true }) { | 144 | @action async _createService({ recipeId, serviceData, redirect = true }) { |
145 | const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData); | 145 | const data = this._cleanUpTeamIdAndCustomUrl(recipeId, serviceData); |
146 | |||
146 | const response = await this.createServiceRequest.execute(recipeId, data)._promise; | 147 | const response = await this.createServiceRequest.execute(recipeId, data)._promise; |
147 | 148 | ||
148 | this.allServicesRequest.patch((result) => { | 149 | this.allServicesRequest.patch((result) => { |
@@ -150,6 +151,13 @@ export default class ServicesStore extends Store { | |||
150 | result.push(response.data); | 151 | result.push(response.data); |
151 | }); | 152 | }); |
152 | 153 | ||
154 | this.actions.settings.update({ | ||
155 | type: 'proxy', | ||
156 | data: { | ||
157 | [`${response.data.id}`]: data.proxy, | ||
158 | }, | ||
159 | }); | ||
160 | |||
153 | this.actionStatus = response.status || []; | 161 | this.actionStatus = response.status || []; |
154 | 162 | ||
155 | if (redirect) { | 163 | if (redirect) { |
@@ -222,6 +230,13 @@ export default class ServicesStore extends Store { | |||
222 | }); | 230 | }); |
223 | } | 231 | } |
224 | 232 | ||
233 | this.actions.settings.update({ | ||
234 | type: 'proxy', | ||
235 | data: { | ||
236 | [`${serviceId}`]: data.proxy, | ||
237 | }, | ||
238 | }); | ||
239 | |||
225 | if (redirect) { | 240 | if (redirect) { |
226 | this.stores.router.push('/settings/services'); | 241 | this.stores.router.push('/settings/services'); |
227 | gaEvent('Service', 'update', service.recipe.id); | 242 | gaEvent('Service', 'update', service.recipe.id); |
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index f1b067115..a5c2c8b52 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,4 +1,4 @@ | |||
1 | import { remote } from 'electron'; | 1 | import { remote, ipcRenderer } from 'electron'; |
2 | import { action, computed, observable } from 'mobx'; | 2 | import { action, computed, observable } from 'mobx'; |
3 | import localStorage from 'mobx-localstorage'; | 3 | import localStorage from 'mobx-localstorage'; |
4 | 4 | ||
@@ -7,6 +7,8 @@ import SettingsModel from '../models/Settings'; | |||
7 | import Request from './lib/Request'; | 7 | import Request from './lib/Request'; |
8 | import CachedRequest from './lib/CachedRequest'; | 8 | import CachedRequest from './lib/CachedRequest'; |
9 | 9 | ||
10 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; | ||
11 | |||
10 | const { systemPreferences } = remote; | 12 | const { systemPreferences } = remote; |
11 | const debug = require('debug')('Franz:SettingsStore'); | 13 | const debug = require('debug')('Franz:SettingsStore'); |
12 | 14 | ||
@@ -14,12 +16,35 @@ export default class SettingsStore extends Store { | |||
14 | @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings'); | 16 | @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings'); |
15 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); | 17 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); |
16 | 18 | ||
19 | @observable fileSystemSettingsRequests = []; | ||
20 | |||
21 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; | ||
22 | @observable _fileSystemSettingsCache = { | ||
23 | app: DEFAULT_APP_SETTINGS, | ||
24 | proxy: {}, | ||
25 | }; | ||
26 | |||
17 | constructor(...args) { | 27 | constructor(...args) { |
18 | super(...args); | 28 | super(...args); |
19 | 29 | ||
20 | // Register action handlers | 30 | // Register action handlers |
21 | this.actions.settings.update.listen(this._update.bind(this)); | 31 | this.actions.settings.update.listen(this._update.bind(this)); |
22 | this.actions.settings.remove.listen(this._remove.bind(this)); | 32 | this.actions.settings.remove.listen(this._remove.bind(this)); |
33 | |||
34 | this.fileSystemSettingsTypes.forEach((type) => { | ||
35 | this.fileSystemSettingsRequests[type] = new CachedRequest(this.api.local, 'getAppSettings'); | ||
36 | }); | ||
37 | |||
38 | ipcRenderer.on('appSettings', (event, resp) => { | ||
39 | debug('Get appSettings resolves', resp, resp.type, resp.data); | ||
40 | |||
41 | this._fileSystemSettingsCache[resp.type] = resp.data; | ||
42 | }); | ||
43 | |||
44 | this.fileSystemSettingsTypes.forEach((type) => { | ||
45 | console.log(type); | ||
46 | ipcRenderer.send('getAppSettings', type); | ||
47 | }); | ||
23 | } | 48 | } |
24 | 49 | ||
25 | async setup() { | 50 | async setup() { |
@@ -28,29 +53,53 @@ export default class SettingsStore extends Store { | |||
28 | await this._migrate(); | 53 | await this._migrate(); |
29 | } | 54 | } |
30 | 55 | ||
56 | @computed get app() { | ||
57 | return this._fileSystemSettingsCache.app || DEFAULT_APP_SETTINGS; | ||
58 | } | ||
59 | |||
60 | @computed get proxy() { | ||
61 | return this._fileSystemSettingsCache.proxy || {}; | ||
62 | } | ||
63 | |||
64 | @computed get service() { | ||
65 | return localStorage.getItem('service') || { | ||
66 | activeService: '', | ||
67 | }; | ||
68 | } | ||
69 | |||
70 | @computed get stats() { | ||
71 | return localStorage.getItem('stats') || { | ||
72 | activeService: '', | ||
73 | }; | ||
74 | } | ||
75 | |||
76 | @computed get migration() { | ||
77 | return localStorage.getItem('migration') || {}; | ||
78 | } | ||
79 | |||
31 | @computed get all() { | 80 | @computed get all() { |
32 | return new SettingsModel({ | 81 | return { |
33 | app: this.appSettingsRequest.execute().result || {}, | 82 | app: this.app, |
34 | service: localStorage.getItem('service') || {}, | 83 | proxy: this.proxy, |
35 | group: localStorage.getItem('group') || {}, | 84 | service: this.service, |
36 | stats: localStorage.getItem('stats') || {}, | 85 | stats: this.stats, |
37 | migration: localStorage.getItem('migration') || {}, | 86 | migration: this.migration, |
38 | }); | 87 | }; |
39 | } | 88 | } |
40 | 89 | ||
41 | @action async _update({ type, data }) { | 90 | @action async _update({ type, data }) { |
42 | const appSettings = this.all; | 91 | const appSettings = this.all; |
43 | if (type !== 'app') { | 92 | if (!this.fileSystemSettingsTypes.includes(type)) { |
44 | debug('Update settings', type, data, this.all); | 93 | debug('Update settings', type, data, this.all); |
45 | localStorage.setItem(type, Object.assign(appSettings[type], data)); | 94 | localStorage.setItem(type, Object.assign(appSettings[type], data)); |
46 | } else { | 95 | } else { |
47 | debug('Update settings on file system', type, data); | 96 | debug('Update settings on file system', type, data); |
48 | this.updateAppSettingsRequest.execute(data); | 97 | ipcRenderer.send('updateAppSettings', { |
49 | 98 | type, | |
50 | this.appSettingsRequest.patch((result) => { | 99 | data, |
51 | if (!result) return; | ||
52 | Object.assign(result, data); | ||
53 | }); | 100 | }); |
101 | |||
102 | Object.assign(this._fileSystemSettingsCache[type], data); | ||
54 | } | 103 | } |
55 | } | 104 | } |
56 | 105 | ||
@@ -128,4 +177,8 @@ export default class SettingsStore extends Store { | |||
128 | debug('Set up dark mode'); | 177 | debug('Set up dark mode'); |
129 | } | 178 | } |
130 | } | 179 | } |
180 | |||
181 | _getFileBasedSettings(type) { | ||
182 | ipcRenderer.send('getAppSettings', type); | ||
183 | } | ||
131 | } | 184 | } |