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/features/basicAuth/index.ts | 2 +- src/features/basicAuth/mainIpcHandler.ts | 2 +- src/features/basicAuth/store.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/features/basicAuth') diff --git a/src/features/basicAuth/index.ts b/src/features/basicAuth/index.ts index dd02a3bdc..ae698cba8 100644 --- a/src/features/basicAuth/index.ts +++ b/src/features/basicAuth/index.ts @@ -2,7 +2,7 @@ import { AuthInfo, BrowserWindow, ipcRenderer } from 'electron'; import { state as ModalState } from './store'; -const debug = require('debug')('Ferdium:feature:basicAuth'); +const debug = require('../../preload-safe-debug')('Ferdium:feature:basicAuth'); const state = ModalState; diff --git a/src/features/basicAuth/mainIpcHandler.ts b/src/features/basicAuth/mainIpcHandler.ts index 2f78b1497..5d320df5c 100644 --- a/src/features/basicAuth/mainIpcHandler.ts +++ b/src/features/basicAuth/mainIpcHandler.ts @@ -1,6 +1,6 @@ import { BrowserWindow } from 'electron'; -const debug = require('debug')('Ferdium:feature:basicAuth:main'); +const debug = require('../../preload-safe-debug')('Ferdium:feature:basicAuth:main'); export default function mainIpcHandler(mainWindow: BrowserWindow, authInfo) { debug('Sending basic auth call', authInfo); diff --git a/src/features/basicAuth/store.ts b/src/features/basicAuth/store.ts index 4b71d32fd..e0ae8ba17 100644 --- a/src/features/basicAuth/store.ts +++ b/src/features/basicAuth/store.ts @@ -1,7 +1,7 @@ import { observable } from 'mobx'; import { ipcRenderer } from 'electron'; -const debug = require('debug')('Ferdium:feature:basicAuth'); +const debug = require('../../preload-safe-debug')('Ferdium:feature:basicAuth'); const defaultState = { isModalVisible: true, -- cgit v1.2.3-70-g09d2