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/download.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/download.ts')
-rw-r--r-- | src/electron/ipc-api/download.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/electron/ipc-api/download.ts b/src/electron/ipc-api/download.ts index 3631e8fee..21af0d045 100644 --- a/src/electron/ipc-api/download.ts +++ b/src/electron/ipc-api/download.ts | |||
@@ -4,8 +4,7 @@ import mime from 'mime-types'; | |||
4 | import { writeFileSync } from 'fs-extra'; | 4 | import { writeFileSync } from 'fs-extra'; |
5 | import { PathLike } from 'fs'; | 5 | import { PathLike } from 'fs'; |
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:ipcApi:download'); |
8 | // const debug = require('debug')('Ferdium:ipcApi:download'); | ||
9 | 8 | ||
10 | function decodeBase64Image(dataString: string) { | 9 | function decodeBase64Image(dataString: string) { |
11 | const matches = dataString.match(/^data:([+/A-Za-z-]+);base64,(.+)$/); | 10 | const matches = dataString.match(/^data:([+/A-Za-z-]+);base64,(.+)$/); |
@@ -28,7 +27,7 @@ export default (params: { mainWindow: BrowserWindow }) => { | |||
28 | const dl = await download(win!, url, { | 27 | const dl = await download(win!, url, { |
29 | saveAs: true, | 28 | saveAs: true, |
30 | }); | 29 | }); |
31 | console.log('File saved to', dl.savePath); | 30 | debug('File saved to', dl.savePath); |
32 | } else { | 31 | } else { |
33 | const extension = mime.extension(fileOptions.mime); | 32 | const extension = mime.extension(fileOptions.mime); |
34 | const filename = `${fileOptions.name}.${extension}`; | 33 | const filename = `${fileOptions.name}.${extension}`; |
@@ -47,7 +46,7 @@ export default (params: { mainWindow: BrowserWindow }) => { | |||
47 | 'binary', | 46 | 'binary', |
48 | ); | 47 | ); |
49 | 48 | ||
50 | console.log('File blob saved to', saveDialog.filePath); | 49 | debug('File blob saved to', saveDialog.filePath); |
51 | } catch (error) { | 50 | } catch (error) { |
52 | console.error(error); | 51 | console.error(error); |
53 | } | 52 | } |