Add window.loadFile and webContents.loadFile helper methods

This commit is contained in:
Samuel Attard 2018-01-04 11:38:56 +13:00
parent 249bd41e11
commit 1553b54779
No known key found for this signature in database
GPG key ID: E89DDE5742D58C4E
4 changed files with 46 additions and 0 deletions

View file

@ -2,6 +2,8 @@
const {EventEmitter} = require('events')
const electron = require('electron')
const path = require('path')
const url = require('url')
const {app, ipcMain, session, NavigationController} = electron
// session is not used here, the purpose is to make sure session is initalized
@ -243,6 +245,17 @@ WebContents.prototype.getZoomLevel = function (callback) {
})
}
WebContents.prototype.loadFile = function (filePath) {
if (typeof filePath !== 'string') {
throw new Error('Must pass filePath as a string')
}
return this.loadURL(url.format({
protocol: 'file',
slashes: true,
pathname: path.resolve(app.getAppPath(), filePath)
}))
}
WebContents.prototype.getZoomFactor = function (callback) {
if (typeof callback !== 'function') {
throw new Error('Must pass function as an argument')