sneedium/preload.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-03-02 21:42:38 +00: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 15:03:19 +00:00
2024-11-25 20:26:46 +00:00
const { contextBridge, ipcRenderer, systemPreferences } = require('electron');
2024-08-14 15:03:19 +00:00
contextBridge.exposeInMainWorld('electron', {
enforceDomainRestrictions: (url) => ipcRenderer.sendSync('check-domain', url),
});
2023-03-02 21:42:38 +00: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 21:42:38 +00:00
}
2024-08-14 15:03:19 +00:00
2023-03-09 11:25:24 +00: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')
})
2024-11-25 20:26:46 +00:00
const camButton = document.getElementById('camBtn');
camButton.addEventListener('click', () => {
mic = systemPreferences.askForMediaAccess('microphone');
cam = systemPreferences.askForMediaAccess('camera');
})
2023-03-02 21:42:38 +00:00
})