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/spellchecker.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/webview/spellchecker.ts') diff --git a/src/webview/spellchecker.ts b/src/webview/spellchecker.ts index 8cf16a7ba..8e452c791 100644 --- a/src/webview/spellchecker.ts +++ b/src/webview/spellchecker.ts @@ -2,8 +2,7 @@ import { ipcRenderer } from 'electron'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; import { isMac } from '../environment'; -// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed -// const debug = require('debug')('Ferdium:spellchecker'); +const debug = require('../preload-safe-debug')('Ferdium:spellchecker'); export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { const locales = Object.keys(SPELLCHECKER_LOCALES).filter( @@ -17,14 +16,14 @@ export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { export function switchDict(fuzzyLocale: string, serviceId: string) { if (isMac) { - console.log('Ignoring dictionary changes on macOS'); + debug('Ignoring dictionary changes on macOS'); return; } - console.log(`Setting spellchecker locale from: ${fuzzyLocale}`); + debug(`Setting spellchecker locale from: ${fuzzyLocale}`); const locale = getSpellcheckerLocaleByFuzzyIdentifier(fuzzyLocale); if (locale) { - console.log(`Sending spellcheck locales to host: ${locale}`); + debug(`Sending spellcheck locales to host: ${locale}`); ipcRenderer.send('set-spellchecker-locales', { locale, serviceId }); } } -- cgit v1.2.3-70-g09d2