From d02644f7c41150709795e57bfd40351b4da35a7b Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 23 Apr 2022 01:59:21 +0200 Subject: Preload safe debug shim (#29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/api/server/LocalApi.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/api/server/LocalApi.ts') 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'; import { getServicePartitionsDirectory } from '../../helpers/service-helpers'; -// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed -// const debug = require('debug')('Ferdium:LocalApi'); +const debug = require('../../preload-safe-debug')('Ferdium:LocalApi'); export default class LocalApi { // Settings getAppSettings(type: string) { return new Promise(resolve => { ipcRenderer.once('appSettings', (_event, resp) => { - console.log('LocalApi::getAppSettings resolves', resp.type, resp.data); + debug('LocalApi::getAppSettings resolves', resp.type, resp.data); resolve(resp); }); @@ -21,7 +20,7 @@ export default class LocalApi { } async updateAppSettings(type: string, data: any) { - console.log('LocalApi::updateAppSettings resolves', type, data); + debug('LocalApi::updateAppSettings resolves', type, data); ipcRenderer.send('updateAppSettings', { type, data, @@ -40,7 +39,7 @@ export default class LocalApi { reject(err); } - console.log('LocalApi::getAppCacheSize resolves', bytes); + debug('LocalApi::getAppCacheSize resolves', bytes); resolve(bytes); }, ); -- cgit v1.2.3-54-g00ecf