discord-sandboxed/preload.js
2019-10-19 20:38:47 -07:00

46 lines
1.2 KiB
JavaScript

const { ipcRenderer } = require('electron')
window.addEventListener("DOMContentLoaded", () => {
ipcRenderer.send('asynchronous-message', 'DOMready')
})
// Send commands from main to renderer
ipcRenderer.on('devMode', (event, msg) => {
console.log(`Dev Mode: ${msg}`)
window.postMessage({ type: "devMode", text: `${msg}` }, "*")
})
ipcRenderer.on('micOpen', (event, msg) => {
window.postMessage({ type: "micOpen"}, "*")
})
ipcRenderer.on('micClose', (event, msg) => {
window.postMessage({ type: "micClose"}, "*")
})
// Handle events sent from renderer, sends it to main
window.addEventListener(
"message",
event => {
if (event.origin === "file://" && event.source === window) {
if (event.data.type === 'connected'){
ipcRenderer.send('asynchronous-message', 'connected')
}
if (event.data.type === 'disconnected'){
ipcRenderer.send('asynchronous-message', 'disconnected')
}
if (event.data.type === 'self-muted'){
ipcRenderer.send('asynchronous-message', 'self-muted')
}
if (event.data.type === 'self-unmuted'){
ipcRenderer.send('asynchronous-message', 'self-unmuted')
}
}
},
false
)