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/stores/RecipesStore.js | |
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/stores/RecipesStore.js')
-rw-r--r-- | src/stores/RecipesStore.js | 11 |
1 files changed, 5 insertions, 6 deletions
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'; | |||
8 | import { matchRoute } from '../helpers/routing-helpers'; | 8 | import { matchRoute } from '../helpers/routing-helpers'; |
9 | import { asarRecipesPath } from '../helpers/asar-helpers'; | 9 | import { asarRecipesPath } from '../helpers/asar-helpers'; |
10 | 10 | ||
11 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed | 11 | const debug = require('../preload-safe-debug')('Ferdium:RecipeStore'); |
12 | // const debug = require('debug')('Ferdium:RecipeStore'); | ||
13 | 12 | ||
14 | export default class RecipesStore extends Store { | 13 | export default class RecipesStore extends Store { |
15 | @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); | 14 | @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); |
@@ -48,7 +47,7 @@ export default class RecipesStore extends Store { | |||
48 | return activeRecipe; | 47 | return activeRecipe; |
49 | } | 48 | } |
50 | 49 | ||
51 | console.log(`Recipe ${match.id} not installed`); | 50 | debug(`Recipe ${match.id} not installed`); |
52 | } | 51 | } |
53 | 52 | ||
54 | return null; | 53 | return null; |
@@ -79,7 +78,7 @@ export default class RecipesStore extends Store { | |||
79 | const recipes = {}; | 78 | const recipes = {}; |
80 | 79 | ||
81 | // Hackfix, reference this.all to fetch services | 80 | // Hackfix, reference this.all to fetch services |
82 | console.log(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); | 81 | debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); |
83 | 82 | ||
84 | for (const r of recipeIds) { | 83 | for (const r of recipeIds) { |
85 | const recipe = this.one(r); | 84 | const recipe = this.one(r); |
@@ -108,7 +107,7 @@ export default class RecipesStore extends Store { | |||
108 | } | 107 | } |
109 | 108 | ||
110 | const updates = [...remoteUpdates, ...localUpdates]; | 109 | const updates = [...remoteUpdates, ...localUpdates]; |
111 | console.log( | 110 | debug( |
112 | 'Got update information (local, remote):', | 111 | 'Got update information (local, remote):', |
113 | localUpdates, | 112 | localUpdates, |
114 | remoteUpdates, | 113 | remoteUpdates, |
@@ -146,7 +145,7 @@ export default class RecipesStore extends Store { | |||
146 | 145 | ||
147 | if (!this.stores.recipes.isInstalled(recipeId)) { | 146 | if (!this.stores.recipes.isInstalled(recipeId)) { |
148 | router.push('/settings/recipes'); | 147 | router.push('/settings/recipes'); |
149 | console.log(`Recipe ${recipeId} is not installed, trying to install it`); | 148 | debug(`Recipe ${recipeId} is not installed, trying to install it`); |
150 | 149 | ||
151 | const recipe = await this.installRecipeRequest.execute(recipeId) | 150 | const recipe = await this.installRecipeRequest.execute(recipeId) |
152 | ._promise; | 151 | ._promise; |