diff options
author | 2022-04-22 15:04:21 -0500 | |
---|---|---|
committer | 2022-04-22 20:04:21 +0000 | |
commit | 759d93dc198a3cc8c5265245c0144efa5435682b (patch) | |
tree | 53e963a085d3d12af5a2efa2f1ab6f3e5574edc7 /src/webview/recipe.js | |
parent | Added build scripts for linux, macos and windows to help new contributors get... (diff) | |
download | ferdium-app-759d93dc198a3cc8c5265245c0144efa5435682b.tar.gz ferdium-app-759d93dc198a3cc8c5265245c0144efa5435682b.tar.zst ferdium-app-759d93dc198a3cc8c5265245c0144efa5435682b.zip |
Turn off usage of 'debug' npm package using with electron-16 (fixes #17)
Diffstat (limited to 'src/webview/recipe.js')
-rw-r--r-- | src/webview/recipe.js | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index 4fcf28363..1f3017ccd 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -50,7 +50,8 @@ import { | |||
50 | 50 | ||
51 | import { DEFAULT_APP_SETTINGS } from '../config'; | 51 | import { DEFAULT_APP_SETTINGS } from '../config'; |
52 | 52 | ||
53 | const debug = require('debug')('Ferdium:Plugin'); | 53 | // TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed |
54 | // const debug = require('debug')('Ferdium:Plugin'); | ||
54 | 55 | ||
55 | const badgeHandler = new BadgeHandler(); | 56 | const badgeHandler = new BadgeHandler(); |
56 | 57 | ||
@@ -64,7 +65,7 @@ const notificationsHandler = new NotificationsHandler(); | |||
64 | const originalWindowOpen = window.open; | 65 | const originalWindowOpen = window.open; |
65 | 66 | ||
66 | window.open = (url, frameName, features) => { | 67 | window.open = (url, frameName, features) => { |
67 | debug('window.open', url, frameName, features); | 68 | console.log('window.open', url, frameName, features); |
68 | if (!url) { | 69 | if (!url) { |
69 | // The service hasn't yet supplied a URL (as used in Skype). | 70 | // The service hasn't yet supplied a URL (as used in Skype). |
70 | // Return a new dummy window object and wait for the service to change the properties | 71 | // Return a new dummy window object and wait for the service to change the properties |
@@ -170,12 +171,12 @@ class RecipeController { | |||
170 | async initialize() { | 171 | async initialize() { |
171 | for (const channel of Object.keys(this.ipcEvents)) { | 172 | for (const channel of Object.keys(this.ipcEvents)) { |
172 | ipcRenderer.on(channel, (...args) => { | 173 | ipcRenderer.on(channel, (...args) => { |
173 | debug('Received IPC event for channel', channel, 'with', ...args); | 174 | console.log('Received IPC event for channel', channel, 'with', ...args); |
174 | this[this.ipcEvents[channel]](...args); | 175 | this[this.ipcEvents[channel]](...args); |
175 | }); | 176 | }); |
176 | } | 177 | } |
177 | 178 | ||
178 | debug('Send "hello" to host'); | 179 | console.log('Send "hello" to host'); |
179 | setTimeout(() => ipcRenderer.sendToHost('hello'), 100); | 180 | setTimeout(() => ipcRenderer.sendToHost('hello'), 100); |
180 | 181 | ||
181 | this.spellcheckingProvider = null; | 182 | this.spellcheckingProvider = null; |
@@ -198,9 +199,9 @@ class RecipeController { | |||
198 | } | 199 | } |
199 | 200 | ||
200 | loadRecipeModule(event, config, recipe) { | 201 | loadRecipeModule(event, config, recipe) { |
201 | debug('loadRecipeModule'); | 202 | console.log('loadRecipeModule'); |
202 | const modulePath = join(recipe.path, 'webview.js'); | 203 | const modulePath = join(recipe.path, 'webview.js'); |
203 | debug('module path', modulePath); | 204 | console.log('module path', modulePath); |
204 | // Delete module from cache | 205 | // Delete module from cache |
205 | delete require.cache[require.resolve(modulePath)]; | 206 | delete require.cache[require.resolve(modulePath)]; |
206 | try { | 207 | try { |
@@ -213,7 +214,7 @@ class RecipeController { | |||
213 | if (existsSync(modulePath)) { | 214 | if (existsSync(modulePath)) { |
214 | // eslint-disable-next-line import/no-dynamic-require | 215 | // eslint-disable-next-line import/no-dynamic-require |
215 | require(modulePath)(this.recipe, { ...config, recipe }); | 216 | require(modulePath)(this.recipe, { ...config, recipe }); |
216 | debug('Initialize Recipe', config, recipe); | 217 | console.log('Initialize Recipe', config, recipe); |
217 | } | 218 | } |
218 | 219 | ||
219 | this.settings.service = Object.assign(config, { recipe }); | 220 | this.settings.service = Object.assign(config, { recipe }); |
@@ -265,18 +266,18 @@ class RecipeController { | |||
265 | } | 266 | } |
266 | 267 | ||
267 | update() { | 268 | update() { |
268 | debug('enableSpellchecking', this.settings.app.enableSpellchecking); | 269 | console.log('enableSpellchecking', this.settings.app.enableSpellchecking); |
269 | debug('isDarkModeEnabled', this.settings.service.isDarkModeEnabled); | 270 | console.log('isDarkModeEnabled', this.settings.service.isDarkModeEnabled); |
270 | debug( | 271 | console.log( |
271 | 'System spellcheckerLanguage', | 272 | 'System spellcheckerLanguage', |
272 | this.settings.app.spellcheckerLanguage, | 273 | this.settings.app.spellcheckerLanguage, |
273 | ); | 274 | ); |
274 | debug( | 275 | console.log( |
275 | 'Service spellcheckerLanguage', | 276 | 'Service spellcheckerLanguage', |
276 | this.settings.service.spellcheckerLanguage, | 277 | this.settings.service.spellcheckerLanguage, |
277 | ); | 278 | ); |
278 | debug('darkReaderSettigs', this.settings.service.darkReaderSettings); | 279 | console.log('darkReaderSettigs', this.settings.service.darkReaderSettings); |
279 | debug('searchEngine', this.settings.app.searchEngine); | 280 | console.log('searchEngine', this.settings.app.searchEngine); |
280 | 281 | ||
281 | if (this.userscript && this.userscript.internal_setSettings) { | 282 | if (this.userscript && this.userscript.internal_setSettings) { |
282 | this.userscript.internal_setSettings(this.settings); | 283 | this.userscript.internal_setSettings(this.settings); |
@@ -284,10 +285,10 @@ class RecipeController { | |||
284 | 285 | ||
285 | if (this.settings.app.enableSpellchecking) { | 286 | if (this.settings.app.enableSpellchecking) { |
286 | let { spellcheckerLanguage } = this; | 287 | let { spellcheckerLanguage } = this; |
287 | debug(`Setting spellchecker language to ${spellcheckerLanguage}`); | 288 | console.log(`Setting spellchecker language to ${spellcheckerLanguage}`); |
288 | if (spellcheckerLanguage.includes('automatic')) { | 289 | if (spellcheckerLanguage.includes('automatic')) { |
289 | this.automaticLanguageDetection(); | 290 | this.automaticLanguageDetection(); |
290 | debug( | 291 | console.log( |
291 | 'Found `automatic` locale, falling back to user locale until detected', | 292 | 'Found `automatic` locale, falling back to user locale until detected', |
292 | this.settings.app.locale, | 293 | this.settings.app.locale, |
293 | ); | 294 | ); |
@@ -295,14 +296,14 @@ class RecipeController { | |||
295 | } | 296 | } |
296 | switchDict(spellcheckerLanguage, this.settings.service.id); | 297 | switchDict(spellcheckerLanguage, this.settings.service.id); |
297 | } else { | 298 | } else { |
298 | debug('Disable spellchecker'); | 299 | console.log('Disable spellchecker'); |
299 | } | 300 | } |
300 | 301 | ||
301 | if (!this.recipe) { | 302 | if (!this.recipe) { |
302 | this.hasUpdatedBeforeRecipeLoaded = true; | 303 | this.hasUpdatedBeforeRecipeLoaded = true; |
303 | } | 304 | } |
304 | 305 | ||
305 | debug( | 306 | console.log( |
306 | 'Darkmode enabled?', | 307 | 'Darkmode enabled?', |
307 | this.settings.service.isDarkModeEnabled, | 308 | this.settings.service.isDarkModeEnabled, |
308 | 'Dark theme active?', | 309 | 'Dark theme active?', |
@@ -322,11 +323,11 @@ class RecipeController { | |||
322 | this.settings.service.isDarkModeEnabled && | 323 | this.settings.service.isDarkModeEnabled && |
323 | this.settings.app.isDarkThemeActive !== false | 324 | this.settings.app.isDarkThemeActive !== false |
324 | ) { | 325 | ) { |
325 | debug('Enable dark mode'); | 326 | console.log('Enable dark mode'); |
326 | 327 | ||
327 | // Check if recipe has a custom dark mode handler | 328 | // Check if recipe has a custom dark mode handler |
328 | if (this.recipe && this.recipe.darkModeHandler) { | 329 | if (this.recipe && this.recipe.darkModeHandler) { |
329 | debug('Using custom dark mode handler'); | 330 | console.log('Using custom dark mode handler'); |
330 | 331 | ||
331 | // Remove other dark mode styles if they were already loaded | 332 | // Remove other dark mode styles if they were already loaded |
332 | if (this.hasUpdatedBeforeRecipeLoaded) { | 333 | if (this.hasUpdatedBeforeRecipeLoaded) { |
@@ -337,7 +338,7 @@ class RecipeController { | |||
337 | 338 | ||
338 | this.recipe.darkModeHandler(true, handlerConfig); | 339 | this.recipe.darkModeHandler(true, handlerConfig); |
339 | } else if (darkModeStyleExists(this.settings.service.recipe.path)) { | 340 | } else if (darkModeStyleExists(this.settings.service.recipe.path)) { |
340 | debug('Injecting darkmode from recipe'); | 341 | console.log('Injecting darkmode from recipe'); |
341 | injectDarkModeStyle(this.settings.service.recipe.path); | 342 | injectDarkModeStyle(this.settings.service.recipe.path); |
342 | 343 | ||
343 | // Make sure universal dark mode is disabled | 344 | // Make sure universal dark mode is disabled |
@@ -347,7 +348,7 @@ class RecipeController { | |||
347 | this.settings.app.universalDarkMode && | 348 | this.settings.app.universalDarkMode && |
348 | !ignoreList.includes(window.location.host) | 349 | !ignoreList.includes(window.location.host) |
349 | ) { | 350 | ) { |
350 | debug('Injecting Dark Reader'); | 351 | console.log('Injecting Dark Reader'); |
351 | 352 | ||
352 | // Use Dark Reader instead | 353 | // Use Dark Reader instead |
353 | const { brightness, contrast, sepia } = | 354 | const { brightness, contrast, sepia } = |
@@ -361,8 +362,8 @@ class RecipeController { | |||
361 | this.universalDarkModeInjected = true; | 362 | this.universalDarkModeInjected = true; |
362 | } | 363 | } |
363 | } else { | 364 | } else { |
364 | debug('Remove dark mode'); | 365 | console.log('Remove dark mode'); |
365 | debug('DarkMode disabled - removing remaining styles'); | 366 | console.log('DarkMode disabled - removing remaining styles'); |
366 | 367 | ||
367 | if (this.recipe && this.recipe.darkModeHandler) { | 368 | if (this.recipe && this.recipe.darkModeHandler) { |
368 | // Remove other dark mode styles if they were already loaded | 369 | // Remove other dark mode styles if they were already loaded |
@@ -374,10 +375,10 @@ class RecipeController { | |||
374 | 375 | ||
375 | this.recipe.darkModeHandler(false, handlerConfig); | 376 | this.recipe.darkModeHandler(false, handlerConfig); |
376 | } else if (isDarkModeStyleInjected()) { | 377 | } else if (isDarkModeStyleInjected()) { |
377 | debug('Removing injected darkmode from recipe'); | 378 | console.log('Removing injected darkmode from recipe'); |
378 | removeDarkModeStyle(); | 379 | removeDarkModeStyle(); |
379 | } else { | 380 | } else { |
380 | debug('Removing Dark Reader'); | 381 | console.log('Removing Dark Reader'); |
381 | 382 | ||
382 | disableDarkMode(); | 383 | disableDarkMode(); |
383 | this.universalDarkModeInjected = false; | 384 | this.universalDarkModeInjected = false; |
@@ -405,7 +406,7 @@ class RecipeController { | |||
405 | } | 406 | } |
406 | 407 | ||
407 | serviceIdEcho(event) { | 408 | serviceIdEcho(event) { |
408 | debug('Received a service echo ping'); | 409 | console.log('Received a service echo ping'); |
409 | event.sender.send('service-id', this.settings.service.id); | 410 | event.sender.send('service-id', this.settings.service.id); |
410 | } | 411 | } |
411 | 412 | ||
@@ -427,7 +428,7 @@ class RecipeController { | |||
427 | // Force a minimum length to get better detection results | 428 | // Force a minimum length to get better detection results |
428 | if (value.length < 25) return; | 429 | if (value.length < 25) return; |
429 | 430 | ||
430 | debug('Detecting language for', value); | 431 | console.log('Detecting language for', value); |
431 | const locale = await ipcRenderer.invoke('detect-language', { | 432 | const locale = await ipcRenderer.invoke('detect-language', { |
432 | sample: value, | 433 | sample: value, |
433 | }); | 434 | }); |
@@ -437,7 +438,7 @@ class RecipeController { | |||
437 | 438 | ||
438 | const spellcheckerLocale = | 439 | const spellcheckerLocale = |
439 | getSpellcheckerLocaleByFuzzyIdentifier(locale); | 440 | getSpellcheckerLocaleByFuzzyIdentifier(locale); |
440 | debug( | 441 | console.log( |
441 | 'Language detected reliably, setting spellchecker language to', | 442 | 'Language detected reliably, setting spellchecker language to', |
442 | spellcheckerLocale, | 443 | spellcheckerLocale, |
443 | ); | 444 | ); |