sneedium/preload.js

35 lines
1 KiB
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
*/
2024-08-14 10:03:19 -05:00
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electron', {
enforceDomainRestrictions: (url) => ipcRenderer.sendSync('check-domain', url),
});
2023-03-02 15:42:38 -06:00
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`, 'sneedium-version')
2023-03-02 15:42:38 -06:00
}
2024-08-14 10:03:19 -05:00
2023-03-09 05:25:24 -06:00
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
})