本文整理汇总了TypeScript中electron.BrowserWindow.loadFile方法的典型用法代码示例。如果您正苦于以下问题:TypeScript BrowserWindow.loadFile方法的具体用法?TypeScript BrowserWindow.loadFile怎么用?TypeScript BrowserWindow.loadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.BrowserWindow
的用法示例。
在下文中一共展示了BrowserWindow.loadFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createMainWindow
export function createMainWindow(): Electron.BrowserWindow {
console.log(`Creating main window`);
const browserWindow = new BrowserWindow(getMainWindowOptions());
browserWindow.loadFile('./dist/static/index.html');
browserWindow.webContents.once('dom-ready', () => {
browserWindow.show();
if (browserWindow) {
createContextMenu(browserWindow);
}
});
browserWindow.on('closed', () => {
browserWindows = browserWindows
.filter((bw) => browserWindow !== bw);
});
browserWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
browserWindow.webContents.on('will-navigate', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
browserWindows.push(browserWindow);
return browserWindow;
}
示例2: createWindow
function createWindow() {
const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;
// Create the browser window.
mainWindow = new BrowserWindow({
x: 0,
y: 0,
width: size.width,
height: size.height
});
if (liveReload) {
require('electron-reload')(__dirname, { electron: require(`${__dirname}/node_modules/electron`) });
mainWindow.loadURL('http://localhost:4200');
mainWindow.webContents.openDevTools();
} else {
// Load the index.html of the app.
mainWindow.loadFile('dist.electron/index.html');
}
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
示例3: it
it('returns an array of web contents', async () => {
w.loadFile(path.join(fixturesPath, 'pages', 'webview-zoom-factor.html'))
await emittedOnce(w.webContents, 'did-attach-webview')
w.webContents.openDevTools()
await emittedOnce(w.webContents, 'devtools-opened')
const all = webContents.getAllWebContents().sort((a, b) => {
return a.id - b.id
})
expect(all).to.have.length(3)
expect(all[0].getType()).to.equal('window')
expect(all[all.length - 2].getType()).to.equal('webview')
expect(all[all.length - 1].getType()).to.equal('remote')
})
示例4: BrowserWindow
app.on('ready', () => {
window = new BrowserWindow({
acceptFirstMouse: true,
width: 1280,
height: 720,
minWidth: 500,
minHeight: 500,
backgroundColor: "#DDDDDD",
frame: false,
hasShadow: true
});
// window.setMenu(null);
window.loadFile(join(__dirname, "../", "index.html"));
window.on('closed', function () {
window = undefined;
});
});
示例5: EstablishElectronWindow
function EstablishElectronWindow() {
// If not prod, install Vue devtools.
if (isDev) {
require('vue-devtools').install()
}
/* Check whether we are started in the hidden state as part of the computer startup process. */
const loginSettings = elc.app.getLoginItemSettings()
let hiddenStartAtBoot = loginSettings.wasOpenedAsHidden
// ^ Only applies to Mac OS
if (process.platform === 'win32') {
// ^ Windows version of above
for (let arg of process.argv) {
if (arg === '--hidden') {
hiddenStartAtBoot = true
}
}
}
// Create the browser window.
// let dm = elc.screen.getPrimaryDisplay().size
let bounds = getWinBounds()
let windowSpec: any = {
show: false,
// width: dm.width * 0.8,
width: bounds.w,
// height: dm.height * 0.8,
height: bounds.h,
title: 'Aether',
fullscreenWindowTitle: true,
backgroundColor: '#292b2f',
disableBlinkFeatures: 'Auxclick', // disable middle click new window
autoHideMenuBar: true,
webPreferences: {
// blinkFeatures: 'OverlayScrollbars'
},
}
if (process.platform === 'win32') {
windowSpec.frame = false // We have our traffic lights implementation for Win
}
if (process.platform === 'darwin') {
windowSpec.titleBarStyle = 'hiddenInset' // Mac traffic lights
}
if (process.platform === 'linux') {
windowSpec.darkTheme = true // GTK3+ Only
// Nothing specific for the frame for now.
}
win = new elc.BrowserWindow(windowSpec)
win.once('ready-to-show', function() {
// We want to show the window only after Electron is done readying itself.
setTimeout(function() {
if (!hiddenStartAtBoot) {
win.show()
}
}, 100)
// Unfortunately, there's a race condition from the Electron side here (I might be making a mistake also, but it is simple enough to reproduce that there is not much space for me to make a mistake). If the setTimeout is 0 or is not present, there's about 1/10 chance the window is painted but completely frozen. Having 100ms seems to make it go away, but it's a little icky, because that basically is my guess. Not great. Hopefully they'll fix this in upcoming Electron 3.
})
win.loadFile('index.html')
if (isDev) {
// Open the DevTools.
win.webContents.openDevTools({ mode: 'bottom' })
}
// win.webContents.openDevTools({ mode: 'bottom' })
win.on('close', function(e: any) {
e.preventDefault()
// ^ Prevents the app from continuing on with destroying the window element. We need that element.
closeAppWindow()
// DOM_READY = false // This is useful when the electron window fully shuts down, not when it's not fully shut down.
})
win.webContents.on('dom-ready', function() {
DOM_READY = true
// This is needed because the renderer process won't be able to respond to IPC requests before this event happens.
if (process.platform == 'win32') {
/*---------- Windows specific deep linker ----------*/
/*
This is the windows-specific implementation of the open-url in the will-finish-launching event.
This code is available in two different places. This one handles deep-linking from cold boot.
*/
// Keep only command line / deep linked arguments
if (typeof process.argv.slice(1)[0] !== 'undefined') {
linkToLoadAtBoot = process.argv.slice(1)[0].substring(8)
}
}
// Normal open-url event works for Mac and Linux
if (linkToLoadAtBoot.length > 0) {
ipc.callRenderer(win, 'RouteTo', linkToLoadAtBoot)
}
})
win.webContents.on('will-navigate', function(e: any, reqUrl: any) {
e.preventDefault()
elc.shell.openExternal(reqUrl)
// return
// let getHost = function(url: any) { require('url').parse(url).host }
// let reqHost = getHost(reqUrl)
// let isExternal = reqHost && reqHost != getHost(win.webContents.getURL())
// if (isExternal) {
//.........这里部分代码省略.........
示例6: async
export const loadFile = async (appPath: string) => {
mainWindow = await createWindow()
mainWindow.loadFile(appPath)
mainWindow.focus()
}