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/helpers/url-helpers.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/helpers/url-helpers.ts')
-rw-r--r-- | src/helpers/url-helpers.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts index abe123577..ddbf4b4f7 100644 --- a/src/helpers/url-helpers.ts +++ b/src/helpers/url-helpers.ts | |||
@@ -6,8 +6,7 @@ import { shell } from 'electron'; | |||
6 | 6 | ||
7 | import { ALLOWED_PROTOCOLS } from '../config'; | 7 | import { ALLOWED_PROTOCOLS } from '../config'; |
8 | 8 | ||
9 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed | 9 | const debug = require('../preload-safe-debug')('Ferdium:Helpers:url'); |
10 | // const debug = require('debug')('Ferdium:Helpers:url'); | ||
11 | 10 | ||
12 | export function isValidExternalURL(url: string | URL) { | 11 | export function isValidExternalURL(url: string | URL) { |
13 | let parsedUrl: URL; | 12 | let parsedUrl: URL; |
@@ -19,7 +18,7 @@ export function isValidExternalURL(url: string | URL) { | |||
19 | 18 | ||
20 | const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); | 19 | const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); |
21 | 20 | ||
22 | console.log('protocol check is', isAllowed, 'for:', url); | 21 | debug('protocol check is', isAllowed, 'for:', url); |
23 | 22 | ||
24 | return isAllowed; | 23 | return isAllowed; |
25 | } | 24 | } |
@@ -38,7 +37,7 @@ export function openExternalUrl( | |||
38 | url: string | URL, | 37 | url: string | URL, |
39 | skipValidityCheck: boolean = false, | 38 | skipValidityCheck: boolean = false, |
40 | ) { | 39 | ) { |
41 | console.log('Open url:', url, 'with skipValidityCheck:', skipValidityCheck); | 40 | debug('Open url:', url, 'with skipValidityCheck:', skipValidityCheck); |
42 | if (skipValidityCheck || isValidExternalURL(url)) { | 41 | if (skipValidityCheck || isValidExternalURL(url)) { |
43 | shell.openExternal(url.toString()); | 42 | shell.openExternal(url.toString()); |
44 | } | 43 | } |