aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/serviceProxy
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-12-05 11:11:41 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-12-05 11:11:41 +0100
commit4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5 (patch)
tree03271792b328da14bedabe8c2923aa2394cceb82 /src/features/serviceProxy
parentfix(App): Use system proxy for services (diff)
downloadferdium-app-4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5.tar.gz
ferdium-app-4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5.tar.zst
ferdium-app-4ebe1a0cc36061541d3a414a6a8b7a7aacc68ed5.zip
Simplify setProxy logic / use system defaults unless overwritten
Diffstat (limited to 'src/features/serviceProxy')
-rw-r--r--src/features/serviceProxy/index.js47
1 files changed, 18 insertions, 29 deletions
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 @@
1import { autorun, observable } from 'mobx'; 1import { autorun, observable } from 'mobx';
2import { remote } from 'electron'; 2import { remote } from 'electron';
3 3
4import { DEFAULT_FEATURES_CONFIG, HEALTHCHECK_URL } from '../../config'; 4import { DEFAULT_FEATURES_CONFIG } from '../../config';
5 5
6const { session } = remote; 6const { session } = remote;
7 7
@@ -15,41 +15,30 @@ export const config = observable({
15export default function init(stores) { 15export 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}