electron#NewWindowWebContentsEvent TypeScript Examples
The following examples show how to use
electron#NewWindowWebContentsEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts From bitcoin-s-ts with MIT License | 6 votes |
createWindow = (): void => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1080,
height: 900,
icon: path.join(__dirname, 'assets/icon.png'), // Linux app icon
webPreferences: {
nodeIntegration: true,
// May want to use app.getAppPath() instead
// preload: path.join(__dirname, 'preload.js'), // use a preload script
// preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
// allowRunningInsecureContent: true,
// webSecurity: false,
// sandbox: false,
}
});
// and load the index.html of the app.
// mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
mainWindow.loadURL(`http://localhost:${uiPort}`)
// Open the DevTools for `npm run start`
if (!app.isPackaged) mainWindow.webContents.openDevTools()
mainWindow.on('close', function () {
console.debug('close')
clearLocalStorage()
})
mainWindow.on('closed', function () {
console.debug('closed')
mainWindow = null
})
// Open links in browser instead of new electron window
mainWindow.webContents.on('new-window', function(e: NewWindowWebContentsEvent, url: string) {
e.preventDefault()
shell.openExternal(url)
})
}
Example #2
Source File: index.ts From bitcoin-s-ts with MIT License | 5 votes |
createWindow = (): void => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1080,
height: 900,
icon: path.join(__dirname, 'assets/icon.png'), // Linux app icon
webPreferences: {
nodeIntegration: true,
// May want to use app.getAppPath() instead
// preload: path.join(__dirname, 'preload.js'), // use a preload script
// preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
// allowRunningInsecureContent: true,
// webSecurity: false,
// sandbox: false,
}
});
// and load the index.html of the app.
// mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
mainWindow.loadURL('http://localhost:3002')
// Open the DevTools
if (!app.isPackaged)
mainWindow.webContents.openDevTools()
mainWindow.on('close', function () {
console.debug('close')
clearLocalStorage()
})
mainWindow.on('closed', function () {
console.debug('closed')
mainWindow = null
})
// Open links in browser instead of new electron window
mainWindow.webContents.on('new-window', function(e: NewWindowWebContentsEvent, url: string) {
e.preventDefault()
shell.openExternal(url)
})
}