add some initial API code

This commit is contained in:
Richard Unger
2024-01-27 22:01:16 +01:00
parent 001173d61a
commit 88f2cad3e5
6 changed files with 100 additions and 13 deletions

View File

@@ -1,2 +1,22 @@
// See the Electron documentation for details on how to use preload scripts:
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
const { contextBridge, ipcRenderer } = require('electron')
// expose an API to choose available devices
contextBridge.exposeInMainWorld('nanodevices', {
list() { ipcRenderer.invoke('nanodevices:list'); },
connect(devicename) { ipcRenderer.invoke('nanodevices:connect', devicename); },
disconnect() { ipcRenderer.invoke('nanodevices:disconnect'); },
on_device_attached(listener) { ipcRenderer.on('nanodevice-attached', (_event, value) => listener(value)); },
on_device_detached(listener) { ipcRenderer.on('nanodevice-detached', (_event, value) => listener(value)); },
});
// expose an API to communicate with the nano device
contextBridge.exposeInMainWorld('nanodevice', {
get_value(pid, tid, vid){ ipcRenderer.invoke('nano:get', pid, tid, vid); },
set_value(pid, tid, vid, value){ ipcRenderer.invoke('nano:set', pid, tid, vid, value); },
on_value(listener){ ipcRenderer.on('nano-onvalue', (_event, value) => listener(value)); }
});