diff options
author | 2022-04-23 01:59:21 +0200 | |
---|---|---|
committer | 2022-04-22 23:59:21 +0000 | |
commit | d02644f7c41150709795e57bfd40351b4da35a7b (patch) | |
tree | 2403fb76bd5fae1703f8b55172ffce9e0a5d2bce /src/features/todos/preload.ts | |
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/todos/preload.ts')
-rw-r--r-- | src/features/todos/preload.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/features/todos/preload.ts b/src/features/todos/preload.ts index 4ccee39a0..6c8bc1aea 100644 --- a/src/features/todos/preload.ts +++ b/src/features/todos/preload.ts | |||
@@ -1,10 +1,9 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { IPC } from './constants'; | 2 | import { IPC } from './constants'; |
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:todos:preload'); |
5 | // const debug = require('debug')('Ferdium:feature:todos:preload'); | ||
6 | 5 | ||
7 | console.log('Preloading Todos Webview'); | 6 | debug('Preloading Todos Webview'); |
8 | 7 | ||
9 | let hostMessageListener = ({ action }) => { | 8 | let hostMessageListener = ({ action }) => { |
10 | switch (action) { | 9 | switch (action) { |
@@ -28,7 +27,7 @@ window['ferdium'] = { | |||
28 | }; | 27 | }; |
29 | 28 | ||
30 | ipcRenderer.on(IPC.TODOS_HOST_CHANNEL, (event, message) => { | 29 | ipcRenderer.on(IPC.TODOS_HOST_CHANNEL, (event, message) => { |
31 | console.log('Received host message', event, message); | 30 | debug('Received host message', event, message); |
32 | hostMessageListener(message); | 31 | hostMessageListener(message); |
33 | }); | 32 | }); |
34 | 33 | ||