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/spellchecker.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/spellchecker.ts')
-rw-r--r-- | src/webview/spellchecker.ts | 9 |
1 files changed, 4 insertions, 5 deletions
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'; | |||
2 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 2 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
3 | import { isMac } from '../environment'; | 3 | import { isMac } from '../environment'; |
4 | 4 | ||
5 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed | 5 | const debug = require('../preload-safe-debug')('Ferdium:spellchecker'); |
6 | // const debug = require('debug')('Ferdium:spellchecker'); | ||
7 | 6 | ||
8 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { | 7 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { |
9 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter( | 8 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter( |
@@ -17,14 +16,14 @@ export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { | |||
17 | 16 | ||
18 | export function switchDict(fuzzyLocale: string, serviceId: string) { | 17 | export function switchDict(fuzzyLocale: string, serviceId: string) { |
19 | if (isMac) { | 18 | if (isMac) { |
20 | console.log('Ignoring dictionary changes on macOS'); | 19 | debug('Ignoring dictionary changes on macOS'); |
21 | return; | 20 | return; |
22 | } | 21 | } |
23 | 22 | ||
24 | console.log(`Setting spellchecker locale from: ${fuzzyLocale}`); | 23 | debug(`Setting spellchecker locale from: ${fuzzyLocale}`); |
25 | const locale = getSpellcheckerLocaleByFuzzyIdentifier(fuzzyLocale); | 24 | const locale = getSpellcheckerLocaleByFuzzyIdentifier(fuzzyLocale); |
26 | if (locale) { | 25 | if (locale) { |
27 | console.log(`Sending spellcheck locales to host: ${locale}`); | 26 | debug(`Sending spellcheck locales to host: ${locale}`); |
28 | ipcRenderer.send('set-spellchecker-locales', { locale, serviceId }); | 27 | ipcRenderer.send('set-spellchecker-locales', { locale, serviceId }); |
29 | } | 28 | } |
30 | } | 29 | } |