From 759d93dc198a3cc8c5265245c0144efa5435682b Mon Sep 17 00:00:00 2001 From: Vijay Aravamudhan Date: Fri, 22 Apr 2022 15:04:21 -0500 Subject: Turn off usage of 'debug' npm package using with electron-16 (fixes #17) --- src/stores/AppStore.js | 37 +++++++++++++++--------------- src/stores/RecipesStore.js | 11 ++++----- src/stores/RequestStore.js | 5 +++-- src/stores/ServicesStore.js | 55 +++++++++++++++++++++++---------------------- src/stores/SettingsStore.js | 11 ++++----- src/stores/UserStore.js | 5 +++-- 6 files changed, 65 insertions(+), 59 deletions(-) (limited to 'src/stores') diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 68796b692..55cdce5f2 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -29,7 +29,8 @@ import { import { openExternalUrl } from '../helpers/url-helpers'; import { sleep } from '../helpers/async-helpers'; -const debug = require('debug')('Ferdium:AppStore'); +// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed +// const debug = require('debug')('Ferdium:AppStore'); const mainWindow = getCurrentWindow(); @@ -195,7 +196,7 @@ export default class AppStore extends Store { // Handle deep linking (ferdium://) ipcRenderer.on('navigateFromDeepLink', (event, data) => { - debug('Navigate from deep link', data); + console.log('Navigate from deep link', data); let { url } = data; if (!url) return; @@ -217,28 +218,28 @@ export default class AppStore extends Store { this.isSystemDarkModeEnabled = nativeTheme.shouldUseDarkColors; ipcRenderer.on('isWindowFocused', (event, isFocused) => { - debug('Setting is focused to', isFocused); + console.log('Setting is focused to', isFocused); this.isFocused = isFocused; }); powerMonitor.on('suspend', () => { - debug('System suspended starting timer'); + console.log('System suspended starting timer'); this.timeSuspensionStart = moment(); }); powerMonitor.on('resume', () => { - debug('System resumed, last suspended on', this.timeSuspensionStart); + console.log('System resumed, last suspended on', this.timeSuspensionStart); this.actions.service.resetLastPollTimer(); if ( this.timeSuspensionStart.add(10, 'm').isBefore(moment()) && this.stores.settings.app.get('reloadAfterResume') ) { - debug('Reloading services, user info and features'); + console.log('Reloading services, user info and features'); setInterval(() => { - debug('Reload app interval is starting'); + console.log('Reload app interval is starting'); if (this.isOnline) { window.location.reload(); } @@ -250,7 +251,7 @@ export default class AppStore extends Store { // notifications got stuck after upgrade but forcing a notification // via `new Notification` triggered the permission request if (isMac && !localStorage.getItem(CATALINA_NOTIFICATION_HACK_KEY)) { - debug('Triggering macOS Catalina notification permission trigger'); + console.log('Triggering macOS Catalina notification permission trigger'); // eslint-disable-next-line no-new new window.Notification('Welcome to Ferdium 5', { body: 'Have a wonderful day & happy messaging.', @@ -319,7 +320,7 @@ export default class AppStore extends Store { const notification = new window.Notification(title, options); - debug('New notification', title, options); + console.log('New notification', title, options); notification.addEventListener('click', () => { if (serviceId) { @@ -341,7 +342,7 @@ export default class AppStore extends Store { } mainWindow.focus(); - debug('Notification click handler'); + console.log('Notification click handler'); } }); } @@ -370,10 +371,10 @@ export default class AppStore extends Store { try { if (enable) { - debug('enabling launch on startup', executablePath); + console.log('enabling launch on startup', executablePath); autoLauncher.enable(); } else { - debug('disabling launch on startup'); + console.log('disabling launch on startup'); autoLauncher.disable(); } } catch (error) { @@ -388,7 +389,7 @@ export default class AppStore extends Store { @action _checkForUpdates() { if (this.isOnline && this.stores.settings.app.automaticUpdates && (isMac || isWindows || process.env.APPIMAGE)) { - debug('_checkForUpdates: sending event to autoUpdate:check'); + console.log('_checkForUpdates: sending event to autoUpdate:check'); this.updateStatus = this.updateStatusTypes.CHECKING; ipcRenderer.send('autoUpdate', { action: 'check', @@ -401,7 +402,7 @@ export default class AppStore extends Store { } @action _installUpdate() { - debug('_installUpdate: sending event to autoUpdate:install'); + console.log('_installUpdate: sending event to autoUpdate:install'); ipcRenderer.send('autoUpdate', { action: 'install', }); @@ -487,7 +488,7 @@ export default class AppStore extends Store { } moment.locale(this.locale); - debug(`Set locale to "${this.locale}"`); + console.log(`Set locale to "${this.locale}"`); } _getDefaultLocale() { @@ -541,7 +542,7 @@ export default class AppStore extends Store { this.autoLaunchOnStart = await this._checkAutoStart(); if (this.stores.settings.all.stats.appStarts === 1) { - debug('Set app to launch on start'); + console.log('Set app to launch on start'); this.actions.app.launchOnStartup({ enable: true, }); @@ -553,9 +554,9 @@ export default class AppStore extends Store { } async _systemDND() { - debug('Checking if Do Not Disturb Mode is on'); + console.log('Checking if Do Not Disturb Mode is on'); const dnd = await ipcRenderer.invoke('get-dnd'); - debug('Do not disturb mode is', dnd); + console.log('Do not disturb mode is', dnd); if ( dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js index 0a3db2488..d39b87401 100644 --- a/src/stores/RecipesStore.js +++ b/src/stores/RecipesStore.js @@ -8,7 +8,8 @@ import Request from './lib/Request'; import { matchRoute } from '../helpers/routing-helpers'; import { asarRecipesPath } from '../helpers/asar-helpers'; -const debug = require('debug')('Ferdium:RecipeStore'); +// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed +// const debug = require('debug')('Ferdium:RecipeStore'); export default class RecipesStore extends Store { @observable allRecipesRequest = new CachedRequest(this.api.recipes, 'all'); @@ -47,7 +48,7 @@ export default class RecipesStore extends Store { return activeRecipe; } - debug(`Recipe ${match.id} not installed`); + console.log(`Recipe ${match.id} not installed`); } return null; @@ -78,7 +79,7 @@ export default class RecipesStore extends Store { const recipes = {}; // Hackfix, reference this.all to fetch services - debug(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); + console.log(`Check Recipe updates for ${this.all.map(recipe => recipe.id)}`); for (const r of recipeIds) { const recipe = this.one(r); @@ -107,7 +108,7 @@ export default class RecipesStore extends Store { } const updates = [...remoteUpdates, ...localUpdates]; - debug( + console.log( 'Got update information (local, remote):', localUpdates, remoteUpdates, @@ -145,7 +146,7 @@ export default class RecipesStore extends Store { if (!this.stores.recipes.isInstalled(recipeId)) { router.push('/settings/recipes'); - debug(`Recipe ${recipeId} is not installed, trying to install it`); + console.log(`Recipe ${recipeId} is not installed, trying to install it`); const recipe = await this.installRecipeRequest.execute(recipeId) ._promise; diff --git a/src/stores/RequestStore.js b/src/stores/RequestStore.js index 2e76a7023..a6991409c 100644 --- a/src/stores/RequestStore.js +++ b/src/stores/RequestStore.js @@ -4,7 +4,8 @@ import ms from 'ms'; import Store from './lib/Store'; -const debug = require('debug')('Ferdium:RequestsStore'); +// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed +// const debug = require('debug')('Ferdium:RequestsStore'); export default class RequestStore extends Store { @observable userInfoRequest; @@ -65,7 +66,7 @@ export default class RequestStore extends Store { } this._autoRetry(); - debug(`Retry required requests delayed in ${delay / 1000}s`); + console.log(`Retry required requests delayed in ${delay / 1000}s`); }, delay); } } diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 1c800df59..3847536ca 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js @@ -19,7 +19,8 @@ import { DEFAULT_SERVICE_SETTINGS, KEEP_WS_LOADED_USID } from '../config'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; import { ferdiumVersion } from '../environment-remote'; -const debug = require('debug')('Ferdium:ServiceStore'); +// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed +// const debug = require('debug')('Ferdium:ServiceStore'); export default class ServicesStore extends Store { @observable allServicesRequest = new CachedRequest(this.api.services, 'all'); @@ -212,7 +213,7 @@ export default class ServicesStore extends Store { serviceMaintenanceTick = debounce(() => { this._serviceMaintenance(); this.serviceMaintenanceTick(); - debug('Service maintenance tick'); + console.log('Service maintenance tick'); }, ms('10s')); /** @@ -250,7 +251,7 @@ export default class ServicesStore extends Store { // If service did not reply for more than 1m try to reload. if (!service.isActive) { if (this.stores.app.isOnline && service.lostRecipeReloadAttempt < 3) { - debug( + console.log( `Reloading service: ${service.name} (${service.id}). Attempt: ${service.lostRecipeReloadAttempt}`, ); // service.webview.reload(); @@ -259,7 +260,7 @@ export default class ServicesStore extends Store { service.lostRecipeConnection = false; } } else { - debug(`Service lost connection: ${service.name} (${service.id}).`); + console.log(`Service lost connection: ${service.name} (${service.id}).`); service.lostRecipeConnection = true; } } else { @@ -363,7 +364,7 @@ export default class ServicesStore extends Store { return activeService; } - debug('Service not available'); + console.log('Service not available'); } return null; @@ -397,9 +398,9 @@ export default class ServicesStore extends Store { skipCleanup = false, }) { if (!this.stores.recipes.isInstalled(recipeId)) { - debug(`Recipe "${recipeId}" is not installed, installing recipe`); + console.log(`Recipe "${recipeId}" is not installed, installing recipe`); await this.stores.recipes._install({ recipeId }); - debug(`Recipe "${recipeId}" installed`); + console.log(`Recipe "${recipeId}" installed`); } // set default values for serviceData @@ -616,7 +617,7 @@ export default class ServicesStore extends Store { if (service) { service.isActive = false; } else { - debug('No service is active'); + console.log('No service is active'); } } @@ -659,7 +660,7 @@ export default class ServicesStore extends Store { service.webview = webview; if (!service.isAttached) { - debug('Webview is not attached, initializing'); + console.log('Webview is not attached, initializing'); service.initializeWebViewEvents({ handleIPCMessage: this.actions.service.handleIPCMessage, openWindow: this.actions.service.openWindow, @@ -708,7 +709,7 @@ export default class ServicesStore extends Store { } } } else { - debug('No service is active'); + console.log('No service is active'); } } else { this.allServicesRequest.invalidate(); @@ -727,7 +728,7 @@ export default class ServicesStore extends Store { // eslint-disable-next-line default-case switch (channel) { case 'hello': { - debug('Received hello event from', serviceId); + console.log('Received hello event from', serviceId); this._initRecipePolling(service.id); this._initializeServiceRecipeInWebview(serviceId); @@ -741,7 +742,7 @@ export default class ServicesStore extends Store { break; } case 'message-counts': { - debug(`Received unread message info from '${serviceId}'`, args[0]); + console.log(`Received unread message info from '${serviceId}'`, args[0]); this.actions.service.setUnreadMessageCount({ serviceId, @@ -754,7 +755,7 @@ export default class ServicesStore extends Store { break; } case 'active-dialog-title': { - debug(`Received active dialog title from '${serviceId}'`, args[0]); + console.log(`Received active dialog title from '${serviceId}'`, args[0]); this.actions.service.setDialogTitle({ serviceId, @@ -919,7 +920,7 @@ export default class ServicesStore extends Store { serviceId: service.id, }); } else { - debug('No service is active'); + console.log('No service is active'); } } @@ -1027,7 +1028,7 @@ export default class ServicesStore extends Store { if (service) { this._openDevTools({ serviceId: service.id }); } else { - debug('No service is active'); + console.log('No service is active'); } } @@ -1037,7 +1038,7 @@ export default class ServicesStore extends Store { return; } - debug(`Hibernate ${service.name}`); + console.log(`Hibernate ${service.name}`); service.isHibernationRequested = true; service.lastHibernated = Date.now(); @@ -1047,7 +1048,7 @@ export default class ServicesStore extends Store { const now = Date.now(); const service = this.one(serviceId); const automaticTag = automatic ? ' automatically ' : ' '; - debug( + console.log( `Waking up${automaticTag}from service hibernation for ${service.name}`, ); @@ -1068,8 +1069,8 @@ export default class ServicesStore extends Store { // const mainStrategy = this.stores.settings.all.app.hibernationStrategy; let strategy = this.stores.settings.all.app.wakeUpHibernationStrategy; - debug(`wakeUpHibernationStrategy = ${strategy}`); - debug(`hibernationStrategy = ${mainStrategy}`); + console.log(`wakeUpHibernationStrategy = ${strategy}`); + console.log(`hibernationStrategy = ${mainStrategy}`); if (!strategy || strategy < 1) { strategy = this.stores.settings.all.app.hibernationStrategy; } @@ -1081,16 +1082,16 @@ export default class ServicesStore extends Store { ) { // Add 10 additional seconds 50% of the time. splay = 10; - debug('Added splay'); + console.log('Added splay'); } else { - debug('skipping splay'); + console.log('skipping splay'); } // wake up again in strategy + splay seconds instead of mainStrategy seconds. service.lastUsed = now - ms(`${mainStrategy - (strategy + splay)}s`); } else { service.lastUsed = now; } - debug( + console.log( `Setting service.lastUsed to ${service.lastUsed} (${ (now - service.lastUsed) / 1000 }s ago)`, @@ -1100,7 +1101,7 @@ export default class ServicesStore extends Store { } @action _resetLastPollTimer({ serviceId = null }) { - debug( + console.log( `Reset last poll timer for ${ serviceId ? `service: "${serviceId}"` : 'all services' }`, @@ -1131,7 +1132,7 @@ export default class ServicesStore extends Store { service.dialogTitle ? ` - ${service.dialogTitle}` : '' } ${service._webview ? `- ${service._webview.getTitle()}` : ''}`; } else { - debug('No service is active'); + console.log('No service is active'); } } @@ -1145,7 +1146,7 @@ export default class ServicesStore extends Store { }, }); } else { - debug('No service is active'); + console.log('No service is active'); } } @@ -1261,7 +1262,7 @@ export default class ServicesStore extends Store { this.allDisplayed.findIndex(service => service.isActive) === -1 && this.allDisplayed.length > 0 ) { - debug('No active service found, setting active service to index 0'); + console.log('No active service found, setting active service to index 0'); this._setActive({ serviceId: this.allDisplayed[0].id }); } @@ -1277,7 +1278,7 @@ export default class ServicesStore extends Store { JSON.stringify(service.shareWithWebview), ); - debug('Initialize recipe', service.recipe.id, service.name); + console.log('Initialize recipe', service.recipe.id, service.name); service.webview.send( 'initialize-recipe', { diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index cfd73c705..3ba791239 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js @@ -11,7 +11,8 @@ import { hash } from '../helpers/password-helpers'; import Request from './lib/Request'; import Store from './lib/Store'; -const debug = require('debug')('Ferdium:SettingsStore'); +// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed +// const debug = require('debug')('Ferdium:SettingsStore'); export default class SettingsStore extends Store { @observable updateAppSettingsRequest = new Request( @@ -94,7 +95,7 @@ export default class SettingsStore extends Store { } }); } - debug('Get appSettings resolves', resp.type, resp.data); + console.log('Get appSettings resolves', resp.type, resp.data); Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); this.loaded = true; ipcRenderer.send('initialAppSettings', resp); @@ -146,10 +147,10 @@ export default class SettingsStore extends Store { @action async _update({ type, data }) { const appSettings = this.all; if (!this.fileSystemSettingsTypes.includes(type)) { - debug('Update settings', type, data, this.all); + console.log('Update settings', type, data, this.all); localStorage.setItem(type, Object.assign(appSettings[type], data)); } else { - debug('Update settings on file system', type, data); + console.log('Update settings on file system', type, data); ipcRenderer.send('updateAppSettings', { type, data, @@ -200,7 +201,7 @@ export default class SettingsStore extends Store { }); } - debug('Migrated updates settings'); + console.log('Migrated updates settings'); }); this._ensureMigrationAndMarkDone('5.6.0-beta.6-settings', () => { diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 787ffbb56..8c413a065 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js @@ -10,7 +10,8 @@ import Store from './lib/Store'; import Request from './lib/Request'; import CachedRequest from './lib/CachedRequest'; -const debug = require('debug')('Ferdium:UserStore'); +// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed +// const debug = require('debug')('Ferdium:UserStore'); // TODO: split stores into UserStore and AuthStore export default class UserStore extends Store { @@ -394,7 +395,7 @@ export default class UserStore extends Store { } if (!this.data.locale) { - debug('Migrate "locale" to user data'); + console.log('Migrate "locale" to user data'); this.actions.user.update({ userData: { locale: this.stores.app.locale, -- cgit v1.2.3-54-g00ecf