From 56139bc2c8806b1d51ab5feb50719b3f333769a3 Mon Sep 17 00:00:00 2001 From: egdev6 Date: Wed, 25 Nov 2026 11:53:41 +0100 Subject: [PATCH 1/2] fix(hub): wait for the observed app state after open and close requests Rescans no longer blank the installed list, and each app now shows an opening or closing state until a rescan confirms the change, the request fails, or a 15 s timeout warns that it could not be confirmed. --- apps/hub/src/App.test.tsx | 159 ++++++++++++++++++++++++++ apps/hub/src/App.tsx | 192 ++++++++++++++++++++++++++------ apps/hub/src/i18n/messages.json | 10 +- 3 files changed, 322 insertions(+), 39 deletions(-) diff --git a/apps/hub/src/App.test.tsx b/apps/hub/src/App.test.tsx index 1138a74..804a0bf 100644 --- a/apps/hub/src/App.test.tsx +++ b/apps/hub/src/App.test.tsx @@ -236,6 +236,165 @@ it('projects a native process observation into the official row and refreshes af expect(invoke).toHaveBeenCalledWith('close_official_app', { id: 'example-app' }); }); +function mockLiveApp(observe: () => Record, extra: (command: string) => unknown = () => undefined) { + vi.mocked(isTauri).mockReturnValue(true); + const app = { + ...fullCatalog.apps[0], + detection: { windows: { displayName: 'Example App', publisher: 'Example Publisher', executableRelativePath: 'Example.exe' } }, + }; + vi.spyOn(catalogLoader, 'loadCatalog').mockResolvedValue({ + status: 'ready', + catalog: { ...parseCatalog({ schemaVersion: 2, apps: [app] }), schemaVersion: 4 }, + }); + vi.mocked(invoke).mockImplementation(((command: string) => { + if (command === 'get_settings') + return Promise.resolve({ state: 'ready', settings: { ...defaultSettings, firstRunComplete: true, showNewsOnOpen: false, sources: [] } }); + if (command === 'plugin:autostart|is_enabled') return Promise.resolve(false); + if (command === 'platform_key') return Promise.resolve('windows-x86_64'); + if (command === 'read_catalog_v4_cache') return Promise.resolve(JSON.stringify(windowsCatalog([app]))); + if (command === 'installed_apps') return Promise.resolve([{ id: 'example-app', state: 'installed', version: '9.1.0', canOpen: true, ...observe() }]); + const handled = extra(command); + return handled === undefined ? Promise.resolve(null) : (handled as Promise); + }) as typeof invoke); +} +const scanCount = () => vi.mocked(invoke).mock.calls.filter(([command]) => command === 'installed_apps').length; + +it('keeps installed cards and their status visible while a rescan is in flight', async () => { + let hold = false; + let release!: () => void; + mockLiveApp(() => ({ runningState: 'running' })); + const base = vi.mocked(invoke).getMockImplementation(); + vi.mocked(invoke).mockImplementation(((command: string, args?: unknown) => { + if (command === 'installed_apps' && hold) + return new Promise((resolve) => { + release = () => resolve([{ id: 'example-app', state: 'installed', version: '9.1.0', canOpen: true, runningState: 'running' }]); + }); + return base?.(command, args as never); + }) as typeof invoke); + render(); + expect(await screen.findByText('Abierta')).toBeTruthy(); + hold = true; + fireEvent.click(screen.getByRole('button', { name: 'Actualizar apps' })); + await waitFor(() => expect(release).toBeTypeOf('function')); + expect(screen.getByText('Example App')).toBeTruthy(); + expect(screen.getByText('Abierta')).toBeTruthy(); + expect(screen.queryByText('Estado de instalación no disponible todavía.')).toBeNull(); + await act(async () => release()); + expect(screen.getByText('Abierta')).toBeTruthy(); +}); + +it('keeps an opening app pending until a rescan observes it running', async () => { + let scansUntilRunning = Number.POSITIVE_INFINITY; + mockLiveApp( + () => ({ runningState: scanCount() >= scansUntilRunning ? 'running' : 'notRunning' }), + (command) => { + if (command === 'open_official_app') { + scansUntilRunning = scanCount() + 2; + return Promise.resolve('Inicio solicitado; no hay confirmación de ejecución'); + } + }, + ); + render(); + expect(await screen.findByText('Cerrada')).toBeTruthy(); + fireEvent.click(screen.getByRole('button', { name: 'Abrir Example App' })); + expect(await screen.findByText('Abriendo…')).toBeTruthy(); + await waitFor(() => expect(scanCount()).toBeGreaterThanOrEqual(scansUntilRunning - 1)); + expect(screen.queryByText('Cerrada')).toBeNull(); + expect((screen.getByRole('button', { name: 'Abrir Example App' }) as HTMLButtonElement).disabled).toBe(true); + expect(await screen.findByText('Abierta', {}, { timeout: 4000 })).toBeTruthy(); + expect(screen.queryByText('Abriendo…')).toBeNull(); + expect((screen.getByRole('button', { name: 'Cerrar Example App' }) as HTMLButtonElement).disabled).toBe(false); +}); + +it('keeps a closing app pending until a rescan observes it stopped', async () => { + let scansUntilStopped = Number.POSITIVE_INFINITY; + mockLiveApp( + () => ({ runningState: scanCount() >= scansUntilStopped ? 'notRunning' : 'running' }), + (command) => { + if (command === 'close_official_app') { + scansUntilStopped = scanCount() + 2; + return Promise.resolve({ status: 'closed', message: 'Example App se ha cerrado.' }); + } + }, + ); + render(); + expect(await screen.findByText('Abierta')).toBeTruthy(); + fireEvent.click(screen.getByRole('button', { name: 'Cerrar Example App' })); + expect(await screen.findByText('Cerrando…')).toBeTruthy(); + expect(screen.queryByText('Abierta')).toBeNull(); + expect((screen.getByRole('button', { name: 'Cerrar Example App' }) as HTMLButtonElement).disabled).toBe(true); + expect(await screen.findByText('Cerrada', {}, { timeout: 4000 })).toBeTruthy(); + expect(screen.queryByText('Cerrando…')).toBeNull(); + expect((screen.getByRole('button', { name: 'Abrir Example App' }) as HTMLButtonElement).disabled).toBe(false); +}); + +it('stops waiting and warns when the state change is never observed', async () => { + vi.useFakeTimers({ shouldAdvanceTime: true }); + try { + mockLiveApp( + () => ({ runningState: 'notRunning' }), + (command) => (command === 'open_official_app' ? Promise.resolve('Inicio solicitado; no hay confirmación de ejecución') : undefined), + ); + render(); + expect(await screen.findByText('Cerrada')).toBeTruthy(); + fireEvent.click(screen.getByRole('button', { name: 'Abrir Example App' })); + expect(await screen.findByText('Abriendo…')).toBeTruthy(); + await act(async () => { + await vi.advanceTimersByTimeAsync(16000); + }); + expect(screen.queryByText('Abriendo…')).toBeNull(); + expect(screen.getByText('Cerrada')).toBeTruthy(); + const warning = screen.getByText('No se pudo confirmar el cambio de estado de Example App.').closest('.eg-notice'); + expect(warning?.getAttribute('data-tone')).toBe('warning'); + expect((screen.getByRole('button', { name: 'Abrir Example App' }) as HTMLButtonElement).disabled).toBe(false); + } finally { + vi.useRealTimers(); + } +}); + +it('ignores a late failure from an expired request while a newer one is pending', async () => { + vi.useFakeTimers({ shouldAdvanceTime: true }); + try { + const rejects: ((reason: unknown) => void)[] = []; + mockLiveApp( + () => ({ runningState: 'notRunning' }), + (command) => + command === 'open_official_app' + ? new Promise((_resolve, reject) => { + rejects.push(reject); + }) + : undefined, + ); + render(); + expect(await screen.findByText('Cerrada')).toBeTruthy(); + fireEvent.click(screen.getByRole('button', { name: 'Abrir Example App' })); + await act(async () => { + await vi.advanceTimersByTimeAsync(16000); + }); + fireEvent.click(screen.getByRole('button', { name: 'Abrir Example App' })); + expect(await screen.findByText('Abriendo…')).toBeTruthy(); + await act(async () => rejects[0]('Primer intento fallido')); + expect(screen.getByText('Abriendo…')).toBeTruthy(); + expect((screen.getByRole('button', { name: 'Abrir Example App' }) as HTMLButtonElement).disabled).toBe(true); + } finally { + vi.useRealTimers(); + } +}); + +it('clears the pending state and reports the error when opening fails', async () => { + mockLiveApp( + () => ({ runningState: 'notRunning' }), + (command) => (command === 'open_official_app' ? Promise.reject('No se pudo iniciar') : undefined), + ); + render(); + expect(await screen.findByText('Cerrada')).toBeTruthy(); + fireEvent.click(screen.getByRole('button', { name: 'Abrir Example App' })); + expect((await screen.findByRole('alert')).textContent).toContain('No se pudo iniciar'); + expect(screen.queryByText('Abriendo…')).toBeNull(); + expect(screen.getByText('Cerrada')).toBeTruthy(); + expect((screen.getByRole('button', { name: 'Abrir Example App' }) as HTMLButtonElement).disabled).toBe(false); +}); + it('ignores an older installation scan that resolves after a newer refresh', async () => { vi.mocked(isTauri).mockReturnValue(true); const app = { diff --git a/apps/hub/src/App.tsx b/apps/hub/src/App.tsx index 8545539..a64b3c1 100644 --- a/apps/hub/src/App.tsx +++ b/apps/hub/src/App.tsx @@ -12,6 +12,7 @@ import { IconButton, Notice, PageHeader, + Spinner, StatusDot, Tabs, Text, @@ -86,6 +87,19 @@ function MainTabsFrame({ children }: { children: ReactNode }) { /** Rescans after an app leaves the registry, measured from its departure. */ const DEPARTURE_RESCAN_DELAYS_MS = [2000, 6000]; +/** Rescan cadence while an open or close request waits for the observed state change. */ +const PENDING_RESCAN_INTERVAL_MS = 1500; +/** How long an open or close request may wait for its observed state change before warning. */ +const PENDING_TIMEOUT_MS = 15000; + +type PendingAction = 'opening' | 'closing'; +type PendingEntry = { action: PendingAction; name: string }; + +/** Whether the observed app state shows the pending action has taken effect. */ +function pendingSettled(action: PendingAction, app: HubApp | undefined, connected: boolean): boolean { + if (action === 'opening') return connected || app?.runningState === 'running' || app?.runningState === 'connected'; + return !connected && app?.runningState !== 'running' && app?.runningState !== 'connected'; +} function OpenAction({ app, onOpen, busy, stale }: { app: HubApp; onOpen?: (id: string) => void; busy: boolean; stale: boolean }) { const locale = useLocale(); @@ -126,8 +140,16 @@ function ProcessCloseAction({ app, onClose, busy, stale }: { app: HubApp; onClos ); } -function Status({ app }: { app: HubApp }) { +function Status({ app, pending }: { app: HubApp; pending?: PendingAction }) { const locale = useLocale(); + if (pending) + return ( + + + {t(locale, pending === 'opening' ? 'appControl.opening' : 'appControl.closing')} + + + ); if (app.installationState === 'installed') { if (app.runningState === 'running') return ( @@ -237,12 +259,14 @@ function ConnectedRow({ onOpen, onMenuAction, busy, + pending, catalogState, installs, open, onOpenChange, }: { app: RegistryApp; + pending?: PendingAction; official?: HubApp; onClose?: (id: string) => void; onOpen?: (id: string) => void; @@ -279,7 +303,13 @@ function ConnectedRow({ {app.app.name} - {app.responsive ? ( + {pending ? ( + + + {t(locale, pending === 'opening' ? 'appControl.opening' : 'appControl.closing')} + + + ) : app.responsive ? ( {t(locale, 'app.connected')} @@ -317,7 +347,8 @@ function ConnectedRow({ size="sm" variant="secondary" aria-label={t(locale, 'appControl.closeFor', { name: app.app.name })} - disabled={busy} + disabled={busy && pending !== 'closing'} + loading={pending === 'closing'} onClick={() => onClose(app.app.id)} > {t(locale, 'common.close')} @@ -368,6 +399,7 @@ function AppRow({ onOpen, onClose, busy, + pending, stale, catalogState, installs, @@ -378,6 +410,7 @@ function AppRow({ onOpen?: (id: string) => void; onClose?: (id: string) => void; busy: boolean; + pending?: PendingAction; stale: boolean; catalogState?: CatalogState; installs: CatalogInstalls; @@ -405,7 +438,7 @@ function AppRow({ {app.name} - + @@ -455,7 +488,7 @@ function InstalledPanel({ onProcessClose, onOpen, onMenuAction, - actionBusy, + pending, stale, hideLocalApps, localCycle, @@ -471,7 +504,7 @@ function InstalledPanel({ onMenuAction?: (app: RegistryApp, itemId: string) => void; onProcessClose?: (id: string) => void; onOpen?: (id: string) => void; - actionBusy: boolean; + pending: Readonly>; stale: boolean; hideLocalApps: boolean; localCycle?: number; @@ -502,7 +535,8 @@ function InstalledPanel({ onClose={onClose} onOpen={onOpen} onMenuAction={onMenuAction} - busy={actionBusy} + busy={!!pending[app.app.id]} + pending={pending[app.app.id]?.action} catalogState={catalogState} installs={installs} {...disclosure(`connected:${app.app.id}`)} @@ -530,7 +564,8 @@ function InstalledPanel({ app={app} onOpen={onOpen} onClose={onProcessClose} - busy={actionBusy} + busy={!!pending[app.id]} + pending={pending[app.id]?.action} stale={stale} catalogState={catalogState} installs={installs} @@ -638,35 +673,81 @@ export function FlyoutPanel({ useContentBackdrop(panelRef, native && hasBackdrop, motion.phase, motion.generation, shown.blur, shown.opacity); const [registry, setRegistry] = useState({ revision: 0, apps: [] }); const [registryFailed, setRegistryFailed] = useState(false); - const [actionBusy, setActionBusy] = useState(false); + const [pending, setPending] = useState>>({}); + const pendingTimers = useRef(new Map>()); + const pendingToken = useRef(0); + /** Latest request token per app; a response superseded by a newer request is ignored. */ + const pendingTokens = useRef(new Map()); const [actionMessage, setActionMessage] = useState<{ error: boolean; warning?: boolean; text: string; localize?: boolean; - key?: 'appControl.quitAccepted'; + key?: 'appControl.quitAccepted' | 'appControl.confirmTimeout'; + params?: Record; } | null>(null); - function openApp(id: string) { - setActionBusy(true); + const observed = useRef({ apps, registry }); + observed.current = { apps, registry }; + function endPending(id: string) { + clearTimeout(pendingTimers.current.get(id)); + pendingTimers.current.delete(id); + setPending((current) => { + if (!current[id]) return current; + const { [id]: _done, ...rest } = current; + return rest; + }); + } + /** Starts waiting for an app's state change and returns a check that the request is still the latest one. */ + function startPending(id: string, action: PendingAction): () => boolean { + const name = + observed.current.apps.find((app) => app.id === id)?.name ?? observed.current.registry.apps.find((entry) => entry.app.id === id)?.app.name ?? id; + const token = ++pendingToken.current; + pendingTokens.current.set(id, token); + clearTimeout(pendingTimers.current.get(id)); + pendingTimers.current.set( + id, + setTimeout(() => { + endPending(id); + setActionMessage({ error: false, warning: true, text: '', key: 'appControl.confirmTimeout', params: { name } }); + }, PENDING_TIMEOUT_MS), + ); + setPending((current) => ({ ...current, [id]: { action, name } })); setActionMessage(null); + return () => pendingTokens.current.get(id) === token; + } + /** Ends the wait when the app state cannot be observed, so no confirmation could ever arrive. */ + function endPendingIfUnobservable(id: string) { + const { apps: currentApps, registry: currentRegistry } = observed.current; + const connected = currentRegistry.apps.some((entry) => entry.app.id === id); + if (!connected && currentApps.find((app) => app.id === id)?.runningState === 'unknown') endPending(id); + } + function openApp(id: string) { + const latest = startPending(id, 'opening'); void openOfficialApp(id) - .then((text) => setActionMessage({ error: false, text, localize: true })) - .catch((error) => setActionMessage({ error: true, text: String(error), localize: true })) - .finally(() => { - setActionBusy(false); - onAppsRefresh?.(); - }); + .then((text) => { + if (!latest()) return; + setActionMessage({ error: false, text, localize: true }); + endPendingIfUnobservable(id); + }) + .catch((error) => { + if (!latest()) return; + endPending(id); + setActionMessage({ error: true, text: String(error), localize: true }); + }) + .finally(() => onAppsRefresh?.()); } function closeApp(id: string) { - setActionBusy(true); - setActionMessage(null); + const latest = startPending(id, 'closing'); void closeConnectedApp(id) - .then(() => setActionMessage({ error: false, text: '', key: 'appControl.quitAccepted' })) - .catch((error) => setActionMessage({ error: true, text: String(error) })) - .finally(() => { - setActionBusy(false); - onAppsRefresh?.(); - }); + .then(() => { + if (latest()) setActionMessage({ error: false, text: '', key: 'appControl.quitAccepted' }); + }) + .catch((error) => { + if (!latest()) return; + endPending(id); + setActionMessage({ error: true, text: String(error) }); + }) + .finally(() => onAppsRefresh?.()); } function runMenuItem(app: RegistryApp, itemId: string) { setActionMessage(null); @@ -675,20 +756,53 @@ export function FlyoutPanel({ ); } function closeProcessApp(id: string) { - setActionBusy(true); - setActionMessage(null); + const latest = startPending(id, 'closing'); void closeOfficialApp(id) - .then((result) => setActionMessage({ error: false, warning: result.status === 'stillRunning', text: result.message })) - .catch((error) => setActionMessage({ error: true, text: String(error), localize: true })) - .finally(() => { - setActionBusy(false); - onAppsRefresh?.(); - }); + .then((result) => { + if (!latest()) return; + if (result.status === 'stillRunning') endPending(id); + else endPendingIfUnobservable(id); + setActionMessage({ error: false, warning: result.status === 'stillRunning', text: result.message }); + }) + .catch((error) => { + if (!latest()) return; + endPending(id); + setActionMessage({ error: true, text: String(error), localize: true }); + }) + .finally(() => onAppsRefresh?.()); } const installed = apps.filter(isInstalled); const installedCount = installed.length; const sampleInstalled = installed.some((app) => app.source !== 'official'); + // Settle each pending request once the observed state shows it took effect. + useEffect(() => { + const connected = new Set(registry.apps.map((entry) => entry.app.id)); + for (const [id, entry] of Object.entries(pending)) + if ( + pendingSettled( + entry.action, + apps.find((app) => app.id === id), + connected.has(id), + ) + ) + endPending(id); + }); + // No event reports a process start or exit, so rescan while a request waits for its effect. + const waiting = Object.keys(pending).length > 0; + useEffect(() => { + if (!waiting) return; + const timer = setInterval(() => refreshAppsRef.current?.(), PENDING_RESCAN_INTERVAL_MS); + return () => clearInterval(timer); + }, [waiting]); + useEffect(() => { + const timers = pendingTimers.current; + return () => { + for (const timer of timers.values()) clearTimeout(timer); + timers.clear(); + }; + }, []); + useEffect(() => { let mounted = true; let unlisten: (() => void) | undefined; @@ -888,7 +1002,11 @@ export function FlyoutPanel({ size="sm" tone={actionMessage.error ? 'danger' : actionMessage.warning ? 'warning' : 'success'} summary={ - actionMessage.key ? t(locale, actionMessage.key) : actionMessage.localize ? localizeAppReason(locale, actionMessage.text) : actionMessage.text + actionMessage.key + ? t(locale, actionMessage.key, actionMessage.params) + : actionMessage.localize + ? localizeAppReason(locale, actionMessage.text) + : actionMessage.text } /> )} @@ -1010,7 +1128,7 @@ export function FlyoutPanel({ onMenuAction={onAppsRefresh ? runMenuItem : undefined} onProcessClose={onAppsRefresh ? closeProcessApp : undefined} onOpen={onAppsRefresh ? openApp : undefined} - actionBusy={actionBusy} + pending={pending} stale={catalogState?.stale === true || (!!catalogState && catalogState.status !== 'ready' && catalogState.status !== 'empty')} hideLocalApps={settings.hideLocalApps} localCycle={visibility?.visible ? visibility.cycle : undefined} @@ -1085,7 +1203,7 @@ export default function App(props: FlyoutProps) { function refreshApps() { if (!liveCatalog || !catalogState.catalog || catalogState.reason === 'cache') return; const id = ++scanId.current; - setInstallations(null); + // Keep the last observation on screen while rescanning; clearing it would blank every card. void scanInstallations() .then((result) => { if (id === scanId.current) setInstallations(result); diff --git a/apps/hub/src/i18n/messages.json b/apps/hub/src/i18n/messages.json index bf9c723..dec0c4c 100644 --- a/apps/hub/src/i18n/messages.json +++ b/apps/hub/src/i18n/messages.json @@ -100,7 +100,10 @@ "refresh": "Actualizar apps", "connectedAbove": "Las apps instaladas conectadas aparecen arriba.", "closeWithoutPlugin": "Para cerrar una app sin plugin, hazlo desde la propia app.", - "quitAccepted": "Solicitud de cierre aceptada; la salida no está confirmada." + "quitAccepted": "Solicitud de cierre aceptada; la salida no está confirmada.", + "opening": "Abriendo…", + "closing": "Cerrando…", + "confirmTimeout": "No se pudo confirmar el cambio de estado de {name}." }, "settings": { "fontCredit": "Tipografía Barlow · SIL Open Font License 1.1", @@ -495,7 +498,10 @@ "refresh": "Refresh apps", "connectedAbove": "Connected installed apps are shown above.", "closeWithoutPlugin": "To close an app without the plugin, close it from within the app.", - "quitAccepted": "Close request accepted; exit is not confirmed." + "quitAccepted": "Close request accepted; exit is not confirmed.", + "opening": "Opening…", + "closing": "Closing…", + "confirmTimeout": "Could not confirm the state change for {name}." }, "settings": { "fontCredit": "Barlow typeface · SIL Open Font License 1.1", From ab4add08b50f85e987d2b88a0d8557738040fa11 Mon Sep 17 00:00:00 2001 From: egdev6 Date: Wed, 25 Nov 2026 11:53:41 +0100 Subject: [PATCH 2/2] fix(hub): collapse the row when closing an app and space local app notices Both the header close action and the inner close button collapse the expanded row. Local app notices keep the card spacing below them. --- apps/hub/src/App.test.tsx | 49 ++++++++++++++++++++++++++++++++ apps/hub/src/App.tsx | 13 +++++++-- apps/hub/src/local-apps/view.tsx | 8 ++++-- apps/hub/src/style.css | 1 + 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/apps/hub/src/App.test.tsx b/apps/hub/src/App.test.tsx index 804a0bf..7a9c137 100644 --- a/apps/hub/src/App.test.tsx +++ b/apps/hub/src/App.test.tsx @@ -328,6 +328,55 @@ it('keeps a closing app pending until a rescan observes it stopped', async () => expect((screen.getByRole('button', { name: 'Abrir Example App' }) as HTMLButtonElement).disabled).toBe(false); }); +it('collapses the expanded row when closing an app from its header action', async () => { + mockLiveApp( + () => ({ runningState: 'running' }), + (command) => (command === 'close_official_app' ? new Promise(() => {}) : undefined), + ); + render(); + expect(await screen.findByText('Abierta')).toBeTruthy(); + const trigger = expandRow('Example App'); + expect(trigger.getAttribute('aria-expanded')).toBe('true'); + fireEvent.click(screen.getByRole('button', { name: 'Cerrar Example App' })); + expect(trigger.getAttribute('aria-expanded')).toBe('false'); + expect(invoke).toHaveBeenCalledWith('close_official_app', { id: 'example-app' }); +}); + +it('collapses the expanded connected row when closing it from the inner close button', async () => { + let publish!: (snapshot: RegistrySnapshot) => void; + vi.mocked(subscribeRegistry).mockImplementation(async (callback) => { + publish = callback; + return () => {}; + }); + mockLiveApp( + () => ({ runningState: 'connected' }), + (command) => (command === 'close_connected_app' ? new Promise(() => {}) : undefined), + ); + render(); + await screen.findByText('Example App'); + act(() => + publish({ + revision: 1, + apps: [ + { + app: { id: 'example-app', name: 'Example App', version: '2.0.0' }, + capabilities: ['show', 'quit'], + unified: true, + responsive: true, + generation: 1, + menu_revision: 0, + menu: [], + }, + ], + }), + ); + const trigger = expandRow('Example App'); + expect(trigger.getAttribute('aria-expanded')).toBe('true'); + fireEvent.click(screen.getByRole('button', { name: 'Cerrar Example App' })); + expect(trigger.getAttribute('aria-expanded')).toBe('false'); + expect(invoke).toHaveBeenCalledWith('close_connected_app', { id: 'example-app' }); +}); + it('stops waiting and warns when the state change is never observed', async () => { vi.useFakeTimers({ shouldAdvanceTime: true }); try { diff --git a/apps/hub/src/App.tsx b/apps/hub/src/App.tsx index a64b3c1..b42f07b 100644 --- a/apps/hub/src/App.tsx +++ b/apps/hub/src/App.tsx @@ -520,6 +520,15 @@ function InstalledPanel({ open: openRow === id, onOpenChange: (open: boolean) => setOpenRow((current) => (open ? id : current === id ? null : current)), }); + /** Closing an app also collapses its row, whichever close control was used. */ + const collapseThen = (close?: (id: string) => void) => + close && + ((id: string) => { + setOpenRow((current) => (current === `official:${id}` || current === `connected:${id}` ? null : current)); + close(id); + }); + const closeConnected = collapseThen(onClose); + const closeProcess = collapseThen(onProcessClose); return ( <> {connected.length > 0 && ( @@ -532,7 +541,7 @@ function InstalledPanel({ key={app.app.id} app={app} official={apps.find((item) => item.source === 'official' && item.id === app.app.id)} - onClose={onClose} + onClose={closeConnected} onOpen={onOpen} onMenuAction={onMenuAction} busy={!!pending[app.app.id]} @@ -563,7 +572,7 @@ function InstalledPanel({ key={app.id} app={app} onOpen={onOpen} - onClose={onProcessClose} + onClose={closeProcess} busy={!!pending[app.id]} pending={pending[app.id]?.action} stale={stale} diff --git a/apps/hub/src/local-apps/view.tsx b/apps/hub/src/local-apps/view.tsx index d5a5c33..88ec176 100644 --- a/apps/hub/src/local-apps/view.tsx +++ b/apps/hub/src/local-apps/view.tsx @@ -109,8 +109,12 @@ export function LocalAppsView({ } /> - {listError && } - {message && } + {(listError || message) && ( +
+ {listError && } + {message && } +
+ )} {rows.map((row) => { const other = row.duplicateOf && (lookup.find((item) => item.id === row.duplicateOf)?.name ?? row.duplicateOf); return ( diff --git a/apps/hub/src/style.css b/apps/hub/src/style.css index a127e4c..159b1d5 100644 --- a/apps/hub/src/style.css +++ b/apps/hub/src/style.css @@ -36,6 +36,7 @@ body[data-flyout-sliding] > :not(#root) { visibility: hidden !important; } .area-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; } .apps-section-header { margin: var(--space-2) 0 var(--space-3); } .app-card { margin-bottom: calc(var(--space-3) * var(--hub-density)); } +.local-apps__notices { display: grid; gap: var(--space-2); margin-bottom: calc(var(--space-3) * var(--hub-density)); } .update-notes { overflow-wrap: anywhere; white-space: pre-wrap; } .row-label { display: flex; align-items: center; gap: var(--space-4); } .app-info { min-width: 0; flex: 1; }