respira/electron/preload.ts
Jan-Henrik Bruhn a253901fb4
Some checks are pending
Build, Test, and Lint / Build, Test, and Lint (push) Waiting to run
Draft Release / Draft Release (push) Waiting to run
Draft Release / Build Web App (push) Blocked by required conditions
Draft Release / Build Release - macos-latest (push) Blocked by required conditions
Draft Release / Build Release - ubuntu-latest (push) Blocked by required conditions
Draft Release / Build Release - windows-latest (push) Blocked by required conditions
Draft Release / Upload to GitHub Release (push) Blocked by required conditions
fix: run linter
2025-12-18 11:39:22 +01:00

43 lines
1.2 KiB
TypeScript

import { contextBridge, ipcRenderer } from "electron";
// Expose protected methods that allow the renderer process to use
// ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld("electronAPI", {
invoke: (channel: string, ...args: unknown[]) => {
const validChannels = [
"storage:savePattern",
"storage:getPattern",
"storage:getLatest",
"storage:deletePattern",
"storage:clear",
"dialog:openFile",
"dialog:saveFile",
"fs:readFile",
"fs:writeFile",
];
if (validChannels.includes(channel)) {
return ipcRenderer.invoke(channel, ...args);
}
throw new Error(`Invalid IPC channel: ${channel}`);
},
// Bluetooth device selection
onBluetoothDeviceList: (
callback: (
devices: Array<{ deviceId: string; deviceName: string }>,
) => void,
) => {
ipcRenderer.on("bluetooth:device-list", (_event, devices) =>
callback(devices),
);
},
selectBluetoothDevice: (deviceId: string) => {
ipcRenderer.send("bluetooth:select-device", deviceId);
},
});
// Also expose process type for platform detection
contextBridge.exposeInMainWorld("process", {
type: "renderer",
});