2024-06-14 01:49:25 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-09-10 21:50:55 +02:00
|
|
|
import { contextBridge, ipcRenderer, WebviewTag } from "electron";
|
2024-06-14 01:49:25 +02:00
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld("api", {
|
2024-08-22 00:04:39 +02:00
|
|
|
getAuthKey: () => ipcRenderer.sendSync("get-auth-key"),
|
|
|
|
getIsDev: () => ipcRenderer.sendSync("get-is-dev"),
|
|
|
|
getPlatform: () => ipcRenderer.sendSync("get-platform"),
|
|
|
|
getCursorPoint: () => ipcRenderer.sendSync("get-cursor-point"),
|
2024-08-28 03:49:49 +02:00
|
|
|
getUserName: () => ipcRenderer.sendSync("get-user-name"),
|
2024-09-06 03:54:12 +02:00
|
|
|
getHostName: () => ipcRenderer.sendSync("get-host-name"),
|
Update data and config paths to match platform defaults (#1047)
Going forward for new installations, config and data files will be
stored at the platform default paths, as defined by
[env-paths](https://www.npmjs.com/package/env-paths).
For backwards compatibility, if the `~/.waveterm` or `WAVETERM_HOME`
directory exists and contains valid data, it will be used. If this check
fails, then `WAVETERM_DATA_HOME` and `WAVETERM_CONFIG_HOME` will be
used. If these are not defined, then `XDG_DATA_HOME` and
`XDG_CONFIG_HOME` will be used. Finally, if none of these are defined,
the [env-paths](https://www.npmjs.com/package/env-paths) defaults will
be used.
As with the existing app, dev instances will write to `waveterm-dev`
directories, while all others will write to `waveterm`.
2024-10-22 18:26:58 +02:00
|
|
|
getDataDir: () => ipcRenderer.sendSync("get-data-dir"),
|
2024-10-22 01:51:18 +02:00
|
|
|
getConfigDir: () => ipcRenderer.sendSync("get-config-dir"),
|
2024-09-04 06:45:44 +02:00
|
|
|
getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"),
|
2024-10-04 05:28:05 +02:00
|
|
|
getDocsiteUrl: () => ipcRenderer.sendSync("get-docsite-url"),
|
2024-10-05 01:34:05 +02:00
|
|
|
getWebviewPreload: () => ipcRenderer.sendSync("get-webview-preload"),
|
2024-08-22 00:04:39 +02:00
|
|
|
openNewWindow: () => ipcRenderer.send("open-new-window"),
|
2024-12-07 04:10:34 +01:00
|
|
|
showContextMenu: (workspaceId, menu) => ipcRenderer.send("contextmenu-show", workspaceId, menu),
|
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-08-22 00:04:39 +02:00
|
|
|
getEnv: (varName) => ipcRenderer.sendSync("get-env", 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"),
|
2024-09-18 23:25:52 +02:00
|
|
|
getUpdaterChannel: () => ipcRenderer.sendSync("get-updater-channel"),
|
2024-08-06 20:05:26 +02:00
|
|
|
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-08-30 01:06:15 +02:00
|
|
|
onReinjectKey: (callback) => ipcRenderer.on("reinject-key", (_event, waveEvent) => callback(waveEvent)),
|
|
|
|
setWebviewFocus: (focused: number) => ipcRenderer.send("webview-focus", focused),
|
|
|
|
registerGlobalWebviewKeys: (keys) => ipcRenderer.send("register-global-webview-keys", keys),
|
|
|
|
onControlShiftStateUpdate: (callback) =>
|
|
|
|
ipcRenderer.on("control-shift-state-update", (_event, state) => callback(state)),
|
2024-12-07 00:33:00 +01:00
|
|
|
createWorkspace: () => ipcRenderer.send("create-workspace"),
|
2024-12-02 19:56:56 +01:00
|
|
|
switchWorkspace: (workspaceId) => ipcRenderer.send("switch-workspace", workspaceId),
|
|
|
|
deleteWorkspace: (workspaceId) => ipcRenderer.send("delete-workspace", workspaceId),
|
2024-10-17 23:34:02 +02:00
|
|
|
setActiveTab: (tabId) => ipcRenderer.send("set-active-tab", tabId),
|
|
|
|
createTab: () => ipcRenderer.send("create-tab"),
|
2024-12-06 03:26:20 +01:00
|
|
|
closeTab: (workspaceId, tabId) => ipcRenderer.send("close-tab", workspaceId, tabId),
|
2024-10-17 23:34:02 +02:00
|
|
|
setWindowInitStatus: (status) => ipcRenderer.send("set-window-init-status", status),
|
|
|
|
onWaveInit: (callback) => ipcRenderer.on("wave-init", (_event, initOpts) => callback(initOpts)),
|
|
|
|
sendLog: (log) => ipcRenderer.send("fe-log", log),
|
2024-10-10 00:12:20 +02:00
|
|
|
onQuicklook: (filePath: string) => ipcRenderer.send("quicklook", filePath),
|
2024-10-31 20:34:30 +01:00
|
|
|
openNativePath: (filePath: string) => ipcRenderer.send("open-native-path", filePath),
|
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
|
|
|
});
|
2024-09-10 21:50:55 +02:00
|
|
|
|
|
|
|
ipcRenderer.on("webcontentsid-from-blockid", (e, blockId, responseCh) => {
|
|
|
|
const webviewElem: WebviewTag = document.querySelector("div[data-blockid='" + blockId + "'] webview");
|
|
|
|
const wcId = webviewElem?.dataset?.webcontentsid;
|
|
|
|
ipcRenderer.send(responseCh, wcId);
|
|
|
|
});
|