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";
|
2024-11-01 18:20:15 +01:00
|
|
|
import { getResolvedUpdateChannel } from "emain/updater";
|
2024-09-18 21:06:34 +02:00
|
|
|
import { RpcResponseHelper, WshClient } from "../frontend/app/store/wshclient";
|
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
|
|
|
import { getWaveWindowById } from "./emain-viewmgr";
|
2024-09-18 21:06:34 +02:00
|
|
|
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;
|
|
|
|
}
|
2024-10-08 19:22:17 +02:00
|
|
|
|
|
|
|
async handle_notify(rh: RpcResponseHelper, notificationOptions: WaveNotificationOptions) {
|
2024-10-17 23:34:02 +02:00
|
|
|
new Notification({
|
2024-10-08 19:22:17 +02:00
|
|
|
title: notificationOptions.title,
|
|
|
|
body: notificationOptions.body,
|
|
|
|
silent: notificationOptions.silent,
|
|
|
|
}).show();
|
|
|
|
}
|
2024-11-01 18:20:15 +01:00
|
|
|
|
|
|
|
async handle_getupdatechannel(rh: RpcResponseHelper): Promise<string> {
|
|
|
|
return getResolvedUpdateChannel();
|
|
|
|
}
|
2024-09-18 08:10:09 +02:00
|
|
|
}
|
2024-09-19 20:04:18 +02:00
|
|
|
|
|
|
|
export let ElectronWshClient: ElectronWshClientType;
|
|
|
|
|
|
|
|
export function initElectronWshClient() {
|
|
|
|
ElectronWshClient = new ElectronWshClientType();
|
|
|
|
}
|