-
-
Save erickzhao/c9c19684f6e0d23c102161fb3e86500b to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>BrowserWindow</title> | |
</head> | |
<body> | |
<button onclick="alert('click me')">Alert</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment