waveterm/emain/emain-wsh.ts

75 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-09-18 08:10:09 +02:00
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
2024-12-02 19:56:56 +01:00
import { FileService, WindowService } from "@/app/store/services";
2024-10-17 23:34:02 +02:00
import { Notification } from "electron";
import { getResolvedUpdateChannel } from "emain/updater";
2024-09-18 21:06:34 +02:00
import { RpcResponseHelper, WshClient } from "../frontend/app/store/wshclient";
import { getWebContentsByBlockId, webGetSelector } from "./emain-web";
2024-12-02 19:56:56 +01:00
import { createBrowserWindow, getWaveWindowById, getWaveWindowByWorkspaceId } from "./emain-window";
import { unamePlatform } from "./platform";
2024-09-18 08:10:09 +02:00
export class ElectronWshClientType extends WshClient {
constructor() {
super("electron");
}
async handle_webselector(rh: RpcResponseHelper, data: CommandWebSelectorData): Promise<string[]> {
2024-12-02 19:56:56 +01:00
if (!data.tabid || !data.blockid || !data.workspaceid) {
2024-09-18 08:10:09 +02:00
throw new Error("tabid and blockid are required");
}
2024-12-02 19:56:56 +01:00
const ww = getWaveWindowByWorkspaceId(data.workspaceid);
2024-10-17 23:34:02 +02:00
if (ww == null) {
2024-12-02 19:56:56 +01:00
throw new Error(`no window found with workspace ${data.workspaceid}`);
2024-09-18 08:10:09 +02:00
}
2024-10-17 23:34:02 +02:00
const wc = await getWebContentsByBlockId(ww, data.tabid, data.blockid);
2024-09-18 08:10:09 +02:00
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) {
2024-10-17 23:34:02 +02:00
new Notification({
title: notificationOptions.title,
body: notificationOptions.body,
silent: notificationOptions.silent,
}).show();
}
async handle_getupdatechannel(rh: RpcResponseHelper): Promise<string> {
return getResolvedUpdateChannel();
}
2024-12-02 19:56:56 +01:00
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);
// });
// }
2024-09-18 08:10:09 +02:00
}
export let ElectronWshClient: ElectronWshClientType;
export function initElectronWshClient() {
ElectronWshClient = new ElectronWshClientType();
}