diff options
author | 2018-12-04 15:20:50 +0100 | |
---|---|---|
committer | 2018-12-04 15:20:50 +0100 | |
commit | 8ddae4a65853ec392eefa01b87145221f53f51c2 (patch) | |
tree | 6d77c6d3c702a5ec6bbd0d218fa149efad97a4bd | |
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
-rw-r--r-- | src/config.js | 2 | ||||
-rw-r--r-- | src/features/serviceProxy/index.js | 45 |
2 files changed, 30 insertions, 17 deletions
diff --git a/src/config.js b/src/config.js index ba3af14b9..b24d18888 100644 --- a/src/config.js +++ b/src/config.js | |||
@@ -10,6 +10,8 @@ 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 | |||
13 | export const DEFAULT_APP_SETTINGS = { | 15 | export const DEFAULT_APP_SETTINGS = { |
14 | autoLaunchInBackground: false, | 16 | autoLaunchInBackground: false, |
15 | runInBackground: true, | 17 | runInBackground: true, |
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 | }); |