mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
Merge pull request #11565 from electron/add-load-file-helper
Add window.loadFile and webContents.loadFile helper methods
This commit is contained in:
@@ -169,6 +169,9 @@ Object.assign(BrowserWindow.prototype, {
|
||||
getURL (...args) {
|
||||
return this.webContents.getURL()
|
||||
},
|
||||
loadFile (filePath) {
|
||||
return this.webContents.loadFile(filePath)
|
||||
},
|
||||
reload (...args) {
|
||||
return this.webContents.reload(...args)
|
||||
},
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user