mirror of
https://github.com/kunkunsh/kunkun-ext-wol.git
synced 2025-04-04 10:26:41 +00:00
refactor: optimize RPC handling and wake on lan process management
This commit is contained in:
parent
cc5c0a039d
commit
dbd27233be
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.kunkun.sh",
|
"$schema": "https://schema.kunkun.sh",
|
||||||
"name": "kunkun-ext-wol",
|
"name": "kunkun-ext-wol",
|
||||||
"version": "0.0.7",
|
"version": "0.0.8",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
20
src/wake.ts
20
src/wake.ts
@ -51,18 +51,14 @@ async function getRpcAPI() {
|
|||||||
|
|
||||||
class WakeOnLan extends WorkerExtension {
|
class WakeOnLan extends WorkerExtension {
|
||||||
private hosts: WakeOnLanHost[] = [];
|
private hosts: WakeOnLanHost[] = [];
|
||||||
private rpc?: {
|
|
||||||
api: API;
|
|
||||||
rpcChannel: RPCChannel<object, API>;
|
|
||||||
process: Child;
|
|
||||||
command: DenoCommand<string>;
|
|
||||||
};
|
|
||||||
|
|
||||||
onListItemSelected(name: string): Promise<void> {
|
async onListItemSelected(name: string): Promise<void> {
|
||||||
|
const rpc = await getRpcAPI();
|
||||||
|
|
||||||
const host = this.hosts.find((host) => host.name === name);
|
const host = this.hosts.find((host) => host.name === name);
|
||||||
if (host) {
|
if (host) {
|
||||||
console.log("host on list item selected", host);
|
console.log("host on list item selected", host);
|
||||||
this.rpc?.api
|
rpc?.api
|
||||||
.wakeOnLan(host.mac, host.ip, host.port)
|
.wakeOnLan(host.mac, host.ip, host.port)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success("Host waked", {
|
toast.success("Host waked", {
|
||||||
@ -73,15 +69,14 @@ class WakeOnLan extends WorkerExtension {
|
|||||||
toast.error("Failed to wake host", {
|
toast.error("Failed to wake host", {
|
||||||
description: err.message,
|
description: err.message,
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
rpc?.process.kill();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
async onBeforeGoBack(): Promise<void> {
|
|
||||||
this.rpc?.process.kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
onActionSelected(value: string): Promise<void> {
|
onActionSelected(value: string): Promise<void> {
|
||||||
const action = JSON.parse(value);
|
const action = JSON.parse(value);
|
||||||
if (action.action === "delete") {
|
if (action.action === "delete") {
|
||||||
@ -104,7 +99,6 @@ class WakeOnLan extends WorkerExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
this.rpc = await getRpcAPI();
|
|
||||||
const hosts = await db.search({
|
const hosts = await db.search({
|
||||||
dataType: WakeOnLanHostType,
|
dataType: WakeOnLanHostType,
|
||||||
fields: ["data", "search_text"],
|
fields: ["data", "search_text"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user