#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Ask where to run Stirling on first visit to SaaS (#8417)
EthanHealy010b47dff0d007
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex 78e3683254..9a736fb639 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -9221,8 +9221,10 @@ title = "Kubernetes"[portal.home.download.linux]detailBody = "Native builds for your distribution."-guideBtn = "View Linux install options"-note = "AppImage, .deb and .rpm builds are available for common distros."+downloadAppImage = "AppImage"+downloadDeb = "Download .deb (Debian, Ubuntu)"+downloadRpm = ".rpm (Fedora, RHEL)"+note = "64-bit x86 builds. AppImage runs on most other distros."tagline = "Native desktop app for your distro"title = "Linux"@@ -11615,6 +11617,64 @@ mi = "Miles (mi)"mm = "Millimeters (mm)"yd = "Yards (yd)"+[runLocation]+back = "Back"+continue = "Continue"+subtitle = "Choose where it runs."+title = "Where do you want to run Stirling?"++[runLocation.choice.browser]+description = "The web app."+title = "In your browser"++[runLocation.choice.computer]+description = "The desktop app."+title = "On your computer"++[runLocation.choice.server]+description = "Self-hosted, for a team."+title = "On your server"++[runLocation.desktop]+computerLabel = "Your computer"+download = "Download for {{platform}}"+downloadAgain = "Download again"+guide = "Open the {{platform}} install guide"+startedSubtitle = "Check your Downloads folder, then open the installer."+startedTitle = "Your download has started"+subtitle = "Download it and open it."+title = "Get the desktop app"++[runLocation.desktop.platform]+linux = "Linux"+mac = "Mac"+windows = "Windows"++[runLocation.desktop.target]+linuxAppImage = "Linux · AppImage"+linuxArm64 = "Linux · Arm (install guide)"+linuxDeb = "Linux · .deb"+linuxRpm = "Linux · .rpm"+mac = "Mac"+windowsArm64 = "Windows · Arm"+windowsX64 = "Windows · x64"++[runLocation.server]+copied = "Copied"+copy = "Copy command"+copyCompose = "Copy compose file"+guide = "{{method}} install guide"+methodLabel = "Run it with"+note = "Then open <url/> to finish setup."+subtitle = "Run this on your server, then open it in a browser."+title = "Set up your server"++[runLocation.server.method]+compose = "Docker Compose"+docker = "Docker"+kubernetes = "Kubernetes"+manual = "Java (JAR)"+[sanitize]desc = "Remove potentially harmful elements from PDF files."sanitizationResults = "Sanitization Results"diff --git a/frontend/editor/src/cloud/components/onboarding/useSaasOnboardingState.ts b/frontend/editor/src/cloud/components/onboarding/useSaasOnboardingState.tsindex 6406fbe77a..4837973a32 100644--- a/frontend/editor/src/cloud/components/onboarding/useSaasOnboardingState.ts+++ b/frontend/editor/src/cloud/components/onboarding/useSaasOnboardingState.ts@@ -10,7 +10,10 @@ import {type SlideId,} from "@app/components/onboarding/saasOnboardingFlowConfig";import { resolveSaasFlow } from "@app/components/onboarding/saasFlowResolver";-import { DOWNLOAD_URLS } from "@app/constants/downloads";+import {+ DESKTOP_DOWNLOAD_OPTIONS,+ desktopDownloadForOs,+} from "@app/components/onboarding/desktopDownloadOptions";import { openExternal } from "@app/platform/openExternal";interface UseSaasOnboardingStateResult {@@ -55,29 +58,8 @@ export function useSaasOnboardingState({}}, [opened]);- // Determine OS details for desktop download- const os = useMemo(() => {- switch (osType) {- case "windows":- return { label: "Windows", url: DOWNLOAD_URLS.WINDOWS };- case "mac":- return { label: "Mac", url: DOWNLOAD_URLS.MAC };- case "linux-x64":- case "linux-arm64":- return { label: "Linux", url: DOWNLOAD_URLS.LINUX_DOCS };- default:- return { label: "", url: "" };- }- }, [osType]);-- const osOptions = useMemo(() => {- const options = [- { label: "Windows", url: DOWNLOAD_URLS.WINDOWS, value: "windows" },- { label: "Mac", url: DOWNLOAD_URLS.MAC, value: "mac" },- { label: "Linux", url: DOWNLOAD_URLS.LINUX_DOCS, value: "linux" },- ];- return options.filter((opt) => opt.url);- }, []);+ const os = useMemo(() => desktopDownloadForOs(osType), [osType]);+ const osOptions = DESKTOP_DOWNLOAD_OPTIONS;// Store selected download URLconst handleDownloadUrlChange = useCallback((url: string) => {diff --git a/frontend/editor/src/core/components/onboarding/desktopDownloadOptions.test.ts b/frontend/editor/src/core/components/onboarding/desktopDownloadOptions.test.tsnew file mode 100644index 0000000000..fbf742664e--- /dev/null+++ b/frontend/editor/src/core/components/onboarding/desktopDownloadOptions.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vitest";+import { DOWNLOAD_URLS } from "@app/constants/downloads";+import {+ DESKTOP_DOWNLOAD_OPTIONS,+ desktopDownloadForOs,+} from "@app/components/onboarding/desktopDownloadOptions";++describe("desktopDownloadForOs", () => {+ it("offers the .deb on x64 Linux", () => {+ expect(desktopDownloadForOs("linux-x64").url).toBe(DOWNLOAD_URLS.LINUX_DEB);+ });++ it("sends Arm Linux, which has no build, to the install guide", () => {+ const arm = desktopDownloadForOs("linux-arm64");+ expect(arm.url).toBe(DOWNLOAD_URLS.LINUX_DOCS);+ // The picker names the selected option by URL, so the guide must be one.+ expect(DESKTOP_DOWNLOAD_OPTIONS.map((option) => option.url)).toContain(+ arm.url,+ );+ });+});diff --git a/frontend/editor/src/core/components/onboarding/desktopDownloadOptions.ts b/frontend/editor/src/core/components/onboarding/desktopDownloadOptions.tsnew file mode 100644index 0000000000..252c40a1a4--- /dev/null+++ b/frontend/editor/src/core/components/onboarding/desktopDownloadOptions.ts@@ -0,0 +1,36 @@+import { DOWNLOAD_URLS } from "@app/constants/downloads";+import type { OS } from "@app/hooks/useOs";+import type { OSOption } from "@app/components/onboarding/slides/DesktopInstallTitle";++export const DESKTOP_DOWNLOAD_OPTIONS: OSOption[] = [+ { label: "Windows", url: DOWNLOAD_URLS.WINDOWS, value: "windows" },+ { label: "Mac", url: DOWNLOAD_URLS.MAC, value: "mac" },+ { label: "Linux (.deb)", url: DOWNLOAD_URLS.LINUX_DEB, value: "linux-deb" },+ { label: "Linux (.rpm)", url: DOWNLOAD_URLS.LINUX_RPM, value: "linux-rpm" },+ {+ label: "Linux (AppImage)",+ url: DOWNLOAD_URLS.LINUX_APPIMAGE,+ value: "linux-appimage",+ },+ // No Arm build exists for Linux, so this option opens the install guide.+ { label: "Linux (Arm)", url: DOWNLOAD_URLS.LINUX_DOCS, value: "linux-arm" },+];++/**+ * The installer to offer first. Arm Linux has no build, so it gets the install+ * guide; platforms with neither get an empty label and url.+ */+export function desktopDownloadForOs(os: OS): { label: string; url: string } {+ switch (os) {+ case "windows":+ return { label: "Windows", url: DOWNLOAD_URLS.WINDOWS };+ case "mac":+ return { label: "Mac", url: DOWNLOAD_URLS.MAC };+ case "linux-x64":+ return { label: "Linux (.deb)", url: DOWNLOAD_URLS.LINUX_DEB };+ case "linux-arm64":+ return { label: "Linux (Arm)", url: DOWNLOAD_URLS.LINUX_DOCS };+ default:+ return { label: "", url: "" };+ }+}diff --git a/frontend/editor/src/core/components/onboarding/useOnboardingDownload.ts b/frontend/editor/src/core/components/onboarding/useOnboardingDownload.tsindex 5e23d9a0ad..234cf852b5 100644--- a/frontend/editor/src/core/components/onboarding/useOnboardingDownload.ts+++ b/frontend/editor/src/core/components/onboarding/useOnboardingDownload.ts@@ -6,7 +6,10 @@import { useState, useEffect, useMemo, useCallback } from "react";import { useOs } from "@app/hooks/useOs";-import { DOWNLOAD_URLS } from "@app/constants/downloads";+import {+ DESKTOP_DOWNLOAD_OPTIONS,+ desktopDownloadForOs,+} from "@app/components/onboarding/desktopDownloadOptions";interface OsInfo {label: string;@@ -31,29 +34,8 @@ export function useOnboardingDownload(): UseOnboardingDownloadResult {const osType = useOs();const [selectedDownloadUrl, setSelectedDownloadUrl] = useState<string>("");- const osInfo = useMemo<OsInfo>(() => {- switch (osType) {- case "windows":- return { label: "Windows", url: DOWNLOAD_URLS.WINDOWS };- case "mac":- return { label: "Mac", url: DOWNLOAD_URLS.MAC };- case "linux-x64":- case "linux-arm64":- return { label: "Linux", url: DOWNLOAD_URLS.LINUX_DOCS };- default:- return { label: "", url: "" };- }- }, [osType]);-- const osOptions = useMemo<OsOption[]>(- () =>- [- { label: "Windows", url: DOWNLOAD_URLS.WINDOWS, value: "windows" },- { label: "Mac", url: DOWNLOAD_URLS.MAC, value: "mac" },- { label: "Linux", url: DOWNLOAD_URLS.LINUX_DOCS, value: "linux" },- ].filter((opt) => opt.url),- [],- );+ const osInfo = useMemo<OsInfo>(() => desktopDownloadForOs(osType), [osType]);+ const osOptions: OsOption[] = DESKTOP_DOWNLOAD_OPTIONS;// Initialize selected URL from detected OSuseEffect(() => {diff --git a/frontend/editor/src/core/constants/downloads.ts b/frontend/editor/src/core/constants/downloads.tsindex cb5d2f21ba..d98711b893 100644--- a/frontend/editor/src/core/constants/downloads.ts+++ b/frontend/editor/src/core/constants/downloads.ts@@ -1,7 +1,11 @@// Centralized download URLs for Stirling PDF desktop installersexport const DOWNLOAD_URLS = {WINDOWS: "https://files.stirlingpdf.com/win-installer.exe",+ WINDOWS_ARM64: "https://files.stirlingpdf.com/win-arm64-installer.exe",MAC: "https://files.stirlingpdf.com/mac-installer.dmg",+ LINUX_DEB: "https://files.stirlingpdf.com/linux-installer.deb",+ LINUX_RPM: "https://files.stirlingpdf.com/linux-installer.rpm",+ LINUX_APPIMAGE: "https://files.stirlingpdf.com/linux-installer.AppImage",LINUX_DOCS: "https://docs.stirlingpdf.com/Installation/Unix%20Installation/",} as const;diff --git a/frontend/editor/src/core/constants/selfHosting.ts b/frontend/editor/src/core/constants/selfHosting.tsnew file mode 100644index 0000000000..d1562bcbd4--- /dev/null+++ b/frontend/editor/src/core/constants/selfHosting.ts@@ -0,0 +1,34 @@+import { DOWNLOAD_URLS } from "@app/constants/downloads";++export type DockerImageTag = "latest" | "latest-fat" | "latest-ultra-lite";++const DOCKER_IMAGE = "docker.stirlingpdf.com/stirlingtools/stirling-pdf";++export const dockerRunCommand = (tag: DockerImageTag = "latest") =>+ `docker run -d --name stirling-pdf -p 8080:8080 \\\n -v ./stirling-data:/configs \\\n ${DOCKER_IMAGE}:${tag}`;++export const DOCKER_COMPOSE_FILE = `# Save as docker-compose.yml, then run: docker compose up -d+services:+ stirling-pdf:+ image: ${DOCKER_IMAGE}:latest+ ports:+ - "8080:8080"+ volumes:+ - ./stirling-data:/configs+ restart: unless-stopped`;++export const HELM_INSTALL_COMMAND = `helm repo add stirling-pdf https://stirling-tools.github.io/Stirling-PDF-chart+helm repo update+helm install stirling-pdf stirling-pdf/stirling-pdf-chart \\\n --namespace stirling-pdf --create-namespace`;++export const SERVER_JAR_URL =+ "https://files.stirlingpdf.com/Stirling-PDF-with-login.jar";++export const JAR_RUN_COMMAND =+ "java -Xmx2g -jar Stirling-PDF-with-login.jar\n# then open http://localhost:8080";++export const SELF_HOST_GUIDES = {+ docker: "https://docs.stirlingpdf.com/Installation/Docker%20Install/",+ kubernetes: "https://docs.stirlingpdf.com/Installation/Kubernetes%20Install/",+ manual: DOWNLOAD_URLS.LINUX_DOCS,+} as const;diff --git a/frontend/editor/src/core/icons/icons.ts b/frontend/editor/src/core/icons/icons.tsindex dfaaa64ee0..6df644fd03 100644--- a/frontend/editor/src/core/icons/icons.ts+++ b/frontend/editor/src/core/icons/icons.ts@@ -8,6 +8,7 @@ import AlignEndHorizontal from "lucide-static/icons/align-end-horizontal.svg?reaimport AlignEndVertical from "lucide-static/icons/align-end-vertical.svg?react";import AlignStartHorizontal from "lucide-static/icons/align-start-horizontal.svg?react";import AlignStartVertical from "lucide-static/icons/align-start-vertical.svg?react";+import AppWindow from "lucide-static/icons/app-window.svg?react";import ArchiveRestore from "lucide-static/icons/archive-restore.svg?react";import ArrowDown from "lucide-static/icons/arrow-down.svg?react";import ArrowLeft from "lucide-static/icons/arrow-left.svg?react";@@ -164,6 +165,7 @@ import Italic from "lucide-static/icons/italic.svg?react";import Key from "lucide-static/icons/key.svg?react";import Keyboard from "lucide-static/icons/keyboard.svg?react";import Landmark from "lucide-static/icons/landmark.svg?react";+import Laptop from "lucide-static/icons/laptop.svg?react";import Layers from "lucide-static/icons/layers.svg?react";import LayersMinus from "lucide-static/icons/layers-minus.svg?react";import LayoutDashboard from "lucide-static/icons/layout-dashboard.svg?react";@@ -437,6 +439,7 @@ export const ICONS = {"align-end-vertical": { Component: AlignEndVertical, kind: "lucide" },"align-start-horizontal": { Component: AlignStartHorizontal, kind: "lucide" },"align-start-vertical": { Component: AlignStartVertical, kind: "lucide" },+ "app-window": { Component: AppWindow, kind: "lucide" },"archive-restore": { Component: ArchiveRestore, kind: "lucide" },"arrow-down": { Component: ArrowDown, kind: "lucide" },"arrow-left": { Component: ArrowLeft, kind: "lucide" },@@ -593,6 +596,7 @@ export const ICONS = {key: { Component: Key, kind: "lucide" },keyboard: { Component: Keyboard, kind: "lucide" },landmark: { Component: Landmark, kind: "lucide" },+ laptop: { Component: Laptop, kind: "lucide" },layers: { Component: Layers, kind: "lucide" },"layers-minus": { Component: LayersMinus, kind: "lucide" },"layout-dashboard": { Component: LayoutDashboard, kind: "lucide" },diff --git a/frontend/editor/src/portal/components/DownloadEditorModal.css b/frontend/editor/src/portal/components/DownloadEditorModal.cssindex ae369b67d4..908d906fad 100644--- a/frontend/editor/src/portal/components/DownloadEditorModal.css+++ b/frontend/editor/src/portal/components/DownloadEditorModal.css@@ -82,6 +82,12 @@width: 100%;}+.portal-install__row {+ display: grid;+ grid-template-columns: 1fr 1fr;+ gap: 0.5rem;+}+.portal-install__eyebrow {margin: 0;font-size: 0.6875rem;diff --git a/frontend/editor/src/portal/components/DownloadEditorModal.tsx b/frontend/editor/src/portal/components/DownloadEditorModal.tsxindex 21fcda5878..b1511ef413 100644--- a/frontend/editor/src/portal/components/DownloadEditorModal.tsx+++ b/frontend/editor/src/portal/components/DownloadEditorModal.tsx@@ -4,6 +4,14 @@ import { Button, CodeBlock, Modal, SegmentedControl } from "@app/ui";import { EDITOR_URL } from "@portal/auth/editorUrl";import { markEditorInstalled } from "@portal/hooks/useEditorInstalled";import { DOWNLOAD_URLS } from "@app/constants/downloads";+import {+ dockerRunCommand,+ HELM_INSTALL_COMMAND,+ JAR_RUN_COMMAND,+ SELF_HOST_GUIDES,+ SERVER_JAR_URL,+ type DockerImageTag,+} from "@app/constants/selfHosting";import { Icon, type IconName } from "@app/ui/Icon";import "@portal/components/DownloadEditorModal.css";@@ -13,26 +21,15 @@ import "@portal/components/DownloadEditorModal.css";const WINGET = "winget install StirlingTools.StirlingPDF";const BREW = "brew install --cask stirling-pdf";-const dockerCmd = (tag: string) =>- `docker run -d --name stirling-pdf -p 8080:8080 \\\n -v ./stirling-data:/configs \\\n stirlingtools/stirling-pdf:${tag}`;-const HELM = `helm repo add stirling-pdf https://stirling-tools.github.io/Stirling-PDF/-helm repo update-helm install stirling-pdf stirling-pdf/stirling-pdf-chart \\\n --namespace stirling-pdf --create-namespace`;-const JAR_URL = "https://files.stirlingpdf.com/Stirling-PDF-with-login.jar";-const JAR =- "java -Xmx2g -jar Stirling-PDF-with-login.jar\n# then open http://localhost:8080";-const GUIDES = {windows: "https://docs.stirlingpdf.com/Installation/Windows%20Installation/",mac: "https://docs.stirlingpdf.com/Installation/Mac%20Installation/",linux: DOWNLOAD_URLS.LINUX_DOCS,- docker: "https://docs.stirlingpdf.com/Installation/Docker%20Install",- kubernetes: "https://docs.stirlingpdf.com/Installation/Kubernetes",- manual: DOWNLOAD_URLS.LINUX_DOCS,+ ...SELF_HOST_GUIDES,} as const;type OptionId = keyof typeof GUIDES;-type DockerVariant = "latest" | "latest-fat" | "latest-ultra-lite";+type DockerVariant = DockerImageTag;const DESKTOP: OptionId[] = ["windows", "mac", "linux"];const SELF_HOSTED: OptionId[] = ["docker", "kubernetes", "manual"];@@ -127,14 +124,31 @@ export function DownloadEditorModal({ open, onClose }: Props) {case "linux":return (<>- {note("linux")}<Button- variant="secondary"- leftSection={<Icon name="external-link" size={16} />}- onClick={() => openUrl(GUIDES.linux)}+ variant="primary"+ leftSection={<Icon name="download" size={16} />}+ onClick={() => download(DOWNLOAD_URLS.LINUX_DEB)}>- {t("portal.home.download.linux.guideBtn")}+ {t("portal.home.download.linux.downloadDeb")}</Button>+ <div className="portal-install__row">+ <Button+ variant="secondary"+ leftSection={<Icon name="download" size={16} />}+ onClick={() => download(DOWNLOAD_URLS.LINUX_RPM)}+ >+ {t("portal.home.download.linux.downloadRpm")}+ </Button>+ <Button+ variant="secondary"+ leftSection={<Icon name="download" size={16} />}+ onClick={() => download(DOWNLOAD_URLS.LINUX_APPIMAGE)}+ >+ {t("portal.home.download.linux.downloadAppImage")}+ </Button>+ </div>+ {note("linux")}+ {guideLink("linux")}</>);case "docker":@@ -158,7 +172,7 @@ export function DownloadEditorModal({ open, onClose }: Props) {},]}/>- <CodeBlock code={dockerCmd(dockerVariant)} lang="bash" />+ <CodeBlock code={dockerRunCommand(dockerVariant)} lang="bash" />{note("docker")}{guideLink("docker")}</>@@ -166,7 +180,7 @@ export function DownloadEditorModal({ open, onClose }: Props) {case "kubernetes":return (<>- <CodeBlock code={HELM} lang="bash" />+ <CodeBlock code={HELM_INSTALL_COMMAND} lang="bash" />{note("kubernetes")}{guideLink("kubernetes")}</>@@ -177,14 +191,14 @@ export function DownloadEditorModal({ open, onClose }: Props) {<Buttonvariant="primary"leftSection={<Icon name="download" size={16} />}- onClick={() => download(JAR_URL)}+ onClick={() => download(SERVER_JAR_URL)}>{t("portal.home.download.manual.downloadBtn")}</Button><p className="portal-install__eyebrow">{t("portal.home.download.manual.runLabel")}</p>- <CodeBlock code={JAR} lang="bash" />+ <CodeBlock code={JAR_RUN_COMMAND} lang="bash" />{note("manual")}{guideLink("manual")}</>diff --git a/frontend/editor/src/proprietary/auth/ui/AuthShell.module.css b/frontend/editor/src/proprietary/auth/ui/AuthShell.module.cssindex 9690a8f08f..4477d64acc 100644--- a/frontend/editor/src/proprietary/auth/ui/AuthShell.module.css+++ b/frontend/editor/src/proprietary/auth/ui/AuthShell.module.css@@ -23,6 +23,22 @@box-shadow: 0 1.25rem 3.75rem rgba(0, 0, 0, 0.12);overflow-y: auto;overflow-x: hidden;+ transition: width var(--motion-slow);+}++@media (prefers-reduced-motion: reduce) {+ .authCard {+ transition: none;+ }+}++.authCardWide {+ width: min(36rem, 96vw);+ padding: 2.5rem;+}++.authCardWide .authContent {+ max-width: none;}.authCard::-webkit-scrollbar {diff --git a/frontend/editor/src/proprietary/auth/ui/AuthShell.tsx b/frontend/editor/src/proprietary/auth/ui/AuthShell.tsxindex 2b1f8f705c..7eb756872b 100644--- a/frontend/editor/src/proprietary/auth/ui/AuthShell.tsx+++ b/frontend/editor/src/proprietary/auth/ui/AuthShell.tsx@@ -5,6 +5,8 @@ export interface AuthShellProps {children: ReactNode;/** Optional fixed footer slot (the editor passes its legal/cookie footer). */footer?: ReactNode;+ /** `wide` fits content with code samples or side-by-side rows. Default `narrow`. */+ size?: "narrow" | "wide";}/**@@ -12,10 +14,18 @@ export interface AuthShellProps {* card centered on the screen. Purely presentational - callers provide the* form (children) and an optional footer.*/-export function AuthShell({ children, footer }: AuthShellProps) {+export function AuthShell({+ children,+ footer,+ size = "narrow",+}: AuthShellProps) {return (<div className={styles.authContainer}>- <div className={styles.authCard}>+ <div+ className={[styles.authCard, size === "wide" ? styles.authCardWide : ""]+ .filter(Boolean)+ .join(" ")}+ ><div className={styles.authContent}>{children}</div></div>{footer && (diff --git a/frontend/editor/src/saas/App.tsx b/frontend/editor/src/saas/App.tsxindex 0acf378e71..d6acdd4fbe 100644--- a/frontend/editor/src/saas/App.tsx+++ b/frontend/editor/src/saas/App.tsx@@ -1,9 +1,9 @@-import { Suspense, lazy, type ReactNode } from "react";+import { Suspense, lazy } from "react";import { Routes, Route, useLocation } from "react-router-dom";import { isAuthRoute } from "@app/utils/pathUtils";import { AppProviders } from "@app/components/AppProviders";-import { PreferencesProvider } from "@app/contexts/PreferencesContext";-import { ThemeProvider } from "@app/components/shared/ThemeProvider";+import { PublicRouteProviders } from "@app/components/PublicRouteProviders";+import { RunLocationGate } from "@app/components/runLocation/RunLocationGate";import { setBaseUrl } from "@app/constants/app";import type { AppConfig } from "@app/contexts/AppConfigContext";import { AppLayout } from "@app/components/AppLayout";@@ -42,17 +42,6 @@ function handleConfigLoaded(config: AppConfig) {if (config.baseUrl) setBaseUrl(config.baseUrl);}-// Minimal providers for the public, no-auth mobile-scanner page. Just theme +-// preferences, no AppProviders, so no auth and no backend bootstrap - it-// renders without a logged-in session.-function PublicRouteProviders({ children }: { children: ReactNode }) {- return (- <PreferencesProvider>- <ThemeProvider>{children}</ThemeProvider>- </PreferencesProvider>- );-}-/*** Onboarding / sign-up modals must never cover auth-flow pages (login, signup,* OAuth consent): they steal focus from the task the user was sent there to@@ -143,11 +132,14 @@ export default function App() {}/>- {/* Both apps, under a shared frame so the rail renders once outside them. */}- <Route element={<AppFrame />}>- {/* The portal: its own top-level shell, before the catch-all. */}- {getAdminRouteExtensions()}- <Route path="*" element={<MainApp />} />+ {/* Before the frame and auth, so a first visit sees the chooser alone. */}+ <Route element={<RunLocationGate />}>+ {/* Both apps, under a shared frame so the rail renders once outside them. */}+ <Route element={<AppFrame />}>+ {/* The portal: its own top-level shell, before the catch-all. */}+ {getAdminRouteExtensions()}+ <Route path="*" element={<MainApp />} />+ </Route></Route></Routes></Suspense>diff --git a/frontend/editor/src/saas/components/PublicRouteProviders.tsx b/frontend/editor/src/saas/components/PublicRouteProviders.tsxnew file mode 100644index 0000000000..82f6a1ac65--- /dev/null+++ b/frontend/editor/src/saas/components/PublicRouteProviders.tsx@@ -0,0 +1,15 @@+import type { ReactNode } from "react";+import { PreferencesProvider } from "@app/contexts/PreferencesContext";+import { ThemeProvider } from "@app/components/shared/ThemeProvider";++/**+ * Theme and preferences only, for pages that render without a session: no+ * AppProviders, so no auth and no backend bootstrap.+ */+export function PublicRouteProviders({ children }: { children: ReactNode }) {+ return (+ <PreferencesProvider>+ <ThemeProvider>{children}</ThemeProvider>+ </PreferencesProvider>+ );+}diff --git a/frontend/editor/src/saas/components/runLocation/AnimatedHeight.tsx b/frontend/editor/src/saas/components/runLocation/AnimatedHeight.tsxnew file mode 100644index 0000000000..6177c38396--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/AnimatedHeight.tsx@@ -0,0 +1,41 @@+import { useLayoutEffect, useRef, useState, type ReactNode } from "react";+import styles from "@app/components/runLocation/RunLocation.module.css";++/**+ * Eases its height to fit whatever it holds. CSS cannot transition to `auto`,+ * so the content is measured and the measured height applied. Clipping is only+ * on mid-transition: left on, it would cut off focus rings at the edges.+ */+export function AnimatedHeight({ children }: { children: ReactNode }) {+ const contentRef = useRef<HTMLDivElement>(null);+ const [height, setHeight] = useState<number>();+ const [animating, setAnimating] = useState(false);++ useLayoutEffect(() => {+ const content = contentRef.current;+ if (!content) return;+ const observer = new ResizeObserver(() => {+ const next = content.offsetHeight;+ setHeight((previous) => {+ if (previous !== undefined && previous !== next) setAnimating(true);+ return next;+ });+ });+ observer.observe(content);+ return () => observer.disconnect();+ }, []);++ return (+ <div+ className={[styles.animatedHeight, animating ? styles.animating : ""]+ .filter(Boolean)+ .join(" ")}+ style={{ height }}+ onTransitionEnd={(event) => {+ if (event.target === event.currentTarget) setAnimating(false);+ }}+ >+ <div ref={contentRef}>{children}</div>+ </div>+ );+}diff --git a/frontend/editor/src/saas/components/runLocation/DesktopDownloadStep.tsx b/frontend/editor/src/saas/components/runLocation/DesktopDownloadStep.tsxnew file mode 100644index 0000000000..bca37256fa--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/DesktopDownloadStep.tsx@@ -0,0 +1,117 @@+import { useEffect, useState } from "react";+import { useTranslation } from "react-i18next";+import { Button } from "@app/ui/Button";+import { Icon } from "@app/ui/Icon";+import { Select } from "@app/ui/Select";+import { RunLocationStepLayout } from "@app/components/runLocation/RunLocationStepLayout";+import {+ DESKTOP_TARGETS,+ detectDesktopTarget,+ getDesktopTarget,+ type DesktopTargetId,+} from "@app/components/runLocation/desktopTargets";+import { startDownload } from "@app/components/runLocation/startDownload";+import styles from "@app/components/runLocation/RunLocation.module.css";++interface DesktopDownloadStepProps {+ onBack: () => void;+}++export function DesktopDownloadStep({ onBack }: DesktopDownloadStepProps) {+ const { t } = useTranslation();+ const [targetId, setTargetId] = useState<DesktopTargetId>("mac");+ const [userPicked, setUserPicked] = useState(false);+ const [downloaded, setDownloaded] = useState(false);++ useEffect(() => {+ if (userPicked) return;+ let cancelled = false;+ void detectDesktopTarget().then((detected) => {+ if (!cancelled) setTargetId(detected);+ });+ return () => {+ cancelled = true;+ };+ }, [userPicked]);++ const target = getDesktopTarget(targetId);+ const platformName = t(+ `runLocation.desktop.platform.${target.platform}`,+ target.platform,+ );++ const options = DESKTOP_TARGETS.map(({ id }) => ({+ value: id,+ label: t(`runLocation.desktop.target.${id}`, id),+ }));++ const download = () => {+ if (target.guide) {+ window.open(target.url, "_blank", "noopener,noreferrer");+ return;+ }+ startDownload(target.url);+ setDownloaded(true);+ };++ return (+ <RunLocationStepLayout+ onBack={onBack}+ title={+ downloaded+ ? t("runLocation.desktop.startedTitle", "Your download has started")+ : t("runLocation.desktop.title", "Get the desktop app")+ }+ subtitle={+ downloaded+ ? t(+ "runLocation.desktop.startedSubtitle",+ "Check your Downloads folder, then open the installer.",+ )+ : t("runLocation.desktop.subtitle", "Download it and open it.")+ }+ >+ <div className={styles.settingRow}>+ <span className={styles.settingLabel} id="run-location-computer">+ {t("runLocation.desktop.computerLabel", "Your computer")}+ </span>+ <div className={styles.settingControl}>+ <Select+ aria-labelledby="run-location-computer"+ options={options}+ value={targetId}+ onChange={(value) => {+ if (!value) return;+ setUserPicked(true);+ setTargetId(value as DesktopTargetId);+ setDownloaded(false);+ }}+ />+ </div>+ </div>+ <Button+ variant={downloaded ? "secondary" : "primary"}+ fat+ fullWidth+ leftSection={+ <Icon name={target.guide ? "external-link" : "download"} size={18} />+ }+ onClick={download}+ >+ {target.guide+ ? t(+ "runLocation.desktop.guide",+ "Open the {{platform}} install guide",+ {+ platform: platformName,+ },+ )+ : downloaded+ ? t("runLocation.desktop.downloadAgain", "Download again")+ : t("runLocation.desktop.download", "Download for {{platform}}", {+ platform: platformName,+ })}+ </Button>+ </RunLocationStepLayout>+ );+}diff --git a/frontend/editor/src/saas/components/runLocation/RunLocation.module.css b/frontend/editor/src/saas/components/runLocation/RunLocation.module.cssnew file mode 100644index 0000000000..921366d0b3--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/RunLocation.module.css@@ -0,0 +1,228 @@+.header {+ display: flex;+ align-items: center;+ gap: var(--space-4);+ margin-bottom: var(--space-6);+}++.headerText {+ display: flex;+ flex-direction: column;+ gap: var(--space-1);+ min-width: 0;+}++.title {+ margin: 0;+ font-size: 1.25rem;+ font-weight: var(--font-weight-semibold);+ line-height: 1.3;+ color: var(--c-text);+}++.subtitle {+ margin: 0;+ font-size: 0.9375rem;+ line-height: 1.5;+ color: var(--c-text-muted);+}++.body {+ display: flex;+ flex-direction: column;+ gap: var(--space-4);+}++.choices {+ display: flex;+ flex-direction: column;+ gap: var(--space-3);+ margin: 0;+ padding: 0;+ border: 0;+}++.choice {+ display: flex;+ align-items: center;+ gap: var(--space-4);+ padding: var(--space-4);+ border: 1px solid var(--c-border);+ border-radius: var(--radius-lg);+ background: var(--c-surface);+ cursor: pointer;+ transition:+ border-color var(--motion-fast),+ background-color var(--motion-fast);+}++.choice:hover {+ background: var(--c-hover);+}++.choiceSelected {+ border-color: var(--c-primary-border);+ background: var(--c-primary-subtle);+}++.choiceSelected:hover {+ background: var(--c-primary-subtle);+}++.choice:has(.choiceInput:focus-visible) {+ outline: 2px solid var(--c-primary);+ outline-offset: 2px;+}++.choiceInput {+ position: absolute;+ opacity: 0;+ width: 0;+ height: 0;+}++.choiceIcon {+ flex: 0 0 auto;+ display: inline-flex;+ color: var(--c-text-muted);+}++.choiceText {+ flex: 1 1 auto;+ display: flex;+ flex-direction: column;+ gap: 0.125rem;+ min-width: 0;+}++.choiceTitle {+ font-size: 1rem;+ font-weight: var(--font-weight-semibold);+ color: var(--c-text);+}++.choiceDesc {+ font-size: 0.875rem;+ color: var(--c-text-muted);+}++.choiceDot {+ flex: 0 0 auto;+ width: 1.125rem;+ height: 1.125rem;+ border-radius: 50%;+ border: 1.5px solid var(--c-border-strong);+ display: inline-flex;+ align-items: center;+ justify-content: center;+}++.choiceSelected .choiceDot {+ border-color: var(--c-primary);+}++.choiceSelected .choiceDot::after {+ content: "";+ width: 0.5625rem;+ height: 0.5625rem;+ border-radius: 50%;+ background: var(--c-primary);+}++.settingRow {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: var(--space-4);+ padding: var(--space-3) 0;+ border-top: 1px solid var(--c-border-subtle);+ border-bottom: 1px solid var(--c-border-subtle);+}++.settingLabel {+ font-size: 0.9375rem;+ font-weight: var(--font-weight-semibold);+ color: var(--c-text);+ white-space: nowrap;+}++.settingControl {+ flex: 0 1 13rem;+ min-width: 0;+}++.note {+ display: flex;+ align-items: flex-start;+ gap: var(--space-2);+ margin: 0;+ padding: var(--space-3) var(--space-4);+ border-radius: var(--radius-md);+ background: var(--c-surface-sunken);+ font-size: 0.875rem;+ line-height: 1.45;+ color: var(--c-text-muted);+}++.noteBody {+ display: flex;+ flex-direction: column;+ align-items: flex-start;+ gap: var(--space-2);+ min-width: 0;+}++.noteText {+ margin: 0;+}++.inlineCode {+ padding: 0.0625rem 0.375rem;+ border: 1px solid var(--c-border-subtle);+ border-radius: var(--radius-sm);+ background: var(--c-surface);+ font-family: var(--font-mono);+ font-size: 0.8125rem;+ color: var(--c-text);+ white-space: nowrap;+}++.noteLink {+ display: inline-flex;+ align-items: center;+ gap: var(--space-1);+ font-weight: var(--font-weight-medium);+ color: var(--c-accent-fg, var(--c-primary));+ text-decoration: none;+}++.noteLink:hover {+ text-decoration: underline;+}++/* 1.75rem is the vertical padding of .sui-code__pre in CodeBlock.css; keep the+ two in sync or the longest command scrolls. */+.command :global(.sui-code__pre) {+ box-sizing: border-box;+ height: calc(var(--command-lines) * 1lh + 1.75rem);+}++.noteIcon {+ flex: 0 0 auto;+ margin-top: 0.0625rem;+ color: var(--c-accent-fg, var(--c-primary));+}++.animatedHeight {+ transition: height var(--motion-slow);+}++.animating {+ overflow: hidden;+}++@media (prefers-reduced-motion: reduce) {+ .animatedHeight {+ transition: none;+ }+}diff --git a/frontend/editor/src/saas/components/runLocation/RunLocationChooser.tsx b/frontend/editor/src/saas/components/runLocation/RunLocationChooser.tsxnew file mode 100644index 0000000000..ef85f92682--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/RunLocationChooser.tsx@@ -0,0 +1,126 @@+import { useState } from "react";+import { useTranslation } from "react-i18next";+import { AuthShell } from "@app/auth/ui/AuthShell";+import { Button } from "@app/ui/Button";+import { Icon, type IconName } from "@app/ui/Icon";+import { RunLocationStepLayout } from "@app/components/runLocation/RunLocationStepLayout";+import { AnimatedHeight } from "@app/components/runLocation/AnimatedHeight";+import { DesktopDownloadStep } from "@app/components/runLocation/DesktopDownloadStep";+import { SelfHostStep } from "@app/components/runLocation/SelfHostStep";+import { markRunLocationChosen } from "@app/components/runLocation/runLocationChosen";+import styles from "@app/components/runLocation/RunLocation.module.css";++type RunLocation = "browser" | "computer" | "server";++const CHOICES: {+ id: RunLocation;+ icon: IconName;+ title: string;+ description: string;+}[] = [+ {+ id: "browser",+ icon: "app-window",+ title: "In your browser",+ description: "The web app.",+ },+ {+ id: "computer",+ icon: "laptop",+ title: "On your computer",+ description: "The desktop app.",+ },+ {+ id: "server",+ icon: "server",+ title: "On your server",+ description: "Self-hosted, for a team.",+ },+];++interface RunLocationChooserProps {+ /** Leaves the chooser for the web app at the URL the visitor opened. */+ onContinueInBrowser: () => void;+}++/**+ * Asks where the visitor wants to run Stirling. Confirming any choice records+ * it as seen, whatever they then do on the desktop or server step.+ */+export function RunLocationChooser({+ onContinueInBrowser,+}: RunLocationChooserProps) {+ const { t } = useTranslation();+ const [selected, setSelected] = useState<RunLocation>("browser");+ const [confirmed, setConfirmed] = useState<RunLocation | null>(null);++ const confirm = () => {+ markRunLocationChosen();+ if (selected === "browser") {+ onContinueInBrowser();+ return;+ }+ setConfirmed(selected);+ };++ const back = () => setConfirmed(null);++ return (+ <AuthShell size={confirmed === "server" ? "wide" : "narrow"}>+ <AnimatedHeight>+ {confirmed === "computer" && <DesktopDownloadStep onBack={back} />}+ {confirmed === "server" && <SelfHostStep onBack={back} />}+ {confirmed === null && (+ <RunLocationStepLayout+ title={t("runLocation.title", "Where do you want to run Stirling?")}+ subtitle={t("runLocation.subtitle", "Choose where it runs.")}+ >+ <fieldset className={styles.choices}>+ <legend className="sr-only">+ {t("runLocation.title", "Where do you want to run Stirling?")}+ </legend>+ {CHOICES.map(({ id, icon, title, description }) => {+ const isSelected = selected === id;+ return (+ <label+ key={id}+ className={[+ styles.choice,+ isSelected ? styles.choiceSelected : "",+ ]+ .filter(Boolean)+ .join(" ")}+ >+ <input+ type="radio"+ name="run-location"+ value={id}+ checked={isSelected}+ onChange={() => setSelected(id)}+ className={styles.choiceInput}+ />+ <span className={styles.choiceIcon} aria-hidden>+ <Icon name={icon} size={24} />+ </span>+ <span className={styles.choiceText}>+ <span className={styles.choiceTitle}>+ {t(`runLocation.choice.${id}.title`, title)}+ </span>+ <span className={styles.choiceDesc}>+ {t(`runLocation.choice.${id}.description`, description)}+ </span>+ </span>+ <span className={styles.choiceDot} aria-hidden />+ </label>+ );+ })}+ </fieldset>+ <Button variant="primary" fat fullWidth onClick={confirm}>+ {t("runLocation.continue", "Continue")}+ </Button>+ </RunLocationStepLayout>+ )}+ </AnimatedHeight>+ </AuthShell>+ );+}diff --git a/frontend/editor/src/saas/components/runLocation/RunLocationGate.test.tsx b/frontend/editor/src/saas/components/runLocation/RunLocationGate.test.tsxnew file mode 100644index 0000000000..02dd3a81e1--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/RunLocationGate.test.tsx@@ -0,0 +1,132 @@+import { act, fireEvent, render, screen } from "@testing-library/react";+import { MantineProvider } from "@mantine/core";+import type { ReactNode } from "react";+import { MemoryRouter, Route, Routes } from "react-router-dom";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { RunLocationGate } from "@app/components/runLocation/RunLocationGate";+import { startDownload } from "@app/components/runLocation/startDownload";+import { DOWNLOAD_URLS } from "@app/constants/downloads";++vi.mock("@app/components/PublicRouteProviders", () => ({+ PublicRouteProviders: ({ children }: { children: ReactNode }) => (+ <MantineProvider>{children}</MantineProvider>+ ),+}));+vi.mock("react-i18next", () => ({+ Trans: ({ defaults }: { defaults: string }) => defaults,+ useTranslation: () => ({+ t: (_key: string, fallback: string, options: Record<string, string> = {}) =>+ fallback.replace(/\{\{(\w+)\}\}/g, (_, name: string) => options[name]),+ }),+}));+vi.mock("@app/components/runLocation/startDownload", () => ({+ startDownload: vi.fn(),+}));+// Detection reads the runner's own OS, so pin it: CI runs on Linux.+vi.mock(+ "@app/components/runLocation/desktopTargets",+ async (importOriginal) => ({+ ...(await importOriginal<+ typeof import("@app/components/runLocation/desktopTargets")+ >()),+ detectDesktopTarget: vi.fn(() => Promise.resolve("mac")),+ }),+);++const SEEN_KEY = "stirling.runLocationChosen.v1";++function renderAt(path: string) {+ return render(+ <MemoryRouter initialEntries={[path]}>+ <Routes>+ <Route element={<RunLocationGate />}>+ <Route path="*" element={<div>The app</div>} />+ </Route>+ </Routes>+ </MemoryRouter>,+ );+}++function choose(label: string) {+ fireEvent.click(screen.getByLabelText(new RegExp(label)));+ fireEvent.click(screen.getByRole("button", { name: "Continue" }));+}++describe("RunLocationGate", () => {+ beforeEach(() => {+ window.localStorage.clear();+ vi.mocked(startDownload).mockClear();+ });++ it("shows the chooser instead of the app on a first visit", () => {+ renderAt("/");+ expect(+ screen.getByRole("heading", {+ name: "Where do you want to run Stirling?",+ }),+ ).toBeInTheDocument();+ expect(screen.queryByText("The app")).not.toBeInTheDocument();+ });++ it("goes straight to the app once a choice has been confirmed", () => {+ window.localStorage.setItem(SEEN_KEY, "true");+ renderAt("/");+ expect(screen.getByText("The app")).toBeInTheDocument();+ });++ it("lets flow links through without recording a choice", () => {+ renderAt("/auth/callback");+ expect(screen.getByText("The app")).toBeInTheDocument();+ expect(window.localStorage.getItem(SEEN_KEY)).toBeNull();+ });++ it("opens the app and records the choice when browser is confirmed", () => {+ renderAt("/login");+ choose("In your browser");+ expect(screen.getByText("The app")).toBeInTheDocument();+ expect(window.localStorage.getItem(SEEN_KEY)).toBe("true");+ });++ it("records the choice before the desktop step and downloads on request", async () => {+ renderAt("/");+ choose("On your computer");+ expect(window.localStorage.getItem(SEEN_KEY)).toBe("true");+ // The step detects the visitor's OS asynchronously on mount; let that settle.+ await act(async () => {});+ expect(+ screen.getByRole("heading", { name: "Get the desktop app" }),+ ).toBeInTheDocument();++ fireEvent.click(screen.getByRole("button", { name: /Download for/ }));+ expect(startDownload).toHaveBeenCalledWith(DOWNLOAD_URLS.MAC);+ expect(+ screen.getByRole("heading", { name: "Your download has started" }),+ ).toBeInTheDocument();++ expect(screen.queryByText("The app")).not.toBeInTheDocument();+ });++ it("shows the server setup with a run command", () => {+ renderAt("/");+ choose("On your server");+ expect(window.localStorage.getItem(SEEN_KEY)).toBe("true");+ expect(+ screen.getByRole("heading", { name: "Set up your server" }),+ ).toBeInTheDocument();+ expect(+ screen.getByText(/stirlingtools\/stirling-pdf:latest/),+ ).toBeInTheDocument();+ });++ it("returns to the choices from a step, keeping what was picked", () => {+ renderAt("/");+ choose("On your server");+ fireEvent.click(screen.getByRole("button", { name: "Back" }));+ expect(+ screen.getByRole("heading", {+ name: "Where do you want to run Stirling?",+ }),+ ).toBeInTheDocument();+ expect(screen.getByLabelText(/On your server/)).toBeChecked();+ });+});diff --git a/frontend/editor/src/saas/components/runLocation/RunLocationGate.tsx b/frontend/editor/src/saas/components/runLocation/RunLocationGate.tsxnew file mode 100644index 0000000000..d90117fb04--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/RunLocationGate.tsx@@ -0,0 +1,41 @@+import { useState } from "react";+import { Outlet, useLocation } from "react-router-dom";+import { normalizePath } from "@app/utils/pathUtils";+import { PublicRouteProviders } from "@app/components/PublicRouteProviders";+import { RunLocationChooser } from "@app/components/runLocation/RunLocationChooser";+import { hasChosenRunLocation } from "@app/components/runLocation/runLocationChosen";++// Links that finish a flow already in progress (an emailed sign-in, an OAuth+// redirect, a shared file). Interrupting them with the chooser in a fresh+// browser would strand the visitor mid-flow, or lose the token in the URL.+const FLOW_PATHS = [+ "/auth/callback",+ "/auth/reset",+ "/oauth/consent",+ "/link",+ "/account-link/callback",+];++export function bypassesRunLocation(pathname: string): boolean {+ const path = normalizePath(pathname);+ return FLOW_PATHS.includes(path) || path.startsWith("/share/");+}++/**+ * Layout route that shows the run-location chooser ahead of everything else,+ * auth included, until this browser has confirmed a choice once.+ */+export function RunLocationGate() {+ const { pathname } = useLocation();+ const [showChooser, setShowChooser] = useState(() => !hasChosenRunLocation());++ if (!showChooser || bypassesRunLocation(pathname)) {+ return <Outlet />;+ }++ return (+ <PublicRouteProviders>+ <RunLocationChooser onContinueInBrowser={() => setShowChooser(false)} />+ </PublicRouteProviders>+ );+}diff --git a/frontend/editor/src/saas/components/runLocation/RunLocationStepLayout.tsx b/frontend/editor/src/saas/components/runLocation/RunLocationStepLayout.tsxnew file mode 100644index 0000000000..c61a1b1609--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/RunLocationStepLayout.tsx@@ -0,0 +1,48 @@+import type { ReactNode } from "react";+import { useTranslation } from "react-i18next";+import { Button } from "@app/ui/Button";+import { Icon } from "@app/ui/Icon";+import { Logo } from "@app/ui/Logo";+import styles from "@app/components/runLocation/RunLocation.module.css";++interface RunLocationStepLayoutProps {+ title: ReactNode;+ subtitle: ReactNode;+ children: ReactNode;+ /** Shows a back button below the content when set. */+ onBack?: () => void;+}++export function RunLocationStepLayout({+ title,+ subtitle,+ children,+ onBack,+}: RunLocationStepLayoutProps) {+ const { t } = useTranslation();+ return (+ <>+ <header className={styles.header}>+ <Logo variant="iconOnly" iconHeight="2.5rem" />+ <div className={styles.headerText}>+ <h1 className={styles.title}>{title}</h1>+ <p className={styles.subtitle}>{subtitle}</p>+ </div>+ </header>+ <div className={styles.body}>+ {children}+ {onBack && (+ <Button+ variant="secondary"+ fat+ fullWidth+ leftSection={<Icon name="arrow-left" size={18} />}+ onClick={onBack}+ >+ {t("runLocation.back", "Back")}+ </Button>+ )}+ </div>+ </>+ );+}diff --git a/frontend/editor/src/saas/components/runLocation/SelfHostStep.tsx b/frontend/editor/src/saas/components/runLocation/SelfHostStep.tsxnew file mode 100644index 0000000000..883f8ec2d8--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/SelfHostStep.tsx@@ -0,0 +1,148 @@+import { useState, type CSSProperties } from "react";+import { Trans, useTranslation } from "react-i18next";+import { Button } from "@app/ui/Button";+import { CodeBlock } from "@app/ui/CodeBlock";+import { Icon } from "@app/ui/Icon";+import { Select } from "@app/ui/Select";+import {+ DOCKER_COMPOSE_FILE,+ dockerRunCommand,+ HELM_INSTALL_COMMAND,+ JAR_RUN_COMMAND,+ SELF_HOST_GUIDES,+ SERVER_JAR_URL,+} from "@app/constants/selfHosting";+import { RunLocationStepLayout } from "@app/components/runLocation/RunLocationStepLayout";+import styles from "@app/components/runLocation/RunLocation.module.css";++type SelfHostMethod = "docker" | "compose" | "kubernetes" | "manual";++const COMMANDS: Record<SelfHostMethod, string> = {+ docker: dockerRunCommand(),+ compose: DOCKER_COMPOSE_FILE,+ kubernetes: HELM_INSTALL_COMMAND,+ manual: `curl -LO ${SERVER_JAR_URL}\n${JAR_RUN_COMMAND}`,+};++const GUIDES: Record<SelfHostMethod, string> = {+ docker: SELF_HOST_GUIDES.docker,+ compose: SELF_HOST_GUIDES.docker,+ kubernetes: SELF_HOST_GUIDES.kubernetes,+ manual: SELF_HOST_GUIDES.manual,+};++const METHODS: SelfHostMethod[] = ["docker", "compose", "kubernetes", "manual"];++// The command box is sized for the longest command, so switching method never+// resizes the card.+const COMMAND_LINES = Math.max(+ ...Object.values(COMMANDS).map((command) => command.split("\n").length),+);++const SERVER_URL = "http://<your-server>:8080";++const COPIED_RESET_MS = 1500;++interface SelfHostStepProps {+ onBack: () => void;+}++export function SelfHostStep({ onBack }: SelfHostStepProps) {+ const { t } = useTranslation();+ const [method, setMethod] = useState<SelfHostMethod>("docker");+ const [copied, setCopied] = useState(false);++ const methodName = (id: SelfHostMethod) =>+ t(`runLocation.server.method.${id}`, id);++ const copy = async () => {+ try {+ await navigator.clipboard.writeText(COMMANDS[method]);+ setCopied(true);+ setTimeout(() => setCopied(false), COPIED_RESET_MS);+ } catch {+ // Clipboard is blocked outside secure contexts; the command stays selectable.+ }+ };++ return (+ <RunLocationStepLayout+ onBack={onBack}+ title={t("runLocation.server.title", "Set up your server")}+ subtitle={t(+ "runLocation.server.subtitle",+ "Run this on your server, then open it in a browser.",+ )}+ >+ <div className={styles.settingRow}>+ <span className={styles.settingLabel} id="run-location-method">+ {t("runLocation.server.methodLabel", "Run it with")}+ </span>+ <div className={styles.settingControl}>+ <Select+ aria-labelledby="run-location-method"+ options={METHODS.map((id) => ({+ value: id,+ label: methodName(id),+ }))}+ value={method}+ onChange={(value) => {+ if (!value) return;+ setMethod(value as SelfHostMethod);+ setCopied(false);+ }}+ />+ </div>+ </div>+ <div+ className={styles.command}+ style={{ "--command-lines": COMMAND_LINES } as CSSProperties}+ >+ <CodeBlock+ code={COMMANDS[method]}+ lang={method === "compose" ? "plain" : "bash"}+ copyable={false}+ />+ </div>+ <Button+ variant="primary"+ fat+ fullWidth+ leftSection={<Icon name={copied ? "check" : "copy"} size={18} />}+ onClick={copy}+ >+ {copied+ ? t("runLocation.server.copied", "Copied")+ : method === "compose"+ ? t("runLocation.server.copyCompose", "Copy compose file")+ : t("runLocation.server.copy", "Copy command")}+ </Button>+ <div className={styles.note}>+ <Icon name="info" size={16} className={styles.noteIcon} />+ <div className={styles.noteBody}>+ <p className={styles.noteText}>+ <Trans+ t={t}+ i18nKey="runLocation.server.note"+ defaults="Then open <url/> to finish setup."+ components={{+ url: <code className={styles.inlineCode}>{SERVER_URL}</code>,+ }}+ />+ </p>+ <a+ className={styles.noteLink}+ href={GUIDES[method]}+ target="_blank"+ rel="noopener noreferrer"+ >+ {t("runLocation.server.guide", "{{method}} install guide", {+ method: methodName(method),+ })}+ <Icon name="external-link" size={14} />+ </a>+ </div>+ </div>+ </RunLocationStepLayout>+ );+}diff --git a/frontend/editor/src/saas/components/runLocation/desktopTargets.test.ts b/frontend/editor/src/saas/components/runLocation/desktopTargets.test.tsnew file mode 100644index 0000000000..601683cd1d--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/desktopTargets.test.ts@@ -0,0 +1,52 @@+import { describe, expect, it } from "vitest";+import { pickDesktopTarget } from "@app/components/runLocation/desktopTargets";++const MAC_UA =+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15";+const WINDOWS_UA =+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36";+const LINUX_UA =+ "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36";+const ANDROID_UA =+ "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Mobile Safari/537.36";++describe("pickDesktopTarget", () => {+ it("offers the universal Mac build whatever the chip", () => {+ expect(pickDesktopTarget(MAC_UA)).toBe("mac");+ expect(+ pickDesktopTarget(MAC_UA, { platform: "macOS", architecture: "x86" }),+ ).toBe("mac");+ expect(+ pickDesktopTarget(MAC_UA, { platform: "macOS", architecture: "arm" }),+ ).toBe("mac");+ });++ it("picks the Windows build matching the architecture", () => {+ expect(pickDesktopTarget(WINDOWS_UA)).toBe("windowsX64");+ expect(+ pickDesktopTarget(WINDOWS_UA, {+ platform: "Windows",+ architecture: "arm",+ }),+ ).toBe("windowsArm64");+ });++ it("offers the .deb on Linux", () => {+ expect(pickDesktopTarget(LINUX_UA)).toBe("linuxDeb");+ });++ it("sends Arm Linux, which has no build, to the install guide", () => {+ expect(+ pickDesktopTarget(LINUX_UA, { platform: "Linux", architecture: "arm" }),+ ).toBe("linuxArm64");+ expect(+ pickDesktopTarget(+ "Mozilla/5.0 (X11; Linux aarch64; rv:131.0) Gecko/20100101 Firefox/131.0",+ ),+ ).toBe("linuxArm64");+ });++ it("does not mistake Android for desktop Linux", () => {+ expect(pickDesktopTarget(ANDROID_UA)).toBe("mac");+ });+});diff --git a/frontend/editor/src/saas/components/runLocation/desktopTargets.ts b/frontend/editor/src/saas/components/runLocation/desktopTargets.tsnew file mode 100644index 0000000000..122ff53df8--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/desktopTargets.ts@@ -0,0 +1,109 @@+import { DOWNLOAD_URLS } from "@app/constants/downloads";++export type DesktopPlatform = "mac" | "windows" | "linux";++export type DesktopTargetId =+ | "mac"+ | "windowsX64"+ | "windowsArm64"+ | "linuxDeb"+ | "linuxRpm"+ | "linuxAppImage"+ | "linuxArm64";++export interface DesktopTarget {+ id: DesktopTargetId;+ platform: DesktopPlatform;+ url: string;+ /** No installer is built for this machine; `url` is the install guide instead. */+ guide?: boolean;+}++export const DESKTOP_TARGETS: readonly DesktopTarget[] = [+ { id: "mac", platform: "mac", url: DOWNLOAD_URLS.MAC },+ {+ id: "windowsX64",+ platform: "windows",+ url: DOWNLOAD_URLS.WINDOWS,+ },+ {+ id: "windowsArm64",+ platform: "windows",+ url: DOWNLOAD_URLS.WINDOWS_ARM64,+ },+ { id: "linuxDeb", platform: "linux", url: DOWNLOAD_URLS.LINUX_DEB },+ { id: "linuxRpm", platform: "linux", url: DOWNLOAD_URLS.LINUX_RPM },+ {+ id: "linuxAppImage",+ platform: "linux",+ url: DOWNLOAD_URLS.LINUX_APPIMAGE,+ },+ {+ id: "linuxArm64",+ platform: "linux",+ url: DOWNLOAD_URLS.LINUX_DOCS,+ guide: true,+ },+];++export function getDesktopTarget(id: DesktopTargetId): DesktopTarget {+ const target = DESKTOP_TARGETS.find((t) => t.id === id);+ if (!target) throw new Error(`Unknown desktop target: ${id}`);+ return target;+}++export interface PlatformHints {+ platform?: string;+ architecture?: string;+}++/**+ * Best guess at the installer for this machine. The architecture comes from+ * client hints, or for Linux the user agent too (Firefox names aarch64 there);+ * without either, Windows and Linux default to x64, the common case. Arm Linux,+ * which has no build, gets the install guide. Phones and unknown platforms fall+ * back to the Mac build.+ */+export function pickDesktopTarget(+ userAgent: string,+ hints: PlatformHints = {},+): DesktopTargetId {+ const platform = (hints.platform ?? "").toLowerCase();+ const ua = userAgent.toLowerCase();+ const isArm = (hints.architecture ?? "").toLowerCase().includes("arm");+ const linuxTarget: DesktopTargetId =+ isArm || /aarch64|arm64|armv\d/.test(ua) ? "linuxArm64" : "linuxDeb";++ if (+ platform.includes("windows") ||+ (!platform && ua.includes("windows nt"))+ ) {+ return isArm ? "windowsArm64" : "windowsX64";+ }+ if (platform.includes("linux") || platform.includes("chrome os")) {+ return linuxTarget;+ }+ if (!platform && /linux|x11/.test(ua) && !ua.includes("android")) {+ return linuxTarget;+ }+ return "mac";+}++interface UserAgentDataLike {+ getHighEntropyValues(hints: string[]): Promise<PlatformHints>;+}++export async function detectDesktopTarget(): Promise<DesktopTargetId> {+ const uaData = (+ navigator as Navigator & { userAgentData?: UserAgentDataLike }+ ).userAgentData;+ let hints: PlatformHints = {};+ if (uaData?.getHighEntropyValues) {+ try {+ hints = await uaData.getHighEntropyValues(["platform", "architecture"]);+ } catch {+ // Hints are an optional refinement; the user agent alone still works.+ }+ }+ return pickDesktopTarget(navigator.userAgent, hints);+}diff --git a/frontend/editor/src/saas/components/runLocation/runLocationChosen.ts b/frontend/editor/src/saas/components/runLocation/runLocationChosen.tsnew file mode 100644index 0000000000..3ca48b873b--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/runLocationChosen.ts@@ -0,0 +1,19 @@+// Versioned so a redesign of the chooser can be shown again to everyone.+const RUN_LOCATION_CHOSEN_KEY = "stirling.runLocationChosen.v1";++/** False when storage is unreadable, so a locked-down browser still gets the chooser. */+export function hasChosenRunLocation(): boolean {+ try {+ return window.localStorage.getItem(RUN_LOCATION_CHOSEN_KEY) === "true";+ } catch {+ return false;+ }+}++export function markRunLocationChosen(): void {+ try {+ window.localStorage.setItem(RUN_LOCATION_CHOSEN_KEY, "true");+ } catch {+ // Without storage the chooser simply shows again on the next load.+ }+}diff --git a/frontend/editor/src/saas/components/runLocation/startDownload.ts b/frontend/editor/src/saas/components/runLocation/startDownload.tsnew file mode 100644index 0000000000..6e355d5870--- /dev/null+++ b/frontend/editor/src/saas/components/runLocation/startDownload.ts@@ -0,0 +1,13 @@+/**+ * Starts a file download without leaving the page. The installer hosts answer+ * with Content-Disposition: attachment, so following the link downloads the+ * file and the current document stays put.+ */+export function startDownload(url: string): void {+ const anchor = document.createElement("a");+ anchor.href = url;+ anchor.rel = "noopener";+ document.body.appendChild(anchor);+ anchor.click();+ anchor.remove();+}