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/sessionHandler.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/sessionHandler.ts')
-rw-r--r-- | src/webview/sessionHandler.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/webview/sessionHandler.ts b/src/webview/sessionHandler.ts index a2906113d..00eacdf50 100644 --- a/src/webview/sessionHandler.ts +++ b/src/webview/sessionHandler.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed | 1 | const debug = require('../preload-safe-debug')('Ferdium:Plugin:SessionHandler'); |
2 | // const debug = require('debug')('Ferdium:Plugin:SessionHandler'); | ||
3 | 2 | ||
4 | export class SessionHandler { | 3 | export class SessionHandler { |
5 | async releaseServiceWorkers() { | 4 | async releaseServiceWorkers() { |
@@ -8,10 +7,10 @@ export class SessionHandler { | |||
8 | await window.navigator.serviceWorker.getRegistrations(); | 7 | await window.navigator.serviceWorker.getRegistrations(); |
9 | for (const registration of registrations) { | 8 | for (const registration of registrations) { |
10 | registration.unregister(); | 9 | registration.unregister(); |
11 | console.log('ServiceWorker unregistered'); | 10 | debug('ServiceWorker unregistered'); |
12 | } | 11 | } |
13 | } catch (error) { | 12 | } catch (error) { |
14 | console.log(error); | 13 | debug(error); |
15 | } | 14 | } |
16 | } | 15 | } |
17 | } | 16 | } |