electron/docs/fiddles/windows/manage-windows/window-events/renderer.js
Milan Burda b14b876d50
docs: fix fiddles (#39060)
* refactor: replace Array.prototype.forEach.call with plain for-of

* fix: add missing contextIsolation: false

* fix: open links in default browser
2023-07-13 10:10:37 +02:00

39 lines
1.1 KiB
JavaScript

const { shell, ipcRenderer } = require('electron')
const listenToWindowBtn = document.getElementById('listen-to-window')
const focusModalBtn = document.getElementById('focus-on-modal-window')
const hideFocusBtn = () => {
focusModalBtn.classList.add('disappear')
focusModalBtn.classList.remove('smooth-appear')
focusModalBtn.removeEventListener('click', focusWindow)
}
const showFocusBtn = (btn) => {
focusModalBtn.classList.add('smooth-appear')
focusModalBtn.classList.remove('disappear')
focusModalBtn.addEventListener('click', focusWindow)
}
const focusWindow = () => {
ipcRenderer.send('focus-demo-window')
}
ipcRenderer.on('window-focus', hideFocusBtn)
ipcRenderer.on('window-close', hideFocusBtn)
ipcRenderer.on('window-blur', showFocusBtn)
listenToWindowBtn.addEventListener('click', () => {
ipcRenderer.send('show-demo-window')
})
const links = document.querySelectorAll('a[href]')
for (const link of links) {
const url = link.getAttribute('href')
if (url.indexOf('http') === 0) {
link.addEventListener('click', (e) => {
e.preventDefault()
shell.openExternal(url)
})
}
}