sneedium/preload.js

27 lines
878 B
JavaScript
Raw Permalink 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']) {
2024-08-12 15:43:29 -05:00
replaceText(`${type}-version`, 'fstopium-version')
2023-03-02 15:42:38 -06:00
}
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
})