From 4960927289b88bcacbf7af2baa9c551deac64072 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Wed, 8 Sep 2021 23:44:24 +0530 Subject: Revert "chore: proxy feature is always turned on: remove 'enabled' flag" This reverts commit 2772cb2e3e75f16b3dc96a2441518ed0772e3ba1. --- .../settings/services/EditServiceForm.js | 68 ++++++++++--------- src/containers/settings/EditServiceScreen.js | 77 ++++++++++++---------- src/features/serviceProxy/index.js | 29 +++++--- .../src/containers/settings/EditServiceScreen.json | 76 ++++++++++----------- 4 files changed, 135 insertions(+), 115 deletions(-) (limited to 'src') diff --git a/src/components/settings/services/EditServiceForm.js b/src/components/settings/services/EditServiceForm.js index 23c667b82..c41cdd56a 100644 --- a/src/components/settings/services/EditServiceForm.js +++ b/src/components/settings/services/EditServiceForm.js @@ -144,6 +144,7 @@ export default @observer class EditServiceForm extends Component { openRecipeFile: PropTypes.func.isRequired, isSaving: PropTypes.bool.isRequired, isDeleting: PropTypes.bool.isRequired, + isProxyFeatureEnabled: PropTypes.bool.isRequired, }; static defaultProps = { @@ -205,6 +206,7 @@ export default @observer class EditServiceForm extends Component { isDeleting, onDelete, openRecipeFile, + isProxyFeatureEnabled, } = this.props; const { intl } = this.context; @@ -368,40 +370,42 @@ export default @observer class EditServiceForm extends Component { )} -
-

- {intl.formatMessage(messages.headlineProxy)} - beta -

- - {form.$('proxy.isEnabled').value && ( - <> -
-
- - + {isProxyFeatureEnabled && ( +
+

+ {intl.formatMessage(messages.headlineProxy)} + beta +

+ + {form.$('proxy.isEnabled').value && ( + <> +
+
+ + +
-
-
-
- - +
+
+ + +
-
-

- - {intl.formatMessage(messages.proxyRestartInfo)} -

-

- - {intl.formatMessage(messages.proxyInfo)} -

- - )} -
+

+ + {intl.formatMessage(messages.proxyRestartInfo)} +

+

+ + {intl.formatMessage(messages.proxyInfo)} +

+ + )} +
+ )}
diff --git a/src/containers/settings/EditServiceScreen.js b/src/containers/settings/EditServiceScreen.js index 3a66a27e6..c880e97ae 100644 --- a/src/containers/settings/EditServiceScreen.js +++ b/src/containers/settings/EditServiceScreen.js @@ -18,6 +18,8 @@ import ErrorBoundary from '../../components/util/ErrorBoundary'; import { required, url, oneRequired } from '../../helpers/validation-helpers'; import { getSelectOptions } from '../../helpers/i18n-helpers'; +import { config as proxyFeature } from '../../features/serviceProxy'; + import { SPELLCHECKER_LOCALES } from '../../i18n/languages'; import globalMessages from '../../i18n/globalMessages'; @@ -129,7 +131,7 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex } } - prepareForm(recipe, service) { + prepareForm(recipe, service, proxy) { const { intl, } = this.context; @@ -273,42 +275,44 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex }); } - const serviceProxyConfig = stores.settings.proxy[service.id] || {}; - - Object.assign(config.fields, { - proxy: { - name: 'proxy', - label: 'proxy', - fields: { - isEnabled: { - label: intl.formatMessage(messages.enableProxy), - value: serviceProxyConfig.isEnabled, - default: false, - }, - host: { - label: intl.formatMessage(messages.proxyHost), - value: serviceProxyConfig.host, - default: '', - }, - port: { - label: intl.formatMessage(messages.proxyPort), - value: serviceProxyConfig.port, - default: '', - }, - user: { - label: intl.formatMessage(messages.proxyUser), - value: serviceProxyConfig.user, - default: '', - }, - password: { - label: intl.formatMessage(messages.proxyPassword), - value: serviceProxyConfig.password, - default: '', - type: 'password', + if (proxy.isEnabled) { + const serviceProxyConfig = stores.settings.proxy[service.id] || {}; + + Object.assign(config.fields, { + proxy: { + name: 'proxy', + label: 'proxy', + fields: { + isEnabled: { + label: intl.formatMessage(messages.enableProxy), + value: serviceProxyConfig.isEnabled, + default: false, + }, + host: { + label: intl.formatMessage(messages.proxyHost), + value: serviceProxyConfig.host, + default: '', + }, + port: { + label: intl.formatMessage(messages.proxyPort), + value: serviceProxyConfig.port, + default: '', + }, + user: { + label: intl.formatMessage(messages.proxyUser), + value: serviceProxyConfig.user, + default: '', + }, + password: { + label: intl.formatMessage(messages.proxyPassword), + value: serviceProxyConfig.password, + default: '', + type: 'password', + }, }, }, - }, - }); + }); + } return new Form(config); } @@ -377,7 +381,7 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex ); } - const form = this.prepareForm(recipe, service); + const form = this.prepareForm(recipe, service, proxyFeature); return ( @@ -393,6 +397,7 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex onSubmit={(d) => this.onSubmit(d)} onDelete={() => this.deleteService()} openRecipeFile={(file) => this.openRecipeFile(file)} + isProxyFeatureEnabled={proxyFeature.isEnabled} /> ); diff --git a/src/features/serviceProxy/index.js b/src/features/serviceProxy/index.js index 125b4729f..eb7116651 100644 --- a/src/features/serviceProxy/index.js +++ b/src/features/serviceProxy/index.js @@ -1,26 +1,37 @@ -import { autorun } from 'mobx'; +import { autorun, observable } from 'mobx'; import { session } from '@electron/remote'; const debug = require('debug')('Ferdi:feature:serviceProxy'); +export const config = observable({ + isEnabled: true, +}); + export default function init(stores) { debug('Initializing `serviceProxy` feature'); autorun(() => { + config.isEnabled = true; + const services = stores.services.enabled; const proxySettings = stores.settings.proxy; debug('Service Proxy autorun'); services.forEach((service) => { - const serviceProxyConfig = proxySettings[service.id]; - if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { - const proxyHost = `${serviceProxyConfig.host}${serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : ''}`; - debug(`Setting proxy config from service settings for "${service.name}" (${service.id}) to`, proxyHost); - - session.fromPartition(`persist:service-${service.id}`).setProxy({ proxyRules: proxyHost }, () => { - debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`); - }); + const s = session.fromPartition(`persist:service-${service.id}`); + + if (config.isEnabled) { + const serviceProxyConfig = proxySettings[service.id]; + + if (serviceProxyConfig && serviceProxyConfig.isEnabled && serviceProxyConfig.host) { + const proxyHost = `${serviceProxyConfig.host}${serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : ''}`; + debug(`Setting proxy config from service settings for "${service.name}" (${service.id}) to`, proxyHost); + + s.setProxy({ proxyRules: proxyHost }, () => { + debug(`Using proxy "${proxyHost}" for "${service.name}" (${service.id})`); + }); + } } }); }); diff --git a/src/i18n/messages/src/containers/settings/EditServiceScreen.json b/src/i18n/messages/src/containers/settings/EditServiceScreen.json index 4e44b3c8c..6744a9ff3 100644 --- a/src/i18n/messages/src/containers/settings/EditServiceScreen.json +++ b/src/i18n/messages/src/containers/settings/EditServiceScreen.json @@ -4,11 +4,11 @@ "defaultMessage": "!!!Name", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 26, + "line": 28, "column": 8 }, "end": { - "line": 29, + "line": 31, "column": 3 } }, @@ -17,11 +17,11 @@ "defaultMessage": "!!!Enable service", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 30, + "line": 32, "column": 17 }, "end": { - "line": 33, + "line": 35, "column": 3 } }, @@ -30,11 +30,11 @@ "defaultMessage": "!!!Enable hibernation", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 34, + "line": 36, "column": 21 }, "end": { - "line": 37, + "line": 39, "column": 3 } }, @@ -43,11 +43,11 @@ "defaultMessage": "!!!Enable Notifications", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 38, + "line": 40, "column": 22 }, "end": { - "line": 41, + "line": 43, "column": 3 } }, @@ -56,11 +56,11 @@ "defaultMessage": "!!!Show unread message badges", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 42, + "line": 44, "column": 15 }, "end": { - "line": 45, + "line": 47, "column": 3 } }, @@ -69,11 +69,11 @@ "defaultMessage": "!!!Enable audio", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 46, + "line": 48, "column": 15 }, "end": { - "line": 49, + "line": 51, "column": 3 } }, @@ -82,11 +82,11 @@ "defaultMessage": "!!!Team", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 50, + "line": 52, "column": 8 }, "end": { - "line": 53, + "line": 55, "column": 3 } }, @@ -95,11 +95,11 @@ "defaultMessage": "!!!Service URL", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 54, + "line": 56, "column": 13 }, "end": { - "line": 57, + "line": 59, "column": 3 } }, @@ -108,11 +108,11 @@ "defaultMessage": "!!!Show message badge for all new messages", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 58, + "line": 60, "column": 20 }, "end": { - "line": 61, + "line": 63, "column": 3 } }, @@ -121,11 +121,11 @@ "defaultMessage": "!!!Custom icon", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 62, + "line": 64, "column": 8 }, "end": { - "line": 65, + "line": 67, "column": 3 } }, @@ -134,11 +134,11 @@ "defaultMessage": "!!!Enable Dark Mode", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 66, + "line": 68, "column": 18 }, "end": { - "line": 69, + "line": 71, "column": 3 } }, @@ -147,11 +147,11 @@ "defaultMessage": "!!!Dark Reader Brightness", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 70, + "line": 72, "column": 24 }, "end": { - "line": 73, + "line": 75, "column": 3 } }, @@ -160,11 +160,11 @@ "defaultMessage": "!!!Dark Reader Contrast", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 74, + "line": 76, "column": 22 }, "end": { - "line": 77, + "line": 79, "column": 3 } }, @@ -173,11 +173,11 @@ "defaultMessage": "!!!Dark Reader Sepia", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 78, + "line": 80, "column": 19 }, "end": { - "line": 81, + "line": 83, "column": 3 } }, @@ -186,11 +186,11 @@ "defaultMessage": "!!!Use Proxy", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 82, + "line": 84, "column": 15 }, "end": { - "line": 85, + "line": 87, "column": 3 } }, @@ -199,11 +199,11 @@ "defaultMessage": "!!!Proxy Host/IP", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 86, + "line": 88, "column": 13 }, "end": { - "line": 89, + "line": 91, "column": 3 } }, @@ -212,11 +212,11 @@ "defaultMessage": "!!!Port", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 90, + "line": 92, "column": 13 }, "end": { - "line": 93, + "line": 95, "column": 3 } }, @@ -225,11 +225,11 @@ "defaultMessage": "!!!User", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 94, + "line": 96, "column": 13 }, "end": { - "line": 97, + "line": 99, "column": 3 } }, @@ -238,11 +238,11 @@ "defaultMessage": "!!!Password", "file": "src/containers/settings/EditServiceScreen.js", "start": { - "line": 98, + "line": 100, "column": 17 }, "end": { - "line": 101, + "line": 103, "column": 3 } } -- cgit v1.2.3-70-g09d2