From d02644f7c41150709795e57bfd40351b4da35a7b Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 23 Apr 2022 01:59:21 +0200 Subject: Preload safe debug shim (#29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In https://github.com/ferdium/ferdium-app/pull/23 we removed usages of the debug package due to an electron bug. This patch aims to restore some debug functionality by introducing a shim. The shim detect whether if it is being introduced in a preload script where the electron but would be triggered, and falls back to a simple replacement for debug. However, in the main and renderer processes, where a preload script is not being used, we still get full debug functionality. In this way, a module can be used both in a preload script and outside of it, while still preserving debug functionality whenever possible. Signed-off-by: Kristóf Marussy --- src/features/serviceProxy/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/features/serviceProxy') diff --git a/src/features/serviceProxy/index.ts b/src/features/serviceProxy/index.ts index b3705b190..e0d667a72 100644 --- a/src/features/serviceProxy/index.ts +++ b/src/features/serviceProxy/index.ts @@ -1,8 +1,7 @@ import { autorun, observable } from 'mobx'; import { session } from '@electron/remote'; -// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed -// const debug = require('debug')('Ferdium:feature:serviceProxy'); +const debug = require('../../preload-safe-debug')('Ferdium:feature:serviceProxy'); export const config = observable({ isEnabled: true, @@ -12,7 +11,7 @@ export default function init(stores: { services: { enabled: any }; settings: { proxy: any }; }) { - console.log('Initializing `serviceProxy` feature'); + debug('Initializing `serviceProxy` feature'); autorun(() => { config.isEnabled = true; @@ -20,7 +19,7 @@ export default function init(stores: { const services = stores.services.enabled; const proxySettings = stores.settings.proxy; - console.log('Service Proxy autorun'); + debug('Service Proxy autorun'); for (const service of services) { const s = session.fromPartition(`persist:service-${service.id}`); @@ -36,14 +35,14 @@ export default function init(stores: { const proxyHost = `${serviceProxyConfig.host}${ serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : '' }`; - console.log( + debug( `Setting proxy config from service settings for "${service.name}" (${service.id}) to`, proxyHost, ); s.setProxy({ proxyRules: proxyHost }) .then(() => { - console.log( + debug( `Using proxy "${proxyHost}" for "${service.name}" (${service.id})`, ); }) -- cgit v1.2.3-54-g00ecf