electron/docs/fiddles/windows/manage-windows/window-events/renderer.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

const { shell, ipcRenderer } = require('electron')
2020-08-27 14:31:51 +00:00
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)
2020-08-27 14:31:51 +00:00
listenToWindowBtn.addEventListener('click', () => {
ipcRenderer.send('show-demo-window')
2020-08-27 14:31:51 +00:00
})
const links = document.querySelectorAll('a[href]')
2020-08-27 14:31:51 +00:00
Array.prototype.forEach.call(links, (link) => {
const url = link.getAttribute('href')
if (url.indexOf('http') === 0) {
link.addEventListener('click', (e) => {
e.preventDefault()
shell.openExternal(url)
})
}
})