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/SettingsStore.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/stores/SettingsStore.js') diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 3ba791239..6b6b77454 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -11,8 +11,7 @@ import { hash } from '../helpers/password-helpers'; import Request from './lib/Request'; import Store from './lib/Store'; -// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed -// const debug = require('debug')('Ferdium:SettingsStore'); +const debug = require('../preload-safe-debug')('Ferdium:SettingsStore'); export default class SettingsStore extends Store { @observable updateAppSettingsRequest = new Request( @@ -95,7 +94,7 @@ export default class SettingsStore extends Store { } }); } - console.log('Get appSettings resolves', resp.type, resp.data); + debug('Get appSettings resolves', resp.type, resp.data); Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); this.loaded = true; ipcRenderer.send('initialAppSettings', resp); @@ -147,10 +146,10 @@ export default class SettingsStore extends Store { @action async _update({ type, data }) { const appSettings = this.all; if (!this.fileSystemSettingsTypes.includes(type)) { - console.log('Update settings', type, data, this.all); + debug('Update settings', type, data, this.all); localStorage.setItem(type, Object.assign(appSettings[type], data)); } else { - console.log('Update settings on file system', type, data); + debug('Update settings on file system', type, data); ipcRenderer.send('updateAppSettings', { type, data, @@ -201,7 +200,7 @@ export default class SettingsStore extends Store { }); } - console.log('Migrated updates settings'); + debug('Migrated updates settings'); }); this._ensureMigrationAndMarkDone('5.6.0-beta.6-settings', () => { -- cgit v1.2.3-70-g09d2