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/webview/darkmode.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/webview/darkmode.ts') 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 @@ import { join } from 'path'; import { pathExistsSync, readFileSync } from 'fs-extra'; -// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed -// const debug = require('debug')('Ferdium:DarkMode'); +const debug = require('../preload-safe-debug')('Ferdium:DarkMode'); const chars = [...'abcdefghijklmnopqrstuvwxyz']; @@ -27,7 +26,7 @@ export function injectDarkModeStyle(recipePath: string) { document.querySelector('head')?.appendChild(styles); - console.log('Injected Dark Mode style with ID', ID); + debug('Injected Dark Mode style with ID', ID); } } @@ -37,7 +36,7 @@ export function removeDarkModeStyle() { if (style) { style.remove(); - console.log('Removed Dark Mode Style with ID', ID); + debug('Removed Dark Mode Style with ID', ID); } } -- cgit v1.2.3-70-g09d2