From 97628dfd13dad887cd3a472af6f6e9918d47e77b Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Sun, 29 Nov 2026 10:12:50 +0000 Subject: [PATCH] fix(app): open settings for built-in plugins (#11308) The plugin page gated settings on the managed install list. Use the client catalog to resolve the contributed screen so that built-in plugins can open settings from their links. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> --- .../browser/builtin-plugin-settings.spec.ts | 13 ++++ .../e2e/fixtures/builtin-settings/daemon.mts | 34 ++++++++ .../helpers/builtin-plugin-settings.ts | 77 +++++++++++++++++++ packages/app/e2e/support/helpers/hosts.ts | 18 ++++- .../app/src/plugins/gallery/plugin-page.tsx | 45 ++++++++--- 5 files changed, 172 insertions(+), 15 deletions(-) create mode 100644 packages/app/e2e/browser/builtin-plugin-settings.spec.ts create mode 100644 packages/app/e2e/fixtures/builtin-settings/daemon.mts create mode 100644 packages/app/e2e/support/helpers/builtin-plugin-settings.ts diff --git a/packages/app/e2e/browser/builtin-plugin-settings.spec.ts b/packages/app/e2e/browser/builtin-plugin-settings.spec.ts new file mode 100644 index 0000000000..d5c3358658 --- /dev/null +++ b/packages/app/e2e/browser/builtin-plugin-settings.spec.ts @@ -0,0 +1,13 @@ +import { + expectBuiltinPluginSettings, + openBuiltinPluginSettings, + test, +} from "../support/helpers/builtin-plugin-settings"; + +test("a built-in plugin's settings link opens its screen", async ({ + page, + builtinSettingsHost, +}) => { + await openBuiltinPluginSettings(page, builtinSettingsHost); + await expectBuiltinPluginSettings(page); +}); diff --git a/packages/app/e2e/fixtures/builtin-settings/daemon.mts b/packages/app/e2e/fixtures/builtin-settings/daemon.mts new file mode 100644 index 0000000000..34d8208de4 --- /dev/null +++ b/packages/app/e2e/fixtures/builtin-settings/daemon.mts @@ -0,0 +1,34 @@ +import { BuiltinPluginLoader } from "../../../../server/src/server/plugins/builtin/index.js"; +import { createTestPaseoDaemon } from "../../../../server/src/server/test-utils/paseo-daemon.js"; +import { DaemonClient } from "../../../../server/src/server/test-utils/daemon-client.js"; +import assert from "node:assert/strict"; +import pino from "pino"; + +const [, , root, origin, paseoHomeRoot, daemonVersion] = process.argv; + +const daemon = await createTestPaseoDaemon({ + corsAllowedOrigins: [origin!], + paseoHomeRoot, + daemonVersion, + logger: pino({ level: "error" }), + builtinPlugins: new BuiltinPluginLoader(root, ["builtin-settings"]), +}); +const client = new DaemonClient({ + appVersion: daemonVersion, + url: `ws://127.0.0.1:${daemon.port}/ws`, +}); + +try { + await client.connect(); + const plugin = (await client.getPluginCatalog()).find(({ id }) => id === "builtin-settings"); + assert.ok(plugin?.clientBundle, JSON.stringify(await client.getPluginLogs("builtin-settings"))); + assert.deepEqual(await client.listPlugins(), []); + process.send!({ serverId: client.getLastServerInfoMessage()!.serverId, port: daemon.port }); + await new Promise((resolve) => { + process.once("disconnect", resolve); + process.once("SIGTERM", resolve); + }); +} finally { + await client.close(); + await daemon.close(); +} diff --git a/packages/app/e2e/support/helpers/builtin-plugin-settings.ts b/packages/app/e2e/support/helpers/builtin-plugin-settings.ts new file mode 100644 index 0000000000..46b76a0405 --- /dev/null +++ b/packages/app/e2e/support/helpers/builtin-plugin-settings.ts @@ -0,0 +1,77 @@ +import { mkdir, writeFile } from "node:fs/promises"; +import path from "node:path"; +import { once } from "node:events"; +import { spawnTsx, killProcessTree } from "./spawn-node"; +import appPackage from "../../../package.json"; +import { expect, test as base, type Page } from "../fixtures"; +import { gotoAppShell } from "./app"; +import { addConnectedHostAndReload } from "./hosts"; +import { pluginRequirements } from "./plugin-fixture"; + +const pluginId = "builtin-settings"; +const screenId = "general"; +const settingsText = "Built-in settings body"; + +export const test = base.extend<{ builtinSettingsHost: { serverId: string; port: number } }>({ + builtinSettingsHost: async ({ baseURL }, provide, testInfo) => { + const root = testInfo.outputPath("builtin-plugins"); + const directory = path.join(root, pluginId); + await mkdir(directory, { recursive: true }); + await writeFile( + path.join(directory, "paseo-plugin.json"), + JSON.stringify({ id: pluginId, requirements: pluginRequirements }), + ); + await writeFile( + path.join(directory, "index.client.tsx"), + `import React from "react"; +import { Text } from "react-native"; + +export default function contribute(client) { + client.addSettingsScreen({ + id: "${screenId}", + title: "General", + icon: "SlidersHorizontal", + Component: () => ${settingsText}, + }); + return () => {}; +}`, + ); + await writeFile( + path.join(directory, "index.server.ts"), + "export default function contribute() { return () => {}; }", + ); + const daemon = spawnTsx( + path.resolve(__dirname, "../../fixtures/builtin-settings/daemon.mts"), + [root, new URL(baseURL!).origin, testInfo.outputPath("daemon"), appPackage.version], + { stdio: ["ignore", "inherit", "inherit", "ipc"] }, + ); + try { + const [host] = await Promise.race([ + once(daemon, "message") as Promise<[{ serverId: string; port: number }]>, + once(daemon, "exit").then(([code]) => { + throw new Error(`Built-in settings daemon exited with code ${code}`); + }), + ]); + await provide(host); + } finally { + await killProcessTree(daemon); + } + }, +}); + +export async function openBuiltinPluginSettings( + page: Page, + host: { serverId: string; port: number }, +) { + await gotoAppShell(page); + await addConnectedHostAndReload(page, { + ...host, + label: "Built-in settings host", + destination: `/settings/hosts/${host.serverId}/plugins/${pluginId}/${screenId}`, + }); +} + +export async function expectBuiltinPluginSettings(page: Page) { + await expect(page.getByText(settingsText, { exact: true })).toBeVisible(); + await expect(page.getByRole("switch", { name: /: Disable$/ })).toHaveCount(0); +} diff --git a/packages/app/e2e/support/helpers/hosts.ts b/packages/app/e2e/support/helpers/hosts.ts index fc7c5d8dba..e2a8e59d74 100644 --- a/packages/app/e2e/support/helpers/hosts.ts +++ b/packages/app/e2e/support/helpers/hosts.ts @@ -76,15 +76,24 @@ export async function addOfflineHostsAndReload( export async function addConnectedHostAndReload( page: Page, - input: { serverId: string; label: string; port: number; primaryLabel?: string }, + input: { + serverId: string; + label: string; + port: number; + primaryLabel?: string; + destination?: string; + }, ): Promise { - await addConnectedHostsAndReload(page, [input], { primaryLabel: input.primaryLabel }); + await addConnectedHostsAndReload(page, [input], { + primaryLabel: input.primaryLabel, + destination: input.destination, + }); } export async function addConnectedHostsAndReload( page: Page, inputs: Array<{ serverId: string; label: string; port: number }>, - options?: { primaryLabel?: string }, + options?: { primaryLabel?: string; destination?: string }, ): Promise { const connectedHosts = inputs.map((input) => buildSeededHost({ @@ -123,7 +132,8 @@ export async function addConnectedHostsAndReload( }, ); - await page.reload(); + if (options?.destination) await page.goto(options.destination); + else await page.reload(); } export async function waitForConnectedHost( diff --git a/packages/app/src/plugins/gallery/plugin-page.tsx b/packages/app/src/plugins/gallery/plugin-page.tsx index cf38535889..c2df60b488 100644 --- a/packages/app/src/plugins/gallery/plugin-page.tsx +++ b/packages/app/src/plugins/gallery/plugin-page.tsx @@ -27,8 +27,12 @@ import { StatusBadge } from "@/components/ui/status-badge"; import { Switch } from "@/components/ui/switch"; import { useIsCompactFormFactor } from "@/constants/layout"; import { useToast } from "@/contexts/toast-api-context"; -import { useHostRuntimeClient } from "@/runtime/host-runtime"; -import { useInstalledPlugin, usePluginEvaluationError } from "@/plugins/registry"; +import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime"; +import { + useInstalledPlugin, + usePluginCatalogStatus, + usePluginEvaluationError, +} from "@/plugins/registry"; import { pluginDisplayName } from "@/plugins/plugin-list"; import { PluginSettingsContent } from "@/plugins/settings"; import { usePluginActions, type PluginAction } from "./actions"; @@ -276,8 +280,6 @@ interface PluginPageModel { error?: string; /** Why the last update failed, while the update is still offered. The installed version keeps running. */ updateError?: string; - /** The plugin's own settings screen, shown inline. */ - screenId?: string; overview?: string; } @@ -301,12 +303,10 @@ function usePluginPageModel({ const directory = usePluginDirectory(serverId); const meta = useListingMeta(); const pluginId = plugin?.id ?? ""; - const installedPlugin = useInstalledPlugin(serverId, pluginId); const evaluationError = usePluginEvaluationError(serverId, pluginId); const pluginOperation = usePluginOperation(serverId, pluginId); const updates = usePluginUpdates(serverId); const text = listing ? listingText(listing, i18n.language) : undefined; - const requestedScreen = subject.kind === "installed" ? subject.screenId : undefined; return { name: plugin ? pluginDisplayName(plugin) : (text?.name ?? subjectId(subject)), description: text?.description ?? plugin?.description, @@ -316,11 +316,22 @@ function usePluginPageModel({ authorAvatar: listing && listingAuthorAvatar(listing), error: plugin ? (evaluationError ?? plugin.error) : failedError(installOperation), updateError: failedUpdateError(pluginOperation, updates.data, pluginId), - screenId: plugin ? (requestedScreen ?? installedPlugin?.settingsScreens[0]?.id) : undefined, overview: detail && listingOverview(detail, i18n.language), }; } +function usePluginPageSettings( + serverId: string, + subject: PluginPageSubject, + plugin: PluginListItem | undefined, +) { + const pluginId = subject.kind === "installed" ? subject.pluginId : (plugin?.id ?? ""); + const installedPlugin = useInstalledPlugin(serverId, pluginId); + const requestedScreen = subject.kind === "installed" ? subject.screenId : undefined; + const screenId = requestedScreen ?? installedPlugin?.settingsScreens[0]?.id; + return (plugin || installedPlugin) && screenId ? { pluginId, screenId } : undefined; +} + function subjectId(subject: PluginPageSubject): string { return subject.kind === "listing" ? subject.listingId : subject.pluginId; } @@ -408,6 +419,9 @@ export function PluginPage({ const { t } = useTranslation(); const compact = useIsCompactFormFactor(); const { plugin, listingId, listing, detail, loading } = useResolvedPlugin(serverId, subject); + const settings = usePluginPageSettings(serverId, subject, plugin); + const catalogStatus = usePluginCatalogStatus(serverId); + const connected = useHostRuntimeIsConnected(serverId); const installOperation = usePluginOperation(serverId, listingId); const model = usePluginPageModel({ serverId, @@ -436,14 +450,20 @@ export function PluginPage({ ); - if (loading) + const waitingForSettings = + subject.kind === "installed" && + !plugin && + !settings && + connected && + catalogStatus === "loading"; + if (loading || waitingForSettings) return ( {back} ); - if (!plugin && !listing) + if (!plugin && !listing && !settings) return ( {installTarget ? ( @@ -500,12 +521,14 @@ function PluginPageBody({ listing, overviewLoading, model, + settings, }: { serverId: string; plugin?: PluginListItem; listing?: PluginListing; overviewLoading: boolean; model: PluginPageModel; + settings?: { pluginId: string; screenId: string }; }) { const { t } = useTranslation(); return ( @@ -523,9 +546,9 @@ function PluginPageBody({ ) : null} {listing ? : null} - {plugin && model.screenId ? ( + {settings ? ( // The plugin's settings screen brings its own sections. - + ) : null} {model.overview || (listing && overviewLoading) ? (