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/api/server/LocalApi.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/api/server/LocalApi.ts')
-rw-r--r-- | src/api/server/LocalApi.ts | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/api/server/LocalApi.ts b/src/api/server/LocalApi.ts index 28028bf80..a292bc42d 100644 --- a/src/api/server/LocalApi.ts +++ b/src/api/server/LocalApi.ts | |||
@@ -4,15 +4,14 @@ import fastFolderSize from 'fast-folder-size'; | |||
4 | 4 | ||
5 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers'; | 5 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers'; |
6 | 6 | ||
7 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed | 7 | const debug = require('../../preload-safe-debug')('Ferdium:LocalApi'); |
8 | // const debug = require('debug')('Ferdium:LocalApi'); | ||
9 | 8 | ||
10 | export default class LocalApi { | 9 | export default class LocalApi { |
11 | // Settings | 10 | // Settings |
12 | getAppSettings(type: string) { | 11 | getAppSettings(type: string) { |
13 | return new Promise(resolve => { | 12 | return new Promise(resolve => { |
14 | ipcRenderer.once('appSettings', (_event, resp) => { | 13 | ipcRenderer.once('appSettings', (_event, resp) => { |
15 | console.log('LocalApi::getAppSettings resolves', resp.type, resp.data); | 14 | debug('LocalApi::getAppSettings resolves', resp.type, resp.data); |
16 | resolve(resp); | 15 | resolve(resp); |
17 | }); | 16 | }); |
18 | 17 | ||
@@ -21,7 +20,7 @@ export default class LocalApi { | |||
21 | } | 20 | } |
22 | 21 | ||
23 | async updateAppSettings(type: string, data: any) { | 22 | async updateAppSettings(type: string, data: any) { |
24 | console.log('LocalApi::updateAppSettings resolves', type, data); | 23 | debug('LocalApi::updateAppSettings resolves', type, data); |
25 | ipcRenderer.send('updateAppSettings', { | 24 | ipcRenderer.send('updateAppSettings', { |
26 | type, | 25 | type, |
27 | data, | 26 | data, |
@@ -40,7 +39,7 @@ export default class LocalApi { | |||
40 | reject(err); | 39 | reject(err); |
41 | } | 40 | } |
42 | 41 | ||
43 | console.log('LocalApi::getAppCacheSize resolves', bytes); | 42 | debug('LocalApi::getAppCacheSize resolves', bytes); |
44 | resolve(bytes); | 43 | resolve(bytes); |
45 | }, | 44 | }, |
46 | ); | 45 | ); |