waveterm/emain/emain-wsh.ts

44 lines
1.5 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-10-17 23:34:02 +02:00
import { Notification } from "electron";
import { getWaveWindowById } from "emain/emain-viewmgr";
2024-09-18 21:06:34 +02:00
import { RpcResponseHelper, WshClient } from "../frontend/app/store/wshclient";
import { getWebContentsByBlockId, webGetSelector } from "./emain-web";
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[]> {
if (!data.tabid || !data.blockid || !data.windowid) {
throw new Error("tabid and blockid are required");
}
2024-10-17 23:34:02 +02:00
const ww = getWaveWindowById(data.windowid);
if (ww == null) {
2024-09-18 08:10:09 +02:00
throw new Error(`no window found with id ${data.windowid}`);
}
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();
}
2024-09-18 08:10:09 +02:00
}
export let ElectronWshClient: ElectronWshClientType;
export function initElectronWshClient() {
ElectronWshClient = new ElectronWshClientType();
}