2024-06-14 01:49:25 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-07-23 21:42:31 +02:00
|
|
|
const { contextBridge, ipcRenderer } = require("electron");
|
2024-06-14 01:49:25 +02:00
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld("api", {
|
2024-08-01 22:46:06 +02:00
|
|
|
getIsDev: () => ipcRenderer.sendSync("getIsDev"),
|
2024-06-21 21:32:38 +02:00
|
|
|
getPlatform: () => ipcRenderer.sendSync("getPlatform"),
|
2024-06-19 20:15:14 +02:00
|
|
|
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),
|
2024-07-22 22:33:10 +02:00
|
|
|
onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", (_event, id) => callback(id)),
|
2024-06-26 21:14:59 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2024-07-18 03:42:49 +02:00
|
|
|
getEnv: (varName) => ipcRenderer.sendSync("getEnv", varName),
|
2024-07-22 22:33:10 +02:00
|
|
|
onFullScreenChange: (callback) =>
|
|
|
|
ipcRenderer.on("fullscreen-change", (_event, isFullScreen) => callback(isFullScreen)),
|
2024-08-06 20:05:26 +02:00
|
|
|
onUpdaterStatusChange: (callback) => ipcRenderer.on("app-update-status", (_event, status) => callback(status)),
|
|
|
|
getUpdaterStatus: () => ipcRenderer.sendSync("get-app-update-status"),
|
|
|
|
installAppUpdate: () => ipcRenderer.send("install-app-update"),
|
2024-08-20 00:49:40 +02:00
|
|
|
onMenuItemAbout: (callback) => ipcRenderer.on("menu-item-about", callback),
|
2024-08-19 23:16:09 +02:00
|
|
|
updateWindowControlsOverlay: (rect) => ipcRenderer.send("update-window-controls-overlay", rect),
|
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);
|
2024-06-14 01:49:25 +02:00
|
|
|
});
|