diff options
author | 2018-12-05 11:11:41 +0100 | |
---|---|---|
committer | 2018-12-05 11:11:41 +0100 | |
commit | 4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5 (patch) | |
tree | 03271792b328da14bedabe8c2923aa2394cceb82 | |
parent | fix(App): Use system proxy for services (diff) | |
download | ferdium-app-4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5.tar.gz ferdium-app-4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5.tar.zst ferdium-app-4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5.zip |
Simplify setProxy logic / use system defaults unless overwritten
-rw-r--r-- | src/config.js | 2 | ||||
-rw-r--r-- | src/features/serviceProxy/index.js | 47 |
2 files changed, 18 insertions, 31 deletions
diff --git a/src/config.js b/src/config.js index b24d18888..ba3af14b9 100644 --- a/src/config.js +++ b/src/config.js | |||
@@ -10,8 +10,6 @@ export const DEV_API = 'https://dev.franzinfra.com'; | |||
10 | export const LIVE_API = 'https://api.franzinfra.com'; | 10 | export const LIVE_API = 'https://api.franzinfra.com'; |
11 | export const GA_ID = 'UA-74126766-10'; | 11 | export const GA_ID = 'UA-74126766-10'; |
12 | 12 | ||
13 | export const HEALTHCHECK_URL = 'https://api.franzinfra.com/health'; | ||
14 | |||
15 | export const DEFAULT_APP_SETTINGS = { | 13 | export const DEFAULT_APP_SETTINGS = { |
16 | autoLaunchInBackground: false, | 14 | autoLaunchInBackground: false, |
17 | runInBackground: true, | 15 | runInBackground: true, |
diff --git a/src/features/serviceProxy/index.js b/src/features/serviceProxy/index.js index e7e6e16d7..ee0b4e79c 100644 --- a/src/features/serviceProxy/index.js +++ b/src/features/serviceProxy/index.js | |||
@@ -1,7 +1,7 @@ | |||
1 | import { autorun, observable } from 'mobx'; | 1 | import { autorun, observable } from 'mobx'; |
2 | import { remote } from 'electron'; | 2 | import { remote } from 'electron'; |
3 | 3 | ||
4 | import { DEFAULT_FEATURES_CONFIG, HEALTHCHECK_URL } from '../../config'; | 4 | import { DEFAULT_FEATURES_CONFIG } from '../../config'; |
5 | 5 | ||
6 | const { session } = remote; | 6 | const { session } = remote; |
7 | 7 | ||
@@ -15,41 +15,30 @@ export const config = observable({ | |||
15 | export default function init(stores) { | 15 | export default function init(stores) { |
16 | debug('Initializing `serviceProxy` feature'); | 16 | debug('Initializing `serviceProxy` feature'); |
17 | 17 | ||
18 | const { defaultSession } = session; | 18 | autorun(() => { |
19 | defaultSession.resolveProxy(HEALTHCHECK_URL, (proxy) => { | 19 | const { isServiceProxyEnabled, isServiceProxyPremiumFeature } = stores.features.features; |
20 | debug('Resolve proxy', proxy); | ||
21 | 20 | ||
22 | let systemProxy = 'direct://'; | 21 | config.isEnabled = isServiceProxyEnabled !== undefined ? isServiceProxyEnabled : DEFAULT_FEATURES_CONFIG.isServiceProxyEnabled; |
23 | const proxyMatch = proxy.match(/PROXY (.*)/i); | 22 | config.isPremium = isServiceProxyPremiumFeature !== undefined ? isServiceProxyPremiumFeature : DEFAULT_FEATURES_CONFIG.isServiceProxyPremiumFeature; |
24 | if (proxyMatch.length) { | ||
25 | systemProxy = proxyMatch[1].trim(); | ||
26 | } | ||
27 | 23 | ||
28 | autorun(() => { | 24 | const services = stores.services.enabled; |
29 | const { isServiceProxyEnabled, isServiceProxyPremiumFeature } = stores.features.features; | 25 | const isPremiumUser = stores.user.data.isPremium; |
30 | 26 | ||
31 | config.isEnabled = isServiceProxyEnabled !== undefined ? isServiceProxyEnabled : DEFAULT_FEATURES_CONFIG.isServiceProxyEnabled; | 27 | services.forEach((service) => { |
32 | config.isPremium = isServiceProxyPremiumFeature !== undefined ? isServiceProxyPremiumFeature : DEFAULT_FEATURES_CONFIG.isServiceProxyPremiumFeature; | 28 | const s = session.fromPartition(`persist:service-${service.id}`); |
33 | 29 | ||
34 | const services = stores.services.enabled; | 30 | if (config.isEnabled && (isPremiumUser || !config.isPremium)) { |
35 | const isPremiumUser = stores.user.data.isPremium; | 31 | const serviceProxyConfig = stores.settings.proxy[service.id]; |
36 | 32 | ||
37 | services.forEach((service) => { | 33 | if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { |
38 | let proxyHost = systemProxy; | 34 | const proxyHost = serviceProxyConfig.host; |
39 | const s = session.fromPartition(`persist:service-${service.id}`); | 35 | debug(`Setting proxy config from service settings for "${service.name}" (${service.id}) to`, proxyHost); |
40 | 36 | ||
41 | if (config.isEnabled && (isPremiumUser || !config.isPremium)) { | 37 | s.setProxy({ proxyRules: proxyHost }, () => { |
42 | const serviceProxyConfig = stores.settings.proxy[service.id]; | 38 | debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`); |
43 | 39 | }); | |
44 | if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { | ||
45 | proxyHost = serviceProxyConfig.host; | ||
46 | } | ||
47 | } | 40 | } |
48 | 41 | } | |
49 | s.setProxy({ proxyRules: proxyHost }, () => { | ||
50 | debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`); | ||
51 | }); | ||
52 | }); | ||
53 | }); | 42 | }); |
54 | }); | 43 | }); |
55 | } | 44 | } |