Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

preload.ts

16 lines824 Bytes

1import { contextBridge, ipcRenderer } from "electron";
2​
3const PICK_FOLDER_CHANNEL = "desktop:pick-folder";
4const CONFIRM_CHANNEL = "desktop:confirm";
5const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
6const OPEN_EXTERNAL_CHANNEL = "desktop:open-external";
7const wsUrl = process.env.T3CODE_DESKTOP_WS_URL ?? null;
8​
9contextBridge.exposeInMainWorld("desktopBridge", {
10 getWsUrl: () => wsUrl,
11 pickFolder: () => ipcRenderer.invoke(PICK_FOLDER_CHANNEL) as Promise<string | null>,
12 confirm: (message: string) => ipcRenderer.invoke(CONFIRM_CHANNEL, message) as Promise<boolean>,
13 showContextMenu: (items: { id: string; label: string }[]) =>
14 ipcRenderer.invoke(CONTEXT_MENU_CHANNEL, items) as Promise<string | null>,
15 openExternal: (url: string) => ipcRenderer.invoke(OPEN_EXTERNAL_CHANNEL, url) as Promise<boolean>,
16});