sneedium/preload.js

27 lines
882 B
JavaScript
Raw Normal View History

2023-03-02 15:42:38 -06:00
/**
* The preload script runs before. It has access to web APIs
* as well as Electron's renderer process modules and some
* polyfilled Node.js functions.
*
* https://www.electronjs.org/docs/latest/tutorial/sandbox
*/
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
2023-03-09 05:25:24 -06:00
const { ipcRenderer } = require('electron')
ipcRenderer.on('windowmaker', (event, arg) => {
console.log(arg) // prints "pong"
})
//button and its event listener
const makeWindowButton = document.getElementById('nwBtn');
makeWindowButton.addEventListener('click', () => {
ipcRenderer.send('windowmaker', 'ping')
})
2023-03-02 15:42:38 -06:00
})