Files
Netcatty/application/state/monitorRuntimeStore.ts
T
陈大猫 bace30578c feat: add synced custom host monitoring panels (#3703)
* feat: add synced custom host monitoring panels

* fix: preserve shared monitoring demand and complete terminal stats

* fix: transfer queued monitoring prompts when a window closes

* fix: keep reused hosts sampling while authentication is queued

* docs: record monitoring acceptance evidence

* fix: transfer pending monitoring auth after panel stop

* fix: release monitor owners in direct SSH runtime

* fix: keep worker monitoring sender compatibility

* fix: include monitoring configuration in automatic sync

* fix: disambiguate independent synced monitoring panel names

* test: assert existing panel order after cloud merge

* test: model browser locks and await monitoring state on Node 22
2026-10-17 15:05:30 +08:00

48 lines
1.1 KiB
TypeScript

import { useSyncExternalStore } from "react";
import type { MonitorSnapshot } from "../../domain/monitorRuntime";
const empty: MonitorSnapshot = {
running: [],
count: 0,
hostCount: 0,
epoch: 0,
runtimeId: "",
takenAt: 0,
activeSessions: [],
hosts: {},
};
let snapshot = empty;
const listeners = new Set<() => void>();
export function publishMonitorSnapshot(next: MonitorSnapshot) {
snapshot = next;
for (const l of listeners) l();
}
export function publishMonitorUnavailable() {
publishMonitorSnapshot({ ...empty, unavailable: true });
}
export function useMonitorSnapshot() {
return useSyncExternalStore(
(l) => {
listeners.add(l);
return () => {
listeners.delete(l);
};
},
() => snapshot,
() => empty,
);
}
export const monitorActions: {
start: (id: string) => void;
stop: (id: string) => void;
stopAll: () => void;
retry: (
id: string,
credentials?: { username: string; password: string },
) => void;
} = {
start: () => {},
stop: () => {},
stopAll: () => {},
retry: () => {},
};