b16e9f0bd1
Plan 0 (workspaces): add workspaces + workspace_memberships schema, extend JWT/Actor/claims with primary_workspace_id, seed default workspace per tenant, thread workspace_id through tenant monitoring quota. Plan A (desktop skeleton): new Electron app (apps/desktop-client) with main/ preload/renderer, shared Vue component package (packages/ui-shared), and server surface — desktop client registration + token rotation + heartbeat, SSE task event stream, desktop accounts/tasks/content handlers, publish job endpoint, and supporting repositories, services, sqlc queries, and migrations. Hard cutover per plan: remove browser-extension monitoring callback endpoints, stub legacy media API in admin-web, and delete monitoring_callback_handler.go.
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
import { computed, onMounted, onUnmounted, readonly, shallowRef } from "vue";
|
|
|
|
import { createPreviewRuntimeSnapshot } from "../mock/runtime-preview";
|
|
import type { DesktopRuntimeSnapshot } from "../types";
|
|
|
|
const snapshot = shallowRef<DesktopRuntimeSnapshot | null>(null);
|
|
const loading = shallowRef(false);
|
|
const error = shallowRef<string | null>(null);
|
|
|
|
let intervalHandle: ReturnType<typeof setInterval> | null = null;
|
|
let subscribers = 0;
|
|
|
|
async function refreshRuntimeSnapshot() {
|
|
loading.value = true;
|
|
error.value = null;
|
|
|
|
try {
|
|
if (window.desktopBridge?.app?.runtimeSnapshot) {
|
|
snapshot.value = await window.desktopBridge.app.runtimeSnapshot();
|
|
return;
|
|
}
|
|
|
|
snapshot.value = createPreviewRuntimeSnapshot();
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : "runtime snapshot unavailable";
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
function startPolling() {
|
|
if (intervalHandle) {
|
|
return;
|
|
}
|
|
|
|
intervalHandle = setInterval(() => {
|
|
void refreshRuntimeSnapshot();
|
|
}, 15_000);
|
|
}
|
|
|
|
function stopPolling() {
|
|
if (subscribers > 0 || !intervalHandle) {
|
|
return;
|
|
}
|
|
|
|
clearInterval(intervalHandle);
|
|
intervalHandle = null;
|
|
}
|
|
|
|
export function useDesktopRuntime() {
|
|
onMounted(() => {
|
|
subscribers += 1;
|
|
if (!snapshot.value && !loading.value) {
|
|
void refreshRuntimeSnapshot();
|
|
}
|
|
startPolling();
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
subscribers = Math.max(0, subscribers - 1);
|
|
stopPolling();
|
|
});
|
|
|
|
return {
|
|
snapshot: readonly(snapshot),
|
|
loading: readonly(loading),
|
|
error: readonly(error),
|
|
refresh: refreshRuntimeSnapshot,
|
|
hasSnapshot: computed(() => snapshot.value !== null),
|
|
};
|
|
}
|