diff --git a/package.json b/package.json index 56b7fb6..6f51e4b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.kunkun.sh", "name": "kunkun-ext-wol", - "version": "0.0.7", + "version": "0.0.8", "license": "MIT", "type": "module", "repository": { diff --git a/src/wake.ts b/src/wake.ts index c1cc51f..121c798 100644 --- a/src/wake.ts +++ b/src/wake.ts @@ -51,18 +51,14 @@ async function getRpcAPI() { class WakeOnLan extends WorkerExtension { private hosts: WakeOnLanHost[] = []; - private rpc?: { - api: API; - rpcChannel: RPCChannel; - process: Child; - command: DenoCommand; - }; - onListItemSelected(name: string): Promise { + async onListItemSelected(name: string): Promise { + const rpc = await getRpcAPI(); + const host = this.hosts.find((host) => host.name === name); if (host) { console.log("host on list item selected", host); - this.rpc?.api + rpc?.api .wakeOnLan(host.mac, host.ip, host.port) .then(() => { toast.success("Host waked", { @@ -73,15 +69,14 @@ class WakeOnLan extends WorkerExtension { toast.error("Failed to wake host", { description: err.message, }); + }) + .finally(() => { + rpc?.process.kill(); }); } return Promise.resolve(); } - async onBeforeGoBack(): Promise { - this.rpc?.process.kill(); - } - onActionSelected(value: string): Promise { const action = JSON.parse(value); if (action.action === "delete") { @@ -104,7 +99,6 @@ class WakeOnLan extends WorkerExtension { } async load() { - this.rpc = await getRpcAPI(); const hosts = await db.search({ dataType: WakeOnLanHostType, fields: ["data", "search_text"],