Files
geo/apps/desktop-client/src/main/runtime-events.ts
T

39 lines
899 B
TypeScript
Raw Normal View History

type RuntimeInvalidationReason = "account-health";
type RuntimeInvalidationListener = (event: {
reason: RuntimeInvalidationReason;
at: number;
accountId?: string;
}) => void;
const listeners = new Set<RuntimeInvalidationListener>();
export function emitRuntimeInvalidated(
reason: RuntimeInvalidationReason,
details: { accountId?: string } = {},
): void {
const event = {
reason,
at: Date.now(),
...details,
} as const;
for (const listener of listeners) {
try {
listener(event);
} catch (error) {
console.warn("[desktop-runtime] invalidation listener failed", {
reason,
message: error instanceof Error ? error.message : String(error),
});
}
}
}
export function onRuntimeInvalidated(listener: RuntimeInvalidationListener): () => void {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}