diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-04-23 01:59:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 23:59:21 +0000 |
commit | d02644f7c41150709795e57bfd40351b4da35a7b (patch) | |
tree | 2403fb76bd5fae1703f8b55172ffce9e0a5d2bce /src/features/serviceProxy | |
parent | Complete tray icons redesign for all platforms (#28) (diff) | |
download | ferdium-app-d02644f7c41150709795e57bfd40351b4da35a7b.tar.gz ferdium-app-d02644f7c41150709795e57bfd40351b4da35a7b.tar.zst ferdium-app-d02644f7c41150709795e57bfd40351b4da35a7b.zip |
Preload safe debug shim (#29)
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 <kristof@marussy.com>
Diffstat (limited to 'src/features/serviceProxy')
-rw-r--r-- | src/features/serviceProxy/index.ts | 11 |
1 files changed, 5 insertions, 6 deletions
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 @@ | |||
1 | import { autorun, observable } from 'mobx'; | 1 | import { autorun, observable } from 'mobx'; |
2 | import { session } from '@electron/remote'; | 2 | import { session } from '@electron/remote'; |
3 | 3 | ||
4 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed | 4 | const debug = require('../../preload-safe-debug')('Ferdium:feature:serviceProxy'); |
5 | // const debug = require('debug')('Ferdium:feature:serviceProxy'); | ||
6 | 5 | ||
7 | export const config = observable({ | 6 | export const config = observable({ |
8 | isEnabled: true, | 7 | isEnabled: true, |
@@ -12,7 +11,7 @@ export default function init(stores: { | |||
12 | services: { enabled: any }; | 11 | services: { enabled: any }; |
13 | settings: { proxy: any }; | 12 | settings: { proxy: any }; |
14 | }) { | 13 | }) { |
15 | console.log('Initializing `serviceProxy` feature'); | 14 | debug('Initializing `serviceProxy` feature'); |
16 | 15 | ||
17 | autorun(() => { | 16 | autorun(() => { |
18 | config.isEnabled = true; | 17 | config.isEnabled = true; |
@@ -20,7 +19,7 @@ export default function init(stores: { | |||
20 | const services = stores.services.enabled; | 19 | const services = stores.services.enabled; |
21 | const proxySettings = stores.settings.proxy; | 20 | const proxySettings = stores.settings.proxy; |
22 | 21 | ||
23 | console.log('Service Proxy autorun'); | 22 | debug('Service Proxy autorun'); |
24 | 23 | ||
25 | for (const service of services) { | 24 | for (const service of services) { |
26 | const s = session.fromPartition(`persist:service-${service.id}`); | 25 | const s = session.fromPartition(`persist:service-${service.id}`); |
@@ -36,14 +35,14 @@ export default function init(stores: { | |||
36 | const proxyHost = `${serviceProxyConfig.host}${ | 35 | const proxyHost = `${serviceProxyConfig.host}${ |
37 | serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : '' | 36 | serviceProxyConfig.port ? `:${serviceProxyConfig.port}` : '' |
38 | }`; | 37 | }`; |
39 | console.log( | 38 | debug( |
40 | `Setting proxy config from service settings for "${service.name}" (${service.id}) to`, | 39 | `Setting proxy config from service settings for "${service.name}" (${service.id}) to`, |
41 | proxyHost, | 40 | proxyHost, |
42 | ); | 41 | ); |
43 | 42 | ||
44 | s.setProxy({ proxyRules: proxyHost }) | 43 | s.setProxy({ proxyRules: proxyHost }) |
45 | .then(() => { | 44 | .then(() => { |
46 | console.log( | 45 | debug( |
47 | `Using proxy "${proxyHost}" for "${service.name}" (${service.id})`, | 46 | `Using proxy "${proxyHost}" for "${service.name}" (${service.id})`, |
48 | ); | 47 | ); |
49 | }) | 48 | }) |