diff --git a/.superset/setup.sh b/.superset/setup.sh index a924fbcb3ba..53dc3adaa5d 100755 --- a/.superset/setup.sh +++ b/.superset/setup.sh @@ -447,6 +447,32 @@ https://localhost:{\$CADDY_ELECTRIC_PORT} { CADDYEOF success "Caddyfile written" + # Generate .superset/ports.json for static port name mapping in the desktop app + if [ -n "${SUPERSET_PORT_BASE:-}" ]; then + local superset_dir + superset_dir="$(dirname "$0")" + cat > "$superset_dir/ports.json" < { }; }); }), + + subscribeAllStatic: publicProcedure.subscription(() => { + return observable<{ type: "change"; workspaceId: string }>((emit) => { + const allWorkspaces = localDb.select().from(workspaces).all(); + const watchedIds: string[] = []; + + for (const workspace of allWorkspaces) { + const workspacePath = getWorkspacePath(workspace); + if (!workspacePath) continue; + + staticPortsWatcher.watch(workspace.id, workspacePath); + watchedIds.push(workspace.id); + } + + const onChange = (changedWorkspaceId: string) => { + emit.next({ type: "change", workspaceId: changedWorkspaceId }); + }; + + staticPortsWatcher.on("change", onChange); + + return () => { + staticPortsWatcher.off("change", onChange); + for (const id of watchedIds) { + staticPortsWatcher.unwatch(id); + } + }; + }); + }), }); }; diff --git a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/PortsList/hooks/usePortsData.ts b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/PortsList/hooks/usePortsData.ts index 22510c65859..aa5c11457c1 100644 --- a/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/PortsList/hooks/usePortsData.ts +++ b/apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/PortsList/hooks/usePortsData.ts @@ -23,15 +23,12 @@ export function usePortsData() { const { data: allStaticPortsData } = electronTrpc.ports.getAllStatic.useQuery(); - // Subscribe to all static port changes - electronTrpc.ports.subscribeStatic.useSubscription( - { workspaceId: "" }, - { - onData: () => { - utils.ports.getAllStatic.invalidate(); - }, + // Subscribe to all static port changes across all workspaces + electronTrpc.ports.subscribeAllStatic.useSubscription(undefined, { + onData: () => { + utils.ports.getAllStatic.invalidate(); }, - ); + }); const { data: initialPorts } = electronTrpc.ports.getAll.useQuery();