-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreload.js
27 lines (21 loc) · 1003 Bytes
/
preload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
const { contextBridge, ipcRenderer } = require("electron")
contextBridge.exposeInMainWorld('myapi', {
leftClick: async (data) => await ipcRenderer.invoke('leftClick', data),
up: async (data) => await ipcRenderer.invoke('up', data),
down: async (data) => await ipcRenderer.invoke('down', data),
drag: async (data) => await ipcRenderer.invoke('drag', data),
pressKey: async (data) => await ipcRenderer.invoke('pressKey', data),
releaseKey: async (data) => await ipcRenderer.invoke('releaseKey', data)
}
)
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
})