mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 14:45:24 +00:00
feat: plugins only see their own host settings in the browser
This commit is contained in:
1 parent
50d43e29fb
commit
fb9c168b6b
17 files changed
+488
-52
No files matched your search
@@ -5,11 +5,19 @@ import type {
|
||||
TermixApp,
|
||||
} from "@termix/plugin-sdk/frontend";
|
||||
|
||||
export function macAddressOf(
|
||||
host: Pick<PluginHostRecord, "pluginSettings"> | null | undefined,
|
||||
): string | null {
|
||||
const macAddress = host?.pluginSettings?.["wake-on-lan"]?.macAddress;
|
||||
return typeof macAddress === "string" && macAddress.trim()
|
||||
? macAddress.trim()
|
||||
: null;
|
||||
}
|
||||
|
||||
export function hasMacAddress(
|
||||
host: Pick<PluginHostRecord, "pluginSettings">,
|
||||
): boolean {
|
||||
const macAddress = host.pluginSettings?.["wake-on-lan"]?.macAddress;
|
||||
return typeof macAddress === "string" && macAddress.trim().length > 0;
|
||||
return macAddressOf(host) !== null;
|
||||
}
|
||||
|
||||
function errorMessage(error: unknown, fallback: string): string {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Zap } from "lucide-react";
|
||||
import type { TermixApp } from "@termix/plugin-sdk/frontend";
|
||||
import { hasMacAddress, wakeHost } from "./host-action.js";
|
||||
import { hasMacAddress, macAddressOf, wakeHost } from "./host-action.js";
|
||||
|
||||
export function activate(app: TermixApp): void {
|
||||
app.registerHostAction({
|
||||
@@ -12,4 +12,8 @@ export function activate(app: TermixApp): void {
|
||||
when: (host) => hasMacAddress(host),
|
||||
run: (host) => wakeHost(app.api, app.t, String(host.id)),
|
||||
});
|
||||
|
||||
// A saved host's MAC address, for plugins that send their own wake packet.
|
||||
app.registerAction("wakeOnLan.macAddress", ((hostId: string | number) =>
|
||||
macAddressOf(app.getHost(hostId))) as never);
|
||||
}
|
||||
Reference in new issue
Block a user