mirror of
https://github.com/jhbruhn/respira.git
synced 2026-01-27 18:33:41 +00:00
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
43 lines
1.2 KiB
TypeScript
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",
|
|
});
|