diff --git a/web/src/features/AppCatalog/Components/InstalledAppCard.tsx b/web/src/features/AppCatalog/Components/InstalledAppCard.tsx index 178a3f18c..11af19b90 100644 --- a/web/src/features/AppCatalog/Components/InstalledAppCard.tsx +++ b/web/src/features/AppCatalog/Components/InstalledAppCard.tsx @@ -36,7 +36,6 @@ export default function InstalledAppCard({ name, publisher, canOpen, - openRouteId, actions, blockedRelease, updateRequiresSource, @@ -113,7 +112,7 @@ export default function InstalledAppCard({ to="/apps/$installationId/{-$routeId}" params={{ installationId: installation.installationId, - routeId: openRouteId, + routeId: undefined, }} search={{}} className={buttonClassName('secondary')} diff --git a/web/src/features/AppCatalog/Hooks/useAppCatalogLogic.ts b/web/src/features/AppCatalog/Hooks/useAppCatalogLogic.ts index d15b75761..d715ea2b6 100644 --- a/web/src/features/AppCatalog/Hooks/useAppCatalogLogic.ts +++ b/web/src/features/AppCatalog/Hooks/useAppCatalogLogic.ts @@ -2,7 +2,7 @@ import { toast } from '@rentnerkev/toasts' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { useEffect, useRef, useState } from 'react' import { useAppUi } from '@/features/AppUi/AppUiProvider.tsx' -import { appUiDefaultRoute } from '@/lib/AppUi/bridge.ts' +import { appPageDefaultRoute } from '@/lib/AppUi/page-access.ts' import { isPackageSourceOutage, sameCatalogLifecycle, @@ -164,17 +164,10 @@ export default function useAppCatalogLogic() { installation, name: installation.name ?? declaredApp?.name ?? app?.name ?? installation.appId, publisher: declaredApp?.publisher, - // An app that declares extensions opens only through a page it declares. canOpen: installation.state === 'running' && app?.appId === installation.appId && - (app.extensionCatalog === undefined || app.pages.length > 0), - openRouteId: - app?.extensionCatalog !== undefined && - app.pages[0] && - app.pages[0].route !== appUiDefaultRoute(app) - ? app.pages[0].route - : undefined, + appPageDefaultRoute(app) !== undefined, actions: catalogInstallationActions( installation, status === 'ready', diff --git a/web/src/features/AppCatalog/Types/app-catalog.types.ts b/web/src/features/AppCatalog/Types/app-catalog.types.ts index 15ca3ae3f..4f97d61e3 100644 --- a/web/src/features/AppCatalog/Types/app-catalog.types.ts +++ b/web/src/features/AppCatalog/Types/app-catalog.types.ts @@ -12,8 +12,6 @@ export type CatalogInstallationView = { name: string publisher: string | undefined canOpen: boolean - /** The route of the app's first page, or undefined for its default route. */ - openRouteId: string | undefined actions: CatalogLifecycleInput[] /** The newest listed release the appliance cannot offer, with the reason. */ blockedRelease: CatalogBlockedRelease | undefined diff --git a/web/src/features/AppUi/AppUiFrame.tsx b/web/src/features/AppUi/AppUiFrame.tsx index 50f67a012..2727c82c8 100644 --- a/web/src/features/AppUi/AppUiFrame.tsx +++ b/web/src/features/AppUi/AppUiFrame.tsx @@ -1,6 +1,7 @@ import { useCallback, useEffect, useEffectEvent, useMemo, useState } from 'react' import { appUiDefaultRoute } from '@/lib/AppUi/bridge.ts' +import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts' import type { AppUiSlot, AppUiSummary } from '@/lib/AppUi/contract.ts' import { APP_UI_PREFIX } from '@/lib/AppUi/paths.ts' import { supportsRemoteRendering, type AppUiRevocation } from '@/lib/AppUi/session.ts' @@ -20,6 +21,7 @@ type FrameProps = { app: AppUiSummary slot?: AppUiSlot | undefined hostId?: string | undefined + hostActionId?: string | undefined route?: string | undefined onNavigate?: ((route: string) => void) | undefined /** Fill the height of a fixed-height container, such as a dialog body. */ @@ -28,26 +30,40 @@ type FrameProps = { type AppFrameSource = OpenedSource & { frameToken: string } -export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill }: FrameProps) { +export default function AppUiFrame({ + app, + slot, + hostId, + hostActionId, + route, + onNavigate, + fill, +}: FrameProps) { const sessionId = useAppUi()?.sessionId const [localRoute, setLocalRoute] = useState() const [attempt, setAttempt] = useState(0) + const defaultRoute = appUiDefaultRoute(app) const current = route ?? - (localRoute && app.routes.includes(localRoute) ? localRoute : appUiDefaultRoute(app)) + [localRoute, defaultRoute, ...app.routes].find( + (candidate) => + candidate !== undefined && isAppUiRouteAllowed(app, candidate, hostActionId), + ) // A new generation, a reconnect or a retry remounts the view below; drafts the user did not - // save pass to the next view of the same session, app, slot and host, never to another. + // save pass to the next view for the same session, app, slot, host and action. const identity = JSON.stringify([ sessionId ?? null, app.installationId, slot ?? null, hostId ?? null, + hostActionId ?? null, ]) // A holder the views write after render, from their layout effects; never read while rendering. const [kept] = useState(() => ({ current: null })) const handoff = useMemo(() => draftHandoff(identity, kept), [identity, kept]) - if (!sessionId) return null + if (!sessionId || current === undefined || !isAppUiRouteAllowed(app, current, hostActionId)) + return null // Routing updates the open document through the bridge. const retry = () => setAttempt((previous) => previous + 1) @@ -60,6 +76,7 @@ export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill app.generation, slot, hostId, + hostActionId, attempt, ])} onRetry={retry} @@ -69,6 +86,7 @@ export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill app={app} slot={slot} hostId={hostId} + hostActionId={hostActionId} route={current} fill={fill} onNavigate={onNavigate ?? setLocalRoute} @@ -102,11 +120,11 @@ function AppUiMount(props: MountProps) { ) const showOwnFrame = useCallback(() => setPooled(false), []) if (!pooled || !pool) return - const { app, sessionId, slot, hostId, route, fill, onNavigate, onRetry } = props + const { app, sessionId, slot, hostId, hostActionId, route, fill, onNavigate, onRetry } = props return ( { @@ -205,6 +225,7 @@ function OpenedAppFrame({ app, source, slot, + hostActionId, route, fill, onNavigate, @@ -213,6 +234,7 @@ function OpenedAppFrame({ app: AppUiSummary source: AppFrameSource slot: AppUiSlot | undefined + hostActionId: string | undefined route: string fill: boolean | undefined onNavigate: (route: string) => void @@ -225,6 +247,7 @@ function OpenedAppFrame({ app={app} source={source} slot={slot} + hostActionId={hostActionId} route={route} fill={fill} theme={ui?.theme ?? 'light'} diff --git a/web/src/features/AppUi/Components/AppFrameView.tsx b/web/src/features/AppUi/Components/AppFrameView.tsx index 3646aec77..92d32a2e3 100644 --- a/web/src/features/AppUi/Components/AppFrameView.tsx +++ b/web/src/features/AppUi/Components/AppFrameView.tsx @@ -1,6 +1,7 @@ import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from 'react' import type { AppUiRendering } from '@/lib/AppUi/bridge.ts' +import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts' import { createRemoteUiStore, type RemoteUiEvent } from '@/lib/AppUi/remote-tree.ts' import { bindAppUiFrame, @@ -22,6 +23,7 @@ export default function AppFrameView({ app, source, slot, + hostActionId, route, fill, theme, @@ -47,7 +49,9 @@ export default function AppFrameView({ })) // Keys match the manifest pattern, so the joined list changes exactly when the keys do. const permissionScope = app.permissionKeys.join(' ') - const navigate = useEffectEvent(onNavigate) + const navigate = useEffectEvent((target: string) => { + if (isAppUiRouteAllowed(app, target, hostActionId)) onNavigate(target) + }) const dialog = useEffectEvent(onDialog) const request = useEffectEvent(onApiRequest) const revoke = useEffectEvent((reason: AppUiRevocation) => { diff --git a/web/src/features/AppUi/Components/AppHostActionDialog.tsx b/web/src/features/AppUi/Components/AppHostActionDialog.tsx index 20b760a4a..b6c82a40c 100644 --- a/web/src/features/AppUi/Components/AppHostActionDialog.tsx +++ b/web/src/features/AppUi/Components/AppHostActionDialog.tsx @@ -24,6 +24,7 @@ export default function AppHostActionDialog(props: AppHostActionDialogProps) { app={state.app} slot="proxyHostTab" hostId={props.hostId} + hostActionId={props.actionId} route={state.route} onNavigate={handler.handleNavigate} fill diff --git a/web/src/features/AppUi/Components/PooledAppFrameView.tsx b/web/src/features/AppUi/Components/PooledAppFrameView.tsx index 74381c92c..8728bee26 100644 --- a/web/src/features/AppUi/Components/PooledAppFrameView.tsx +++ b/web/src/features/AppUi/Components/PooledAppFrameView.tsx @@ -9,6 +9,7 @@ import { import type { RemoteUiEvent } from '@/lib/AppUi/remote-tree.ts' import type { AppUiRemoteEventDetail } from '@/lib/AppUi/session.ts' +import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts' import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' import { ModalActionButton } from '@/shared/Modal/Components/ModalActions.tsx' import type { @@ -47,12 +48,15 @@ export default function PooledAppFrameView({ readonly onRetry: () => void }) { const { t, locale } = useTranslationStore() - const view = useRef({ route: request.route, onNavigate }) + const { app } = request + const handleNavigate = (target: string) => { + if (isAppUiRouteAllowed(app, target, request.hostActionId)) onNavigate(target) + } + const view = useRef({ route: request.route, onNavigate: handleNavigate }) useLayoutEffect(() => { - view.current = { route: request.route, onNavigate } + view.current = { route: request.route, onNavigate: handleNavigate } }) const [frame, setFrame] = useState() - const { app } = request const opened = useRef(request) // The view takes the frame opened for its request, or opens one, and closes it when it goes. diff --git a/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts b/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts index 22e620ea6..b0d90fa85 100644 --- a/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts +++ b/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts @@ -1,6 +1,7 @@ import { useState } from 'react' import { nativeText } from '@/lib/AppUi/native-presentation.ts' +import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts' import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' import { useAppUi } from '../AppUiProvider.tsx' import type { AppHostActionDialogProps } from '../Types/app-host-table.types.ts' @@ -18,7 +19,12 @@ export default function useAppHostActionDialogLogic({ const action = app?.hostActions.find((entry) => entry.id === actionId) const [navigation, setNavigation] = useState<{ action: string; route: string }>() // The app may navigate inside the dialog; a new action starts at its own route again. - const route = navigation?.action === actionId ? navigation.route : action?.route + const route = + app && + navigation?.action === actionId && + isAppUiRouteAllowed(app, navigation.route, actionId) + ? navigation.route + : action?.route return { state: { diff --git a/web/src/features/AppUi/Hooks/useNativeAppUiLogic.ts b/web/src/features/AppUi/Hooks/useNativeAppUiLogic.ts index 63a1edc32..0a9c88d6f 100644 --- a/web/src/features/AppUi/Hooks/useNativeAppUiLogic.ts +++ b/web/src/features/AppUi/Hooks/useNativeAppUiLogic.ts @@ -1,6 +1,7 @@ import { useQuery } from '@tanstack/react-query' import { callAppUi } from '@/lib/AppUi/client.ts' import type { AppUiPayload, AppUiSummary } from '@/lib/AppUi/contract.ts' +import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts' import { useAppUi } from '../AppUiProvider.tsx' import { openAppUiHandler } from '../middleware.ts' @@ -94,7 +95,9 @@ export function useNativeAppUiLogic(app: AppUiSummary) { return result.payload } - return { state: { source, scope }, handler: { call } } + const pages = + source.data?.presentation.pages.filter(({ route }) => isAppUiRouteAllowed(app, route)) ?? [] + return { state: { source, scope, pages }, handler: { call } } } export type NativeAppSession = Pick, 'handler'> & { diff --git a/web/src/features/AppUi/Hooks/usePrewarmAppHostAction.ts b/web/src/features/AppUi/Hooks/usePrewarmAppHostAction.ts index c4d5ede95..548644a9f 100644 --- a/web/src/features/AppUi/Hooks/usePrewarmAppHostAction.ts +++ b/web/src/features/AppUi/Hooks/usePrewarmAppHostAction.ts @@ -1,5 +1,6 @@ import { useCallback } from 'react' +import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts' import { supportsRemoteRendering } from '@/lib/AppUi/session.ts' import { useAppUi } from '../AppUiProvider.tsx' import type { AppHostTableAction } from '../Types/app-host-table.types.ts' @@ -11,15 +12,24 @@ import type { AppHostTableAction } from '../Types/app-host-table.types.ts' export default function usePrewarmAppHostAction() { const ui = useAppUi() return useCallback( - (hostId: string, action: Pick) => { + (hostId: string, action: Pick) => { const app = ui?.apps.find((entry) => entry.installationId === action.installationId) - if (!ui?.sessionId || !app || !supportsRemoteRendering(app)) return + const entry = app?.hostActions.find(({ id }) => id === action.actionId) + if ( + !ui?.sessionId || + !app || + !entry || + !supportsRemoteRendering(app) || + !isAppUiRouteAllowed(app, entry.route, entry.id) + ) + return ui.framePool.prewarm({ app, sessionId: ui.sessionId, slot: 'proxyHostTab', hostId, - route: action.route, + hostActionId: entry.id, + route: entry.route, }) }, [ui], diff --git a/web/src/features/AppUi/NativeAppUi.tsx b/web/src/features/AppUi/NativeAppUi.tsx index 16c3c0988..6d4fca25f 100644 --- a/web/src/features/AppUi/NativeAppUi.tsx +++ b/web/src/features/AppUi/NativeAppUi.tsx @@ -28,8 +28,8 @@ export default function NativeAppUi(props: NativeAppUiProps) { function NativeAppContent({ app, route, onNavigate }: NativeAppUiProps) { const { t, locale } = useTranslationStore() const { state, handler } = useNativeAppUiLogic(app) - const { source, scope } = state - const activePage = source.data?.presentation.pages.find((page) => page.route === route) + const { source, scope, pages } = state + const activePage = pages.find((page) => page.route === route) const session: NativeAppSession | undefined = source.data && { scope, handler, @@ -61,7 +61,7 @@ function NativeAppContent({ app, route, onNavigate }: NativeAppUiProps) { ) : ( <>