Add window.loadFile and webContents.loadFile helper methods
This commit is contained in:
parent
249bd41e11
commit
1553b54779
4 changed files with 46 additions and 0 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue