Permalink
Browse files

fix(App): Use system proxy for services

  • Loading branch information...
adlk committed Dec 4, 2018
1 parent 5c18595 commit 8ddae4a65853ec392eefa01b87145221f53f51c2
Showing with 30 additions and 17 deletions.
  1. +2 −0 src/config.js
  2. +28 −17 src/features/serviceProxy/index.js
@@ -10,6 +10,8 @@ export const DEV_API = 'https://dev.franzinfra.com';
export const LIVE_API = 'https://api.franzinfra.com';
export const GA_ID = 'UA-74126766-10';
export const HEALTHCHECK_URL = 'https://api.franzinfra.com/health';
export const DEFAULT_APP_SETTINGS = {
autoLaunchInBackground: false,
runInBackground: true,
@@ -1,7 +1,7 @@
import { autorun, observable } from 'mobx';
import { remote } from 'electron';
import { DEFAULT_FEATURES_CONFIG } from '../../config';
import { DEFAULT_FEATURES_CONFIG, HEALTHCHECK_URL } from '../../config';
const { session } = remote;
@@ -15,29 +15,40 @@ export const config = observable({
export default function init(stores) {
debug('Initializing `serviceProxy` feature');
autorun(() => {
const { isServiceProxyEnabled, isServiceProxyPremiumFeature } = stores.features.features;
const { defaultSession } = session;
defaultSession.resolveProxy(HEALTHCHECK_URL, (proxy) => {
debug('Resolve proxy', proxy);
config.isEnabled = isServiceProxyEnabled !== undefined ? isServiceProxyEnabled : DEFAULT_FEATURES_CONFIG.isServiceProxyEnabled;
config.isPremium = isServiceProxyPremiumFeature !== undefined ? isServiceProxyPremiumFeature : DEFAULT_FEATURES_CONFIG.isServiceProxyPremiumFeature;
let systemProxy = 'direct://';
const proxyMatch = proxy.match(/PROXY (.*)/i);
if (proxyMatch.length) {
systemProxy = proxyMatch[1].trim();
}
const services = stores.services.all;
const isPremiumUser = stores.user.data.isPremium;
autorun(() => {
const { isServiceProxyEnabled, isServiceProxyPremiumFeature } = stores.features.features;
services.forEach((service) => {
const s = session.fromPartition(`persist:service-${service.id}`);
let proxyHost = 'direct://';
config.isEnabled = isServiceProxyEnabled !== undefined ? isServiceProxyEnabled : DEFAULT_FEATURES_CONFIG.isServiceProxyEnabled;
config.isPremium = isServiceProxyPremiumFeature !== undefined ? isServiceProxyPremiumFeature : DEFAULT_FEATURES_CONFIG.isServiceProxyPremiumFeature;
if (config.isEnabled && (isPremiumUser || !config.isPremium)) {
const serviceProxyConfig = stores.settings.proxy[service.id];
const services = stores.services.enabled;
const isPremiumUser = stores.user.data.isPremium;
if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) {
proxyHost = serviceProxyConfig.host;
services.forEach((service) => {
let proxyHost = systemProxy;
const s = session.fromPartition(`persist:service-${service.id}`);
if (config.isEnabled && (isPremiumUser || !config.isPremium)) {
const serviceProxyConfig = stores.settings.proxy[service.id];
if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) {
proxyHost = serviceProxyConfig.host;
}
}
}
s.setProxy({ proxyRules: proxyHost }, (e) => {
debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`, e);
s.setProxy({ proxyRules: proxyHost }, () => {
debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`);
});
});
});
});

0 comments on commit 8ddae4a

Please sign in to comment.