diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 3fc0cbf..2dbc32b 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -1 +1,13 @@ -console.log("---- electron/preload.ts ----"); +import { contextBridge, shell } from "electron"; +import fs from "node:fs"; + +import { IElectronAPI } from "../../src/types/global"; + +const Api: IElectronAPI = { + fileExists: fs.existsSync, + getPlatform: () => process.platform, + openFile: shell.openPath, + showFile: shell.showItemInFolder, +}; + +contextBridge.exposeInMainWorld("electronAPI", Api); diff --git a/src/types/global.d.ts b/src/types/global.d.ts new file mode 100644 index 0000000..c8a0a35 --- /dev/null +++ b/src/types/global.d.ts @@ -0,0 +1,12 @@ +export interface IElectronAPI { + fileExists: (path: string) => boolean; + getPlatform: () => string; + openFile: (path: string) => Promise; + showFile: (path: string) => void; +} + +declare global { + interface Window { + electronAPI?: IElectronAPI; + } +}