aboutsummaryrefslogtreecommitdiffstats
path: root/src/index.ts
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-04-22 15:04:21 -0500
committerLibravatar GitHub <noreply@github.com>2022-04-22 20:04:21 +0000
commit759d93dc198a3cc8c5265245c0144efa5435682b (patch)
tree53e963a085d3d12af5a2efa2f1ab6f3e5574edc7 /src/index.ts
parentAdded build scripts for linux, macos and windows to help new contributors get... (diff)
downloadferdium-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/index.ts')
-rw-r--r--src/index.ts63
1 files changed, 32 insertions, 31 deletions
diff --git a/src/index.ts b/src/index.ts
index 1721651e4..6be4f3f18 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -44,10 +44,11 @@ import { asarPath } from './helpers/asar-helpers';
44import { openExternalUrl } from './helpers/url-helpers'; 44import { openExternalUrl } from './helpers/url-helpers';
45import userAgent from './helpers/userAgent-helpers'; 45import userAgent from './helpers/userAgent-helpers';
46 46
47const debug = require('debug')('Ferdium:App'); 47// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed
48// const debug = require('debug')('Ferdium:App');
48 49
49// Globally set useragent to fix user agent override in service workers 50// Globally set useragent to fix user agent override in service workers
50debug('Set userAgent to ', userAgent()); 51console.log('Set userAgent to', userAgent());
51app.userAgentFallback = userAgent(); 52app.userAgentFallback = userAgent();
52 53
53// Keep a global reference of the window object, if you don't, the window will 54// Keep a global reference of the window object, if you don't, the window will
@@ -126,7 +127,7 @@ if (!gotTheLock) {
126 if (argv.includes('--reset-window')) { 127 if (argv.includes('--reset-window')) {
127 // Needs to be delayed to not interfere with mainWindow.restore(); 128 // Needs to be delayed to not interfere with mainWindow.restore();
128 setTimeout(() => { 129 setTimeout(() => {
129 debug('Resetting windows via Task'); 130 console.log('Resetting windows via Task');
130 window.setPosition( 131 window.setPosition(
131 DEFAULT_WINDOW_OPTIONS.x + 100, 132 DEFAULT_WINDOW_OPTIONS.x + 100,
132 DEFAULT_WINDOW_OPTIONS.y + 100, 133 DEFAULT_WINDOW_OPTIONS.y + 100,
@@ -139,7 +140,7 @@ if (!gotTheLock) {
139 } else if (argv.includes('--quit')) { 140 } else if (argv.includes('--quit')) {
140 // Needs to be delayed to not interfere with mainWindow.restore(); 141 // Needs to be delayed to not interfere with mainWindow.restore();
141 setTimeout(() => { 142 setTimeout(() => {
142 debug('Quitting Ferdium via Task'); 143 console.log('Quitting Ferdium via Task');
143 app.quit(); 144 app.quit();
144 }, 1); 145 }, 1);
145 } 146 }
@@ -161,7 +162,7 @@ if (
161 162
162// Disable GPU acceleration 163// Disable GPU acceleration
163if (!retrieveSettingValue('enableGPUAcceleration', false)) { 164if (!retrieveSettingValue('enableGPUAcceleration', false)) {
164 debug('Disable GPU Acceleration'); 165 console.log('Disable GPU Acceleration');
165 app.disableHardwareAcceleration(); 166 app.disableHardwareAcceleration();
166} 167}
167 168
@@ -183,7 +184,7 @@ const createWindow = () => {
183 let posY = mainWindowState.y || DEFAULT_WINDOW_OPTIONS.y; 184 let posY = mainWindowState.y || DEFAULT_WINDOW_OPTIONS.y;
184 185
185 if (!isPositionValid({ x: posX, y: posY })) { 186 if (!isPositionValid({ x: posX, y: posY })) {
186 debug('Window is out of screen bounds, resetting window'); 187 console.log('Window is out of screen bounds, resetting window');
187 posX = DEFAULT_WINDOW_OPTIONS.x; 188 posX = DEFAULT_WINDOW_OPTIONS.x;
188 posY = DEFAULT_WINDOW_OPTIONS.y; 189 posY = DEFAULT_WINDOW_OPTIONS.y;
189 } 190 }
@@ -284,7 +285,7 @@ const createWindow = () => {
284 285
285 // Emitted when the window is closed. 286 // Emitted when the window is closed.
286 mainWindow.on('close', e => { 287 mainWindow.on('close', e => {
287 debug('Window: close window'); 288 console.log('Window: close window');
288 // Dereference the window object, usually you would store windows 289 // Dereference the window object, usually you would store windows
289 // in an array if your app supports multi windows, this is the time 290 // in an array if your app supports multi windows, this is the time
290 // when you should delete the corresponding element. 291 // when you should delete the corresponding element.
@@ -297,7 +298,7 @@ const createWindow = () => {
297 ) { 298 ) {
298 e.preventDefault(); 299 e.preventDefault();
299 if (isWindows) { 300 if (isWindows) {
300 debug('Window: minimize'); 301 console.log('Window: minimize');
301 mainWindow?.minimize(); 302 mainWindow?.minimize();
302 303
303 if ( 304 if (
@@ -306,16 +307,16 @@ const createWindow = () => {
306 DEFAULT_APP_SETTINGS.closeToSystemTray, 307 DEFAULT_APP_SETTINGS.closeToSystemTray,
307 ) 308 )
308 ) { 309 ) {
309 debug('Skip taskbar: true'); 310 console.log('Skip taskbar: true');
310 mainWindow?.setSkipTaskbar(true); 311 mainWindow?.setSkipTaskbar(true);
311 } 312 }
312 } else if (isMac && mainWindow?.isFullScreen()) { 313 } else if (isMac && mainWindow?.isFullScreen()) {
313 debug('Window: leaveFullScreen and hide'); 314 console.log('Window: leaveFullScreen and hide');
314 mainWindow.once('show', () => mainWindow?.setFullScreen(true)); 315 mainWindow.once('show', () => mainWindow?.setFullScreen(true));
315 mainWindow.once('leave-full-screen', () => mainWindow?.hide()); 316 mainWindow.once('leave-full-screen', () => mainWindow?.hide());
316 mainWindow.setFullScreen(false); 317 mainWindow.setFullScreen(false);
317 } else { 318 } else {
318 debug('Window: hide'); 319 console.log('Window: hide');
319 mainWindow?.hide(); 320 mainWindow?.hide();
320 } 321 }
321 } else { 322 } else {
@@ -336,31 +337,31 @@ const createWindow = () => {
336 DEFAULT_APP_SETTINGS.minimizeToSystemTray, 337 DEFAULT_APP_SETTINGS.minimizeToSystemTray,
337 ) 338 )
338 ) { 339 ) {
339 debug('Skip taskbar: true'); 340 console.log('Skip taskbar: true');
340 mainWindow?.setSkipTaskbar(true); 341 mainWindow?.setSkipTaskbar(true);
341 trayIcon.show(); 342 trayIcon.show();
342 } 343 }
343 }); 344 });
344 345
345 mainWindow.on('maximize', () => { 346 mainWindow.on('maximize', () => {
346 debug('Window: maximize'); 347 console.log('Window: maximize');
347 // @ts-expect-error Property 'isMaximized' does not exist on type 'App'. 348 // @ts-expect-error Property 'isMaximized' does not exist on type 'App'.
348 app.isMaximized = true; 349 app.isMaximized = true;
349 }); 350 });
350 351
351 mainWindow.on('unmaximize', () => { 352 mainWindow.on('unmaximize', () => {
352 debug('Window: unmaximize'); 353 console.log('Window: unmaximize');
353 // @ts-expect-error Property 'isMaximized' does not exist on type 'App'. 354 // @ts-expect-error Property 'isMaximized' does not exist on type 'App'.
354 app.isMaximized = false; 355 app.isMaximized = false;
355 }); 356 });
356 357
357 mainWindow.on('restore', () => { 358 mainWindow.on('restore', () => {
358 debug('Window: restore'); 359 console.log('Window: restore');
359 mainWindow?.setSkipTaskbar(false); 360 mainWindow?.setSkipTaskbar(false);
360 361
361 // @ts-expect-error Property 'wasMaximized' does not exist on type 'App'. 362 // @ts-expect-error Property 'wasMaximized' does not exist on type 'App'.
362 if (app.wasMaximized) { 363 if (app.wasMaximized) {
363 debug('Window: was maximized before, maximize window'); 364 console.log('Window: was maximized before, maximize window');
364 mainWindow?.maximize(); 365 mainWindow?.maximize();
365 } 366 }
366 367
@@ -370,7 +371,7 @@ const createWindow = () => {
370 DEFAULT_APP_SETTINGS.enableSystemTray, 371 DEFAULT_APP_SETTINGS.enableSystemTray,
371 ) 372 )
372 ) { 373 ) {
373 debug('Tray: hiding tray icon'); 374 console.log('Tray: hiding tray icon');
374 trayIcon.hide(); 375 trayIcon.hide();
375 } 376 }
376 }); 377 });
@@ -382,7 +383,7 @@ const createWindow = () => {
382 } 383 }
383 384
384 mainWindow.on('show', () => { 385 mainWindow.on('show', () => {
385 debug('Skip taskbar: true'); 386 console.log('Skip taskbar: true');
386 mainWindow?.setSkipTaskbar(false); 387 mainWindow?.setSkipTaskbar(false);
387 }); 388 });
388 389
@@ -499,18 +500,18 @@ let authCallback = noop;
499app.on('login', (event, _webContents, _request, authInfo, callback) => { 500app.on('login', (event, _webContents, _request, authInfo, callback) => {
500 // @ts-expect-error Type '(username?: string | undefined, password?: string | undefined) => void' is not assignable to type '() => null'. 501 // @ts-expect-error Type '(username?: string | undefined, password?: string | undefined) => void' is not assignable to type '() => null'.
501 authCallback = callback; 502 authCallback = callback;
502 debug('browser login event', authInfo); 503 console.log('browser login event', authInfo);
503 event.preventDefault(); 504 event.preventDefault();
504 505
505 if (!authInfo.isProxy && authInfo.scheme === 'basic') { 506 if (!authInfo.isProxy && authInfo.scheme === 'basic') {
506 debug('basic auth handler', authInfo); 507 console.log('basic auth handler', authInfo);
507 basicAuthHandler(mainWindow!, authInfo); 508 basicAuthHandler(mainWindow!, authInfo);
508 } 509 }
509}); 510});
510 511
511// TODO: evaluate if we need to store the authCallback for every service 512// TODO: evaluate if we need to store the authCallback for every service
512ipcMain.on('feature-basic-auth-credentials', (_e, { user, password }) => { 513ipcMain.on('feature-basic-auth-credentials', (_e, { user, password }) => {
513 debug('Received basic auth credentials', user, '********'); 514 console.log('Received basic auth credentials', user, '********');
514 515
515 // @ts-expect-error Expected 0 arguments, but got 2. 516 // @ts-expect-error Expected 0 arguments, but got 2.
516 authCallback(user, password); 517 authCallback(user, password);
@@ -529,13 +530,13 @@ ipcMain.on('open-browser-window', (_e, { url, serviceId }) => {
529 enableWebContents(child.webContents); 530 enableWebContents(child.webContents);
530 child.show(); 531 child.show();
531 child.loadURL(url); 532 child.loadURL(url);
532 debug('Received open-browser-window', url); 533 console.log('Received open-browser-window', url);
533}); 534});
534 535
535ipcMain.on( 536ipcMain.on(
536 'modifyRequestHeaders', 537 'modifyRequestHeaders',
537 (_e, { modifiedRequestHeaders, serviceId }) => { 538 (_e, { modifiedRequestHeaders, serviceId }) => {
538 debug( 539 console.log(
539 `Received modifyRequestHeaders ${modifiedRequestHeaders} for serviceId ${serviceId}`, 540 `Received modifyRequestHeaders ${modifiedRequestHeaders} for serviceId ${serviceId}`,
540 ); 541 );
541 for (const headerFilterSet of modifiedRequestHeaders) { 542 for (const headerFilterSet of modifiedRequestHeaders) {
@@ -556,7 +557,7 @@ ipcMain.on(
556); 557);
557 558
558ipcMain.on('knownCertificateHosts', (_e, { knownHosts, serviceId }) => { 559ipcMain.on('knownCertificateHosts', (_e, { knownHosts, serviceId }) => {
559 debug( 560 console.log(
560 `Received knownCertificateHosts ${knownHosts} for serviceId ${serviceId}`, 561 `Received knownCertificateHosts ${knownHosts} for serviceId ${serviceId}`,
561 ); 562 );
562 session 563 session
@@ -576,7 +577,7 @@ ipcMain.on('knownCertificateHosts', (_e, { knownHosts, serviceId }) => {
576}); 577});
577 578
578ipcMain.on('feature-basic-auth-cancel', () => { 579ipcMain.on('feature-basic-auth-cancel', () => {
579 debug('Cancel basic auth'); 580 console.log('Cancel basic auth');
580 581
581 // @ts-expect-error Expected 0 arguments, but got 2. 582 // @ts-expect-error Expected 0 arguments, but got 2.
582 authCallback(null); 583 authCallback(null);
@@ -595,7 +596,7 @@ ipcMain.on('find-in-page', (e, text, options) => {
595 } 596 }
596 } 597 }
597 const requestId = webContents.findInPage(text, sanitizedOptions); 598 const requestId = webContents.findInPage(text, sanitizedOptions);
598 debug('Find in page', text, options, requestId); 599 console.log('Find in page', text, options, requestId);
599 e.returnValue = requestId; 600 e.returnValue = requestId;
600 } else { 601 } else {
601 e.returnValue = null; 602 e.returnValue = null;
@@ -624,10 +625,10 @@ ipcMain.on('set-spellchecker-locales', (_e, { locale, serviceId }) => {
624 625
625 const serviceSession = session.fromPartition(`persist:service-${serviceId}`); 626 const serviceSession = session.fromPartition(`persist:service-${serviceId}`);
626 const [defaultLocale] = serviceSession.getSpellCheckerLanguages(); 627 const [defaultLocale] = serviceSession.getSpellCheckerLanguages();
627 debug(`Spellchecker default locale is: ${defaultLocale}`); 628 console.log(`Spellchecker default locale is: ${defaultLocale}`);
628 629
629 const locales = [locale, defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale]; 630 const locales = [locale, defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale];
630 debug(`Setting spellchecker locales to: ${locales}`); 631 console.log(`Setting spellchecker locales to: ${locales}`);
631 serviceSession.setSpellCheckerLanguages(locales); 632 serviceSession.setSpellCheckerLanguages(locales);
632}); 633});
633 634
@@ -645,10 +646,10 @@ app.on('window-all-closed', () => {
645 DEFAULT_APP_SETTINGS.runInBackground, 646 DEFAULT_APP_SETTINGS.runInBackground,
646 ) 647 )
647 ) { 648 ) {
648 debug('Window: all windows closed, quit app'); 649 console.log('Window: all windows closed, quit app');
649 app.quit(); 650 app.quit();
650 } else { 651 } else {
651 debug("Window: don't quit app"); 652 console.log("Window: don't quit app");
652 } 653 }
653}); 654});
654 655
@@ -694,7 +695,7 @@ app.on('will-finish-launching', () => {
694 event.preventDefault(); 695 event.preventDefault();
695 696
696 onDidLoad((window: BrowserWindow) => { 697 onDidLoad((window: BrowserWindow) => {
697 debug('open-url event', url); 698 console.log('open-url event', url);
698 handleDeepLink(window, url); 699 handleDeepLink(window, url);
699 }); 700 });
700 }); 701 });