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/stores/RecipesStore.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/stores/RecipesStore.js') diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index d39b87401..3d3a506cc 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js @@ -8,8 +8,7 @@ import Request from './lib/Request'; import { matchRoute } from '../helpers/routing-helpers'; import { asarRecipesPath } from '../helpers/asar-helpers'; -// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed -// const debug = require('debug')('Ferdium:RecipeStore'); +const debug = require('../preload-safe-debug')('Ferdium:RecipeStore'); export default class RecipesStore extends Store { @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); @@ -48,7 +47,7 @@ export default class RecipesStore extends Store { return activeRecipe; } - console.log(`Recipe ${match.id} not installed`); + debug(`Recipe ${match.id} not installed`); } return null; @@ -79,7 +78,7 @@ export default class RecipesStore extends Store { const recipes = {}; // Hackfix, reference this.all to fetch services - console.log(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); + debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); for (const r of recipeIds) { const recipe = this.one(r); @@ -108,7 +107,7 @@ export default class RecipesStore extends Store { } const updates = [...remoteUpdates, ...localUpdates]; - console.log( + debug( 'Got update information (local, remote):', localUpdates, remoteUpdates, @@ -146,7 +145,7 @@ export default class RecipesStore extends Store { if (!this.stores.recipes.isInstalled(recipeId)) { router.push('/settings/recipes'); - console.log(`Recipe ${recipeId} is not installed, trying to install it`); + debug(`Recipe ${recipeId} is not installed, trying to install it`); const recipe = await this.installRecipeRequest.execute(recipeId) ._promise; -- cgit v1.2.3-70-g09d2