2025-10-29 23:59:13 +08:00
|
|
|
import { contextBridge, ipcRenderer } from "electron";
|
2023-11-23 18:28:53 +08:00
|
|
|
import { electronAPI } from "@electron-toolkit/preload";
|
|
|
|
|
|
2024-09-26 11:57:23 +08:00
|
|
|
// Use `contextBridge` APIs to expose Electron APIs to
|
|
|
|
|
// renderer only if context isolation is enabled, otherwise
|
|
|
|
|
// just add to the DOM global.
|
2023-11-23 18:28:53 +08:00
|
|
|
if (process.contextIsolated) {
|
|
|
|
|
try {
|
|
|
|
|
contextBridge.exposeInMainWorld("electron", electronAPI);
|
2025-10-29 23:59:13 +08:00
|
|
|
// Expose store API via preload
|
|
|
|
|
contextBridge.exposeInMainWorld("api", {
|
|
|
|
|
store: {
|
|
|
|
|
get: (key: string) => ipcRenderer.invoke("store-get", key),
|
|
|
|
|
set: (key: string, value: unknown) => ipcRenderer.invoke("store-set", key, value),
|
|
|
|
|
has: (key: string) => ipcRenderer.invoke("store-has", key),
|
|
|
|
|
delete: (key: string) => ipcRenderer.invoke("store-delete", key),
|
|
|
|
|
reset: (keys?: string[]) => ipcRenderer.invoke("store-reset", keys),
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-11-23 18:28:53 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|