From 0c6d6a466b4c0e4540d9c4ae619c248066dcb677 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 16 Jul 2020 18:10:33 +0200 Subject: [PATCH 1/2] Add "file not found" error and do not catch user aborts as load errors --- .../{error.html => connection_error.html} | 2 +- frontend/file_not_found_error.html | 20 +++++++++++++++++++ frontend/ts/index.ts | 20 ++++++++++++------- src/windows/MainWindow.ts | 7 +++++-- 4 files changed, 39 insertions(+), 10 deletions(-) rename frontend/{error.html => connection_error.html} (93%) create mode 100644 frontend/file_not_found_error.html diff --git a/frontend/error.html b/frontend/connection_error.html similarity index 93% rename from frontend/error.html rename to frontend/connection_error.html index 39173a3..c3de7e5 100644 --- a/frontend/error.html +++ b/frontend/connection_error.html @@ -15,7 +15,7 @@

Oops

-

An error has occurred while loading this document.

+

A connection error has occurred.

Please check your internet connection and this service's URL.

If you can load the actual URL in your favorite web browser, please file us a bug report.

diff --git a/frontend/file_not_found_error.html b/frontend/file_not_found_error.html new file mode 100644 index 0000000..f2bccb9 --- /dev/null +++ b/frontend/file_not_found_error.html @@ -0,0 +1,20 @@ + + + + + An error occured + + + + + + + + + +

Oops

+

File not found.

+ + diff --git a/frontend/ts/index.ts b/frontend/ts/index.ts index 28e51ee..8be799d 100644 --- a/frontend/ts/index.ts +++ b/frontend/ts/index.ts @@ -1,5 +1,6 @@ import { clipboard, + DidFailLoadEvent, ipcRenderer, PageFaviconUpdatedEvent, remote, @@ -26,7 +27,7 @@ let securityButton: HTMLElement | null, backButton: HTMLElement | null, refreshButton: HTMLElement | null; let addButton, settingsButton; -let emptyPage: string, errorPage: string; +let pages: any; let urlPreview: HTMLElement | null; let serviceSelector: HTMLElement | null; @@ -128,7 +129,7 @@ function openServiceContextMenu(event: Event, serviceId: number) { } -ipcRenderer.on('data', (event, appData, iconSets, actualSelectedService, emptyUrl, errorUrl, config) => { +ipcRenderer.on('data', (event, appData, iconSets, actualSelectedService, urls, config) => { // App info appInfo.title = appData.title; @@ -178,8 +179,7 @@ ipcRenderer.on('data', (event, appData, iconSets, actualSelectedService, emptyUr setActiveService(actualSelectedService); // Empty - emptyPage = emptyUrl; - errorPage = errorUrl; + pages = urls; // Url preview element urlPreview = document.getElementById("url-preview"); @@ -475,15 +475,21 @@ function loadService(serviceId: number, service: any) { service.view.setAttribute('enableRemoteModule', 'false'); service.view.setAttribute('partition', 'persist:service_' + service.partition); service.view.setAttribute('autosize', 'true'); - service.view.setAttribute('src', emptyPage); + service.view.setAttribute('src', pages?.empty); // Enable context isolation. This is currently not used as there is no preload script; however it could prevent // eventual future human mistakes. service.view.setAttribute('webpreferences', 'contextIsolation=yes'); // Error handling - service.view.addEventListener('did-fail-load', (e: Event) => { - service.view.setAttribute('src', errorPage); + service.view.addEventListener('did-fail-load', (e: DidFailLoadEvent) => { + if (e.errorCode <= -100 && e.errorCode > -200) { + service.view.setAttribute('src', pages?.connectionError); + } else if (e.errorCode === -6) { + service.view.setAttribute('src', pages?.fileNotFound); + } else if (e.errorCode !== -3) { + console.error('Unhandled error:', e); + } }); // Append element to DOM diff --git a/src/windows/MainWindow.ts b/src/windows/MainWindow.ts index 776a072..885c144 100644 --- a/src/windows/MainWindow.ts +++ b/src/windows/MainWindow.ts @@ -146,8 +146,11 @@ export default class MainWindow extends Window { Meta.title, Meta.ICON_SETS, this.activeService, - path.resolve(Meta.RESOURCES_PATH, 'empty.html'), - path.resolve(Meta.RESOURCES_PATH, 'error.html'), + { + empty: path.resolve(Meta.RESOURCES_PATH, 'empty.html'), + connectionError: path.resolve(Meta.RESOURCES_PATH, 'connection_error.html'), + fileNotFound: path.resolve(Meta.RESOURCES_PATH, 'file_not_found_error.html'), + }, this.config ); } From aef592e48ad005fad9878efabfd41f2c2e556f6a Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 16 Jul 2020 18:10:51 +0200 Subject: [PATCH 2/2] Version 1.1.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf07a1c..4a2257a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tabs", - "version": "1.1.4", + "version": "1.1.5", "description": "Persistent and separate browser tabs in one window.", "author": { "name": "Alice Gaudon",