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/webview/darkmode.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/webview/darkmode.ts')
-rw-r--r-- | src/webview/darkmode.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/webview/darkmode.ts b/src/webview/darkmode.ts index 99ee68757..34f987b51 100644 --- a/src/webview/darkmode.ts +++ b/src/webview/darkmode.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import { join } from 'path'; | 1 | import { join } from 'path'; |
2 | import { pathExistsSync, readFileSync } from 'fs-extra'; | 2 | import { pathExistsSync, readFileSync } from 'fs-extra'; |
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:DarkMode'); |
5 | // const debug = require('debug')('Ferdium:DarkMode'); | ||
6 | 5 | ||
7 | const chars = [...'abcdefghijklmnopqrstuvwxyz']; | 6 | const chars = [...'abcdefghijklmnopqrstuvwxyz']; |
8 | 7 | ||
@@ -27,7 +26,7 @@ export function injectDarkModeStyle(recipePath: string) { | |||
27 | 26 | ||
28 | document.querySelector('head')?.appendChild(styles); | 27 | document.querySelector('head')?.appendChild(styles); |
29 | 28 | ||
30 | console.log('Injected Dark Mode style with ID', ID); | 29 | debug('Injected Dark Mode style with ID', ID); |
31 | } | 30 | } |
32 | } | 31 | } |
33 | 32 | ||
@@ -37,7 +36,7 @@ export function removeDarkModeStyle() { | |||
37 | if (style) { | 36 | if (style) { |
38 | style.remove(); | 37 | style.remove(); |
39 | 38 | ||
40 | console.log('Removed Dark Mode Style with ID', ID); | 39 | debug('Removed Dark Mode Style with ID', ID); |
41 | } | 40 | } |
42 | } | 41 | } |
43 | 42 | ||