Skip to content

Commit

Permalink
Created loading error handling file for further work on that, i.e. di…
Browse files Browse the repository at this point in the history
…splaying no internet screen or certificate error screen
  • Loading branch information
Enrike Churin committed Aug 6, 2022
1 parent 9ba3353 commit cf69a9b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
23 changes: 23 additions & 0 deletions src/LoadingError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

export function LoadingError(code: number, desc: string, url: string, displayError: (code: number, desc: string) => void): void {
console.log('Failed loading the page, with the code:')
console.log(code)
console.log('Description:')
console.log(desc)
console.log('Failed URL:')
console.log(url)
console.log('')

switch (code) {
case -3:

break

case -106:
displayError(code, desc)
break

default:
break
}
}
10 changes: 8 additions & 2 deletions src/View.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { BrowserView, BrowserWindow, ipcMain, dialog } from "electron"
import * as path from "path"
import { LoadingError } from "./LoadingError"

export class View {
view: BrowserView
Expand All @@ -18,12 +20,14 @@ export class View {
zoomFactor: 1.0,
navigateOnDragDrop: true,
scrollBounce: true,
preload: path.join(__dirname, "viewPreload.js"),
}
})
win.addBrowserView(this.view)
this.view.setBounds({ x: 0, y: tabHeight, width: width, height: height - tabHeight })
this.view.setAutoResize({width: true, height: true})
this.view.webContents.setVisualZoomLevelLimits(1, 3)

// this.view.webContents.openDevTools()

this.goHome()
Expand Down Expand Up @@ -96,9 +100,11 @@ export class View {
win.webContents.send('startedLoading')
})

this.view.webContents.on('did-fail-load', () => {
console.log('failed loading the page!')
this.view.webContents.on('did-fail-load', (_ev: Event, code: number, desc: string, url: string) => {
doneLoading()
LoadingError(code, desc, url, () => {
// pass
})
})

ipcMain.on('goBack', () => {
Expand Down
13 changes: 7 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,28 @@ function createWindow() {

setTimeout(() => {
settingsDropdown = new SettingsDropdown(10, 42, 130, 116, '../pages/settings.html', win.win, view.view, theme)

ipcMain.on('toggleSettings', () => {
if (settingsDropdown.open) {
settingsDropdown.hide()
} else {
settingsDropdown.show()
}
})

}, 500)

}, 1000)
ipcMain.on('toggleTheme', (_ev: Event, t: 'dark' | 'light') => {
theme = t
setTheme(theme)
})

setTheme(theme)

win.win.on('ready-to-show', () => {
win.win.setBackgroundColor(theme === 'dark' ? '#000000' : '#FFFFFF')
})

}

app.on("ready", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ contextBridge.exposeInMainWorld('api', {
handleStartedLoading: (callback: () => void) => ipcRenderer.on('startedLoading', callback),

handleFinishedLoading: (callback: () => void) => ipcRenderer.on('finishedLoading', callback),
})
})
1 change: 1 addition & 0 deletions src/viewPreload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: Add a contextmenu

0 comments on commit cf69a9b

Please sign in to comment.