mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
// Copyright 2024, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
let { contextBridge, ipcRenderer } = require("electron");
|
|
|
|
contextBridge.exposeInMainWorld("api", {
|
|
isDev: () => ipcRenderer.sendSync("isDev"),
|
|
isDevServer: () => ipcRenderer.sendSync("isDevServer"),
|
|
getPlatform: () => ipcRenderer.sendSync("getPlatform"),
|
|
getCursorPoint: () => ipcRenderer.sendSync("getCursorPoint"),
|
|
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 }),
|
|
openExternal: (url) => {
|
|
if (url && typeof url === "string") {
|
|
ipcRenderer.send("open-external", url);
|
|
} else {
|
|
console.error("Invalid URL passed to openExternal:", url);
|
|
}
|
|
},
|
|
});
|
|
|
|
// 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);
|
|
});
|