diff --git a/apps/desktop/src/main/app-routes.test.ts b/apps/desktop/src/main/app-routes.test.ts index f7218cd2af6..5e2684af8ec 100644 --- a/apps/desktop/src/main/app-routes.test.ts +++ b/apps/desktop/src/main/app-routes.test.ts @@ -5,8 +5,8 @@ vi.mock('electron', () => import('@/test/electron-mock')) import { settingsRoute } from '@/main/app-routes' describe('settingsRoute', () => { - it('opens the settings of the organization the user was last in', () => { - expect(settingsRoute('/o/org-1/search?q=x')).toBe('/o/org-1/settings/general') + it('opens the desktop settings of the organization the user was last in', () => { + expect(settingsRoute('/o/org-1/search?q=x')).toBe('/o/org-1/settings/desktop') }) it('keeps the desktop settings of the workspace the user was last in', () => { diff --git a/apps/desktop/src/main/app-routes.ts b/apps/desktop/src/main/app-routes.ts index 7f4065f2a17..4855e415558 100644 --- a/apps/desktop/src/main/app-routes.ts +++ b/apps/desktop/src/main/app-routes.ts @@ -54,8 +54,8 @@ export function newChatRoute(lastRoute: string | undefined): string { } /** - * Route for "Settings…": the settings of the workspace or organization the user - * was last in. Never the app entry, which lands on a page without settings. + * Route for "Settings…": the Desktop settings of the workspace or organization the + * user was last in. Never the app entry, which lands on a page without settings. */ export function settingsRoute(lastRoute: string | undefined): string { const workspaceId = workspaceIdFromRoute(lastRoute) @@ -63,7 +63,7 @@ export function settingsRoute(lastRoute: string | undefined): string { return `/workspace/${workspaceId}/settings/desktop` } const organizationId = organizationIdFromRoute(lastRoute) - return organizationId ? `/o/${organizationId}/settings/general` : SETTINGS_ENTRY_ROUTE + return organizationId ? `/o/${organizationId}/settings/desktop` : SETTINGS_ENTRY_ROUTE } /** diff --git a/apps/sim/app/o/[organizationId]/settings/navigation.test.ts b/apps/sim/app/o/[organizationId]/settings/navigation.test.ts index 675a7be8ba6..e49afa53ac2 100644 --- a/apps/sim/app/o/[organizationId]/settings/navigation.test.ts +++ b/apps/sim/app/o/[organizationId]/settings/navigation.test.ts @@ -3,7 +3,9 @@ import type { OrganizationSettingsFeatures } from '@/components/settings/navigat import { buildOrganizationNavItems } from '@/app/o/[organizationId]/components/organization-sidebar/navigation' import { organizationSettingsNavigation, + organizationSurfaceSettingsNavigation, resolveOrganizationSettingsSection, + resolveOrganizationSurfaceSection, } from '@/app/o/[organizationId]/settings/navigation' const enterprise: OrganizationSettingsFeatures = { @@ -15,6 +17,22 @@ const enterprise: OrganizationSettingsFeatures = { } describe('organization settings navigation', () => { + it('lists Desktop settings only inside the desktop app, where the page resolves', () => { + const ids = (desktopSettings: boolean) => + organizationSurfaceSettingsNavigation( + false, + enterprise, + { connectedAccounts: false, search: true, desktopSettings }, + false + ).map(({ id }) => id) + expect(ids(true)).toContain('desktop') + expect(ids(false)).not.toContain('desktop') + expect(resolveOrganizationSurfaceSection('/o/one/settings/desktop')).toEqual({ + plane: 'account', + section: 'desktop', + }) + }) + it('normalizes old section names and does not expose unsupported routes', () => { expect(resolveOrganizationSettingsSection('/o/one/settings/organization?query=person')).toBe( 'members' diff --git a/apps/sim/app/o/[organizationId]/settings/navigation.ts b/apps/sim/app/o/[organizationId]/settings/navigation.ts index 02f09bc926a..9f095910308 100644 --- a/apps/sim/app/o/[organizationId]/settings/navigation.ts +++ b/apps/sim/app/o/[organizationId]/settings/navigation.ts @@ -25,13 +25,15 @@ export type OrganizationSurfaceSettingsSection = /** * The account sections the organization surface hosts, rendered by the account - * plane's own renderer. General is the one that belongs to the person alone: the - * personal Subscription gives way to the organization's, which sits beside - * General in the Account group. Platform administration keeps the account - * plane's access rules; Desktop, Browser, and Terminal are workspace-bound. + * plane's own renderer. General and Desktop belong to the person and their device: + * the personal Subscription gives way to the organization's, which sits beside + * them in the Account group. Platform administration keeps the account plane's + * access rules; Browser and Terminal stay with the workspace chats that drive them. */ export const ORGANIZATION_SURFACE_ACCOUNT_ITEMS: SettingsNavigationItem[] = - ACCOUNT_SETTINGS_ITEMS.filter((item) => item.id === 'general' || item.group === 'platform') + ACCOUNT_SETTINGS_ITEMS.filter( + (item) => item.id === 'general' || item.id === 'desktop' || item.group === 'platform' + ) export function resolveOrganizationSettingsSection( path: string @@ -108,12 +110,20 @@ export function organizationSettingsNavigation( export function organizationSurfaceSettingsNavigation( isAdmin: boolean, features: OrganizationSettingsFeatures, - availability: { connectedAccounts: boolean; search: boolean; knowledgeGraphs?: boolean }, + availability: { + connectedAccounts: boolean + search: boolean + knowledgeGraphs?: boolean + /** Whether the desktop app hosts this page; Desktop settings exist only there. */ + desktopSettings?: boolean + }, isPlatformAdmin: boolean ): SettingsNavigationItem[] { return [ ...ORGANIZATION_SURFACE_ACCOUNT_ITEMS.filter( - (item) => item.group !== 'platform' || isPlatformAdmin + (item) => + (item.group !== 'platform' || isPlatformAdmin) && + (item.id !== 'desktop' || availability.desktopSettings === true) ), ...organizationSettingsNavigation(isAdmin, features, availability), ] diff --git a/apps/sim/app/o/[organizationId]/settings/organization-settings-sidebar.tsx b/apps/sim/app/o/[organizationId]/settings/organization-settings-sidebar.tsx index d0eaaf656dd..7a22d3b8e6d 100644 --- a/apps/sim/app/o/[organizationId]/settings/organization-settings-sidebar.tsx +++ b/apps/sim/app/o/[organizationId]/settings/organization-settings-sidebar.tsx @@ -11,6 +11,7 @@ import { hasPaidSubscriptionStatus, hasUsableSubscriptionAccess, } from '@/lib/billing/subscriptions/utils' +import { hasDesktopSettings } from '@/lib/desktop' import { organizationRoutes, WORKSPACE_SETTINGS_PATH } from '@/lib/navigation/paths' import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider' import { @@ -20,6 +21,7 @@ import { import { warmOrganizationSettingsSectionQuery } from '@/app/o/[organizationId]/settings/settings-query-warmers' import { useFeatureFlag } from '@/app/workspace/[workspaceId]/providers/feature-flags-provider' import { useOrganizationBillingSummary } from '@/hooks/queries/organization-billing-summary' +import { useHydrated } from '@/hooks/use-hydrated' interface OrganizationSettingsSidebarProps { isCollapsed: boolean @@ -31,6 +33,7 @@ export function OrganizationSettingsSidebar(props: OrganizationSettingsSidebarPr useOrganizationContext() const knowledgeGraphs = useFeatureFlag('mothership-memory-spaces') const pathname = usePathname() + const hydrated = useHydrated() const { data: session } = useSession() const queryClient = useQueryClient() const refreshPlan = viewer.isAdmin && settingsFeatures.hosted && settingsFeatures.billingEnabled @@ -76,6 +79,7 @@ export function OrganizationSettingsSidebar(props: OrganizationSettingsSidebarPr connectedAccounts: connectedAccountsAvailable, search: searchAccess.memberScoped, knowledgeGraphs, + desktopSettings: hydrated && hasDesktopSettings(), }, session?.user?.role === 'admin' )} diff --git a/apps/sim/app/workspace/[workspaceId]/settings/components/desktop/desktop.tsx b/apps/sim/app/workspace/[workspaceId]/settings/components/desktop/desktop.tsx index a1ba37a3061..39374edae73 100644 --- a/apps/sim/app/workspace/[workspaceId]/settings/components/desktop/desktop.tsx +++ b/apps/sim/app/workspace/[workspaceId]/settings/components/desktop/desktop.tsx @@ -7,7 +7,7 @@ import type { QuickChatShortcut, } from '@sim/desktop-bridge' import { Label, Switch, toast } from '@sim/emcn' -import { useParams, useRouter } from 'next/navigation' +import { usePathname, useRouter } from 'next/navigation' import { getDesktopBridge, getDesktopShellVersion } from '@/lib/desktop' import { ComputerUseSettings } from '@/app/workspace/[workspaceId]/settings/components/desktop/computer-use' import { QuickChatShortcutSelect } from '@/app/workspace/[workspaceId]/settings/components/desktop/quick-chat-shortcut-select' @@ -34,9 +34,8 @@ function PreferenceRow({ id, label, checked, disabled, onCheckedChange }: Prefer } export function Desktop() { - const params = useParams() + const pathname = usePathname() const router = useRouter() - const workspaceId = params.workspaceId as string const [preferences, setPreferences] = useState(null) const [pendingPreference, setPendingPreference] = useState(null) /** Whether Sim runs chats on this device in the background; only then can sleep matter. */ @@ -47,7 +46,8 @@ export function Desktop() { useEffect(() => { const bridge = getDesktopBridge() if (!bridge) { - router.replace(`/workspace/${workspaceId}/settings/general`) + // Workspace and organization settings both end in /desktop beside /general. + router.replace(pathname.replace(/\/desktop$/, '/general')) return } void bridge.settings @@ -59,7 +59,7 @@ export function Desktop() { .then((device) => setRunsInBackground(device !== null)) .catch(() => setRunsInBackground(false)) return bridge.settings.onFullFileAccessChanged?.(setPreferences) - }, [router, workspaceId]) + }, [router, pathname]) const updatePreference = async (key: DesktopPreferenceKey, value: boolean) => { const settings = getDesktopBridge()?.settings diff --git a/apps/sim/components/settings/account-settings-renderer.tsx b/apps/sim/components/settings/account-settings-renderer.tsx index 136d291c15f..dbc7db06162 100644 --- a/apps/sim/components/settings/account-settings-renderer.tsx +++ b/apps/sim/components/settings/account-settings-renderer.tsx @@ -20,6 +20,11 @@ const Admin = dynamic(() => (module) => module.Admin ) ) +const Desktop = dynamic(() => + import('@/app/workspace/[workspaceId]/settings/components/desktop/desktop').then( + (module) => module.Desktop + ) +) const Mothership = dynamic(() => import('@/app/workspace/[workspaceId]/settings/components/mothership/mothership').then( (module) => module.Mothership @@ -34,6 +39,7 @@ export function AccountSettingsRenderer({ section }: AccountSettingsRendererProp useCaptureWhenReady('settings_tab_viewed', { plane: 'account', section }, section) if (section === 'general') return + if (section === 'desktop') return if (section === 'billing') return if (section === 'api-keys') return if (section === 'admin') return diff --git a/apps/sim/components/settings/navigation.ts b/apps/sim/components/settings/navigation.ts index 468c1a280cb..3dfe2728de0 100644 --- a/apps/sim/components/settings/navigation.ts +++ b/apps/sim/components/settings/navigation.ts @@ -35,7 +35,13 @@ import { organizationRoutes } from '@/lib/navigation/paths' export type SettingsPlane = 'account' | 'selfhost' | 'workspace' -export type AccountSettingsSection = 'general' | 'billing' | 'api-keys' | 'admin' | 'mothership' +export type AccountSettingsSection = + | 'general' + | 'desktop' + | 'billing' + | 'api-keys' + | 'admin' + | 'mothership' /** * Settings a self-hoster needs from the managed service: their profile, what @@ -363,6 +369,8 @@ export const SETTINGS_SECTION_REGISTRY: readonly SettingsSectionRegistryEntry[] order: 2, requiresDesktopSurface: 'settings', }, + /** Device settings, not workspace data, so surfaces without a workspace host them too. */ + planes: { account: { id: 'desktop', group: 'account', order: 1 } }, }, { label: 'Browser', diff --git a/apps/sim/components/settings/standalone-settings-shell.tsx b/apps/sim/components/settings/standalone-settings-shell.tsx index 5fb8bf8d2d9..88a358387a6 100644 --- a/apps/sim/components/settings/standalone-settings-shell.tsx +++ b/apps/sim/components/settings/standalone-settings-shell.tsx @@ -24,7 +24,9 @@ import { SettingsPendingSection } from '@/components/settings/settings-pending-s import { SettingsSidebar } from '@/components/settings/settings-sidebar' import type { DeploymentShape } from '@/lib/api/contracts/workspaces' import { useDeploymentShape } from '@/lib/core/config/deployment-shape' +import { hasDesktopSettings } from '@/lib/desktop' import { SIDEBAR_NO_MOTION_CLASS } from '@/app/workspace/[workspaceId]/w/components/sidebar/constants' +import { useHydrated } from '@/hooks/use-hydrated' import { useSeedDeploymentShape } from '@/hooks/use-seed-deployment-shape' import { useSidebarWidth } from '@/hooks/use-sidebar-width' @@ -59,7 +61,9 @@ export function StandaloneSettingsShell(props: StandaloneSettingsShellProps) { useSidebarWidth() + const desktopSettings = useHydrated() && hasDesktopSettings() const accountItems = ACCOUNT_SETTINGS_ITEMS.filter((item) => { + if (item.id === 'desktop' && !desktopSettings) return false if (item.id === 'billing' && !billingEnabled) return false if ((item.id === 'admin' || item.id === 'mothership') && !isSuperUser) return false return true