mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
72ea58267d
Adds a new app menu for creating a new workspace or switching to an existing one. This required adding a new WPS event any time a workspace gets updated, since the Electron app menus are static. This also fixes a bug where closing a workspace could delete it if it didn't have both a pinned and an unpinned tab.
75 lines
2.9 KiB
TypeScript
75 lines
2.9 KiB
TypeScript
// Copyright 2024, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { FileService, WindowService } from "@/app/store/services";
|
|
import { Notification } from "electron";
|
|
import { getResolvedUpdateChannel } from "emain/updater";
|
|
import { RpcResponseHelper, WshClient } from "../frontend/app/store/wshclient";
|
|
import { getWebContentsByBlockId, webGetSelector } from "./emain-web";
|
|
import { createBrowserWindow, getWaveWindowById, getWaveWindowByWorkspaceId } from "./emain-window";
|
|
import { unamePlatform } from "./platform";
|
|
|
|
export class ElectronWshClientType extends WshClient {
|
|
constructor() {
|
|
super("electron");
|
|
}
|
|
|
|
async handle_webselector(rh: RpcResponseHelper, data: CommandWebSelectorData): Promise<string[]> {
|
|
if (!data.tabid || !data.blockid || !data.workspaceid) {
|
|
throw new Error("tabid and blockid are required");
|
|
}
|
|
const ww = getWaveWindowByWorkspaceId(data.workspaceid);
|
|
if (ww == null) {
|
|
throw new Error(`no window found with workspace ${data.workspaceid}`);
|
|
}
|
|
const wc = await getWebContentsByBlockId(ww, data.tabid, data.blockid);
|
|
if (wc == null) {
|
|
throw new Error(`no webcontents found with blockid ${data.blockid}`);
|
|
}
|
|
const rtn = await webGetSelector(wc, data.selector, data.opts);
|
|
return rtn;
|
|
}
|
|
|
|
async handle_notify(rh: RpcResponseHelper, notificationOptions: WaveNotificationOptions) {
|
|
new Notification({
|
|
title: notificationOptions.title,
|
|
body: notificationOptions.body,
|
|
silent: notificationOptions.silent,
|
|
}).show();
|
|
}
|
|
|
|
async handle_getupdatechannel(rh: RpcResponseHelper): Promise<string> {
|
|
return getResolvedUpdateChannel();
|
|
}
|
|
|
|
async handle_focuswindow(rh: RpcResponseHelper, windowId: string) {
|
|
console.log(`focuswindow ${windowId}`);
|
|
const fullConfig = await FileService.GetFullConfig();
|
|
let ww = getWaveWindowById(windowId);
|
|
if (ww == null) {
|
|
const window = await WindowService.GetWindow(windowId);
|
|
if (window == null) {
|
|
throw new Error(`window ${windowId} not found`);
|
|
}
|
|
ww = await createBrowserWindow(window, fullConfig, { unamePlatform });
|
|
}
|
|
ww.focus();
|
|
}
|
|
|
|
// async handle_workspaceupdate(rh: RpcResponseHelper) {
|
|
// console.log("workspaceupdate");
|
|
// fireAndForget(async () => {
|
|
// console.log("workspace menu clicked");
|
|
// const updatedWorkspaceMenu = await getWorkspaceMenu();
|
|
// const workspaceMenu = Menu.getApplicationMenu().getMenuItemById("workspace-menu");
|
|
// workspaceMenu.submenu = Menu.buildFromTemplate(updatedWorkspaceMenu);
|
|
// });
|
|
// }
|
|
}
|
|
|
|
export let ElectronWshClient: ElectronWshClientType;
|
|
|
|
export function initElectronWshClient() {
|
|
ElectronWshClient = new ElectronWshClientType();
|
|
}
|