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/electron/ipc-api/sessionStorage.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/electron/ipc-api/sessionStorage.ts')
-rw-r--r-- | src/electron/ipc-api/sessionStorage.ts | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/electron/ipc-api/sessionStorage.ts b/src/electron/ipc-api/sessionStorage.ts index 96acacd12..2a9f4b4d1 100644 --- a/src/electron/ipc-api/sessionStorage.ts +++ b/src/electron/ipc-api/sessionStorage.ts | |||
@@ -2,8 +2,7 @@ import { ipcMain, Session, session } from 'electron'; | |||
2 | 2 | ||
3 | import { TODOS_PARTITION_ID } from '../../config'; | 3 | import { TODOS_PARTITION_ID } from '../../config'; |
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:ipcApi:sessionStorage'); |
6 | // const debug = require('debug')('Ferdium:ipcApi:sessionStorage'); | ||
7 | 6 | ||
8 | function deduceSession(serviceId: string | undefined | null): Session { | 7 | function deduceSession(serviceId: string | undefined | null): Session { |
9 | if (serviceId) { | 8 | if (serviceId) { |
@@ -22,14 +21,14 @@ export default async () => { | |||
22 | const serviceSession = deduceSession(serviceId); | 21 | const serviceSession = deduceSession(serviceId); |
23 | serviceSession.flushStorageData(); | 22 | serviceSession.flushStorageData(); |
24 | if (targetsToClear) { | 23 | if (targetsToClear) { |
25 | console.log('Clearing targets:', targetsToClear); | 24 | debug('Clearing targets:', targetsToClear); |
26 | serviceSession.clearStorageData(targetsToClear); | 25 | serviceSession.clearStorageData(targetsToClear); |
27 | } else { | 26 | } else { |
28 | console.log('Clearing all targets'); | 27 | debug('Clearing all targets'); |
29 | serviceSession.clearStorageData(); | 28 | serviceSession.clearStorageData(); |
30 | } | 29 | } |
31 | } catch (error) { | 30 | } catch (error) { |
32 | console.log(error); | 31 | debug(error); |
33 | } | 32 | } |
34 | }); | 33 | }); |
35 | 34 | ||