diff options
author | 2018-12-04 15:20:50 +0100 | |
---|---|---|
committer | 2018-12-04 15:20:50 +0100 | |
commit | 8ddae4a65853ec392eefa01b87145221f53f51c2 (patch) | |
tree | 6d77c6d3c702a5ec6bbd0d218fa149efad97a4bd /src/features | |
parent | feat(Context Menu): Add "Go Back" and "Go Forward" (diff) | |
download | ferdium-app-8ddae4a65853ec392eefa01b87145221f53f51c2.tar.gz ferdium-app-8ddae4a65853ec392eefa01b87145221f53f51c2.tar.zst ferdium-app-8ddae4a65853ec392eefa01b87145221f53f51c2.zip |
fix(App): Use system proxy for services
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/serviceProxy/index.js | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/features/serviceProxy/index.js b/src/features/serviceProxy/index.js index cad9844fd..e7e6e16d7 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 } from '../../config'; | 4 | import { DEFAULT_FEATURES_CONFIG, HEALTHCHECK_URL } from '../../config'; |
5 | 5 | ||
6 | const { session } = remote; | 6 | const { session } = remote; |
7 | 7 | ||
@@ -15,29 +15,40 @@ 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 | autorun(() => { | 18 | const { defaultSession } = session; |
19 | const { isServiceProxyEnabled, isServiceProxyPremiumFeature } = stores.features.features; | 19 | defaultSession.resolveProxy(HEALTHCHECK_URL, (proxy) => { |
20 | debug('Resolve proxy', proxy); | ||
20 | 21 | ||
21 | config.isEnabled = isServiceProxyEnabled !== undefined ? isServiceProxyEnabled : DEFAULT_FEATURES_CONFIG.isServiceProxyEnabled; | 22 | let systemProxy = 'direct://'; |
22 | config.isPremium = isServiceProxyPremiumFeature !== undefined ? isServiceProxyPremiumFeature : DEFAULT_FEATURES_CONFIG.isServiceProxyPremiumFeature; | 23 | const proxyMatch = proxy.match(/PROXY (.*)/i); |
24 | if (proxyMatch.length) { | ||
25 | systemProxy = proxyMatch[1].trim(); | ||
26 | } | ||
23 | 27 | ||
24 | const services = stores.services.all; | 28 | autorun(() => { |
25 | const isPremiumUser = stores.user.data.isPremium; | 29 | const { isServiceProxyEnabled, isServiceProxyPremiumFeature } = stores.features.features; |
26 | 30 | ||
27 | services.forEach((service) => { | 31 | config.isEnabled = isServiceProxyEnabled !== undefined ? isServiceProxyEnabled : DEFAULT_FEATURES_CONFIG.isServiceProxyEnabled; |
28 | const s = session.fromPartition(`persist:service-${service.id}`); | 32 | config.isPremium = isServiceProxyPremiumFeature !== undefined ? isServiceProxyPremiumFeature : DEFAULT_FEATURES_CONFIG.isServiceProxyPremiumFeature; |
29 | let proxyHost = 'direct://'; | ||
30 | 33 | ||
31 | if (config.isEnabled && (isPremiumUser || !config.isPremium)) { | 34 | const services = stores.services.enabled; |
32 | const serviceProxyConfig = stores.settings.proxy[service.id]; | 35 | const isPremiumUser = stores.user.data.isPremium; |
33 | 36 | ||
34 | if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { | 37 | services.forEach((service) => { |
35 | proxyHost = serviceProxyConfig.host; | 38 | let proxyHost = systemProxy; |
39 | const s = session.fromPartition(`persist:service-${service.id}`); | ||
40 | |||
41 | if (config.isEnabled && (isPremiumUser || !config.isPremium)) { | ||
42 | const serviceProxyConfig = stores.settings.proxy[service.id]; | ||
43 | |||
44 | if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { | ||
45 | proxyHost = serviceProxyConfig.host; | ||
46 | } | ||
36 | } | 47 | } |
37 | } | ||
38 | 48 | ||
39 | s.setProxy({ proxyRules: proxyHost }, (e) => { | 49 | s.setProxy({ proxyRules: proxyHost }, () => { |
40 | debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`, e); | 50 | debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`); |
51 | }); | ||
41 | }); | 52 | }); |
42 | }); | 53 | }); |
43 | }); | 54 | }); |