waveterm/emain/preload.ts

28 lines
1.1 KiB
TypeScript
Raw Normal View History

// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
let { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("api", {
getPlatform: () => ipcRenderer.sendSync("getPlatform"),
getCursorPoint: () => ipcRenderer.sendSync("getCursorPoint"),
2024-06-20 00:42:19 +02:00
openNewWindow: () => ipcRenderer.send("openNewWindow"),
showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position),
onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", callback),
downloadFile: (filePath) => ipcRenderer.send("download", { filePath }),
2024-06-28 03:09:30 +02:00
openExternal: (url) => {
if (url && typeof url === "string") {
ipcRenderer.send("open-external", url);
} else {
console.error("Invalid URL passed to openExternal:", url);
}
},
getEnv: (varName) => ipcRenderer.sendSync("getEnv", varName),
2024-06-28 03:09:30 +02:00
});
// Custom event for "new-window"
ipcRenderer.on("webview-new-window", (e, webContentsId, details) => {
const event = new CustomEvent("new-window", { detail: details });
document.getElementById("webview").dispatchEvent(event);
});