Skip to content

Instantly share code, notes, and snippets.

@erickzhao
Created June 26, 2019 18:35
Show Gist options
  • Save erickzhao/c9c19684f6e0d23c102161fb3e86500b to your computer and use it in GitHub Desktop.
Save erickzhao/c9c19684f6e0d23c102161fb3e86500b to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!DOCTYPE html>
<html lang="en">
<head>
<title>BrowserWindow</title>
</head>
<body>
<button onclick="alert('click me')">Alert</button>
</body>
</html>
const { app, BrowserWindow } = require('electron')
app.on('ready', () => {
// main
const mainWindow = new BrowserWindow({
width: 600,
height: 600,
webPreferences: {
nodeIntegration: true,
nativeWindowOpen: true
}
})
mainWindow.loadFile('index.html')
// modal
mainWindow.once('ready-to-show', () => {
console.log('[LOG] Main focus before this please')
})
const child = new BrowserWindow({
parent: mainWindow,
modal: true,
show: false,
width: 400,
height: 400
})
child.loadURL('https://github.com')
child.once('ready-to-show', async () => {
child.show()
mainWindow.focus()
await setTimeout(() => child.close(), 1000)
})
child.on('focus', () => console.log('[FOCUS] Modal'))
mainWindow.on('focus', () => console.log('[FOCUS] Main'))
child.on('blur', () => console.log('[BLUR] Modal'))
mainWindow.on('blur', () => console.log('[BLUR] Main'))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment