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/workspaces/store.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/features/workspaces/store.js') diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index d2ccfeccf..20d32df67 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js @@ -15,8 +15,7 @@ import { createActionBindings } from '../utils/ActionBinding'; import { KEEP_WS_LOADED_USID } from '../../config'; -// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed -// const debug = require('debug')('Ferdium:feature:workspaces:store'); +const debug = require('../../preload-safe-debug')('Ferdium:feature:workspaces:store'); export default class WorkspacesStore extends FeatureStore { @observable isFeatureActive = false; @@ -70,7 +69,7 @@ export default class WorkspacesStore extends FeatureStore { // ========== PUBLIC API ========= // @action start(stores, actions) { - console.log('WorkspacesStore::start'); + debug('WorkspacesStore::start'); this.stores = stores; this.actions = actions; @@ -116,7 +115,7 @@ export default class WorkspacesStore extends FeatureStore { @action stop() { super.stop(); - console.log('WorkspacesStore::stop'); + debug('WorkspacesStore::stop'); this.reset(); this.isFeatureActive = false; } @@ -274,7 +273,7 @@ export default class WorkspacesStore extends FeatureStore { }; _activateLastUsedWorkspaceReaction = () => { - console.log('_activateLastUsedWorkspaceReaction'); + debug('_activateLastUsedWorkspaceReaction'); if (!this.activeWorkspace && this.userHasWorkspaces) { const { lastActiveWorkspace } = this.settings; if (lastActiveWorkspace) { -- cgit v1.2.3-70-g09d2