Skip to content

Commit 87541cd

Browse files
authored
fix(desktop): show Desktop settings on the organization and account settings surfaces (#10144)
1 parent 10b0baa commit 87541cd

9 files changed

Lines changed: 68 additions & 18 deletions

File tree

‎apps/desktop/src/main/app-routes.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ vi.mock('electron', () => import('@/test/electron-mock'))
55
import { settingsRoute } from '@/main/app-routes'
66

77
describe('settingsRoute', () => {
8-
it('opens the settings of the organization the user was last in', () => {
9-
expect(settingsRoute('/o/org-1/search?q=x')).toBe('/o/org-1/settings/general')
8+
it('opens the desktop settings of the organization the user was last in', () => {
9+
expect(settingsRoute('/o/org-1/search?q=x')).toBe('/o/org-1/settings/desktop')
1010
})
1111

1212
it('keeps the desktop settings of the workspace the user was last in', () => {

‎apps/desktop/src/main/app-routes.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ export function newChatRoute(lastRoute: string | undefined): string {
5454
}
5555

5656
/**
57-
* Route for "Settings…": the settings of the workspace or organization the user
58-
* was last in. Never the app entry, which lands on a page without settings.
57+
* Route for "Settings…": the Desktop settings of the workspace or organization the
58+
* user was last in. Never the app entry, which lands on a page without settings.
5959
*/
6060
export function settingsRoute(lastRoute: string | undefined): string {
6161
const workspaceId = workspaceIdFromRoute(lastRoute)
6262
if (workspaceId) {
6363
return `/workspace/${workspaceId}/settings/desktop`
6464
}
6565
const organizationId = organizationIdFromRoute(lastRoute)
66-
return organizationId ? `/o/${organizationId}/settings/general` : SETTINGS_ENTRY_ROUTE
66+
return organizationId ? `/o/${organizationId}/settings/desktop` : SETTINGS_ENTRY_ROUTE
6767
}
6868

6969
/**

‎apps/sim/app/o/[organizationId]/settings/navigation.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import type { OrganizationSettingsFeatures } from '@/components/settings/navigat
33
import { buildOrganizationNavItems } from '@/app/o/[organizationId]/components/organization-sidebar/navigation'
44
import {
55
organizationSettingsNavigation,
6+
organizationSurfaceSettingsNavigation,
67
resolveOrganizationSettingsSection,
8+
resolveOrganizationSurfaceSection,
79
} from '@/app/o/[organizationId]/settings/navigation'
810

911
const enterprise: OrganizationSettingsFeatures = {
@@ -15,6 +17,22 @@ const enterprise: OrganizationSettingsFeatures = {
1517
}
1618

1719
describe('organization settings navigation', () => {
20+
it('lists Desktop settings only inside the desktop app, where the page resolves', () => {
21+
const ids = (desktopSettings: boolean) =>
22+
organizationSurfaceSettingsNavigation(
23+
false,
24+
enterprise,
25+
{ connectedAccounts: false, search: true, desktopSettings },
26+
false
27+
).map(({ id }) => id)
28+
expect(ids(true)).toContain('desktop')
29+
expect(ids(false)).not.toContain('desktop')
30+
expect(resolveOrganizationSurfaceSection('/o/one/settings/desktop')).toEqual({
31+
plane: 'account',
32+
section: 'desktop',
33+
})
34+
})
35+
1836
it('normalizes old section names and does not expose unsupported routes', () => {
1937
expect(resolveOrganizationSettingsSection('/o/one/settings/organization?query=person')).toBe(
2038
'members'

‎apps/sim/app/o/[organizationId]/settings/navigation.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ export type OrganizationSurfaceSettingsSection =
2525

2626
/**
2727
* The account sections the organization surface hosts, rendered by the account
28-
* plane's own renderer. General is the one that belongs to the person alone: the
29-
* personal Subscription gives way to the organization's, which sits beside
30-
* General in the Account group. Platform administration keeps the account
31-
* plane's access rules; Desktop, Browser, and Terminal are workspace-bound.
28+
* plane's own renderer. General and Desktop belong to the person and their device:
29+
* the personal Subscription gives way to the organization's, which sits beside
30+
* them in the Account group. Platform administration keeps the account plane's
31+
* access rules; Browser and Terminal stay with the workspace chats that drive them.
3232
*/
3333
export const ORGANIZATION_SURFACE_ACCOUNT_ITEMS: SettingsNavigationItem<AccountSettingsSection>[] =
34-
ACCOUNT_SETTINGS_ITEMS.filter((item) => item.id === 'general' || item.group === 'platform')
34+
ACCOUNT_SETTINGS_ITEMS.filter(
35+
(item) => item.id === 'general' || item.id === 'desktop' || item.group === 'platform'
36+
)
3537

3638
export function resolveOrganizationSettingsSection(
3739
path: string
@@ -108,12 +110,20 @@ export function organizationSettingsNavigation(
108110
export function organizationSurfaceSettingsNavigation(
109111
isAdmin: boolean,
110112
features: OrganizationSettingsFeatures,
111-
availability: { connectedAccounts: boolean; search: boolean; knowledgeGraphs?: boolean },
113+
availability: {
114+
connectedAccounts: boolean
115+
search: boolean
116+
knowledgeGraphs?: boolean
117+
/** Whether the desktop app hosts this page; Desktop settings exist only there. */
118+
desktopSettings?: boolean
119+
},
112120
isPlatformAdmin: boolean
113121
): SettingsNavigationItem<AccountSettingsSection | OrganizationSettingsSection>[] {
114122
return [
115123
...ORGANIZATION_SURFACE_ACCOUNT_ITEMS.filter(
116-
(item) => item.group !== 'platform' || isPlatformAdmin
124+
(item) =>
125+
(item.group !== 'platform' || isPlatformAdmin) &&
126+
(item.id !== 'desktop' || availability.desktopSettings === true)
117127
),
118128
...organizationSettingsNavigation(isAdmin, features, availability),
119129
]

‎apps/sim/app/o/[organizationId]/settings/organization-settings-sidebar.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
hasPaidSubscriptionStatus,
1212
hasUsableSubscriptionAccess,
1313
} from '@/lib/billing/subscriptions/utils'
14+
import { hasDesktopSettings } from '@/lib/desktop'
1415
import { organizationRoutes, WORKSPACE_SETTINGS_PATH } from '@/lib/navigation/paths'
1516
import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider'
1617
import {
@@ -20,6 +21,7 @@ import {
2021
import { warmOrganizationSettingsSectionQuery } from '@/app/o/[organizationId]/settings/settings-query-warmers'
2122
import { useFeatureFlag } from '@/app/workspace/[workspaceId]/providers/feature-flags-provider'
2223
import { useOrganizationBillingSummary } from '@/hooks/queries/organization-billing-summary'
24+
import { useHydrated } from '@/hooks/use-hydrated'
2325

2426
interface OrganizationSettingsSidebarProps {
2527
isCollapsed: boolean
@@ -31,6 +33,7 @@ export function OrganizationSettingsSidebar(props: OrganizationSettingsSidebarPr
3133
useOrganizationContext()
3234
const knowledgeGraphs = useFeatureFlag('mothership-memory-spaces')
3335
const pathname = usePathname()
36+
const hydrated = useHydrated()
3437
const { data: session } = useSession()
3538
const queryClient = useQueryClient()
3639
const refreshPlan = viewer.isAdmin && settingsFeatures.hosted && settingsFeatures.billingEnabled
@@ -76,6 +79,7 @@ export function OrganizationSettingsSidebar(props: OrganizationSettingsSidebarPr
7679
connectedAccounts: connectedAccountsAvailable,
7780
search: searchAccess.memberScoped,
7881
knowledgeGraphs,
82+
desktopSettings: hydrated && hasDesktopSettings(),
7983
},
8084
session?.user?.role === 'admin'
8185
)}

‎apps/sim/app/workspace/[workspaceId]/settings/components/desktop/desktop.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
QuickChatShortcut,
88
} from '@sim/desktop-bridge'
99
import { Label, Switch, toast } from '@sim/emcn'
10-
import { useParams, useRouter } from 'next/navigation'
10+
import { usePathname, useRouter } from 'next/navigation'
1111
import { getDesktopBridge, getDesktopShellVersion } from '@/lib/desktop'
1212
import { ComputerUseSettings } from '@/app/workspace/[workspaceId]/settings/components/desktop/computer-use'
1313
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
3434
}
3535

3636
export function Desktop() {
37-
const params = useParams()
37+
const pathname = usePathname()
3838
const router = useRouter()
39-
const workspaceId = params.workspaceId as string
4039
const [preferences, setPreferences] = useState<DesktopPreferences | null>(null)
4140
const [pendingPreference, setPendingPreference] = useState<DesktopPreferenceKey | null>(null)
4241
/** Whether Sim runs chats on this device in the background; only then can sleep matter. */
@@ -47,7 +46,8 @@ export function Desktop() {
4746
useEffect(() => {
4847
const bridge = getDesktopBridge()
4948
if (!bridge) {
50-
router.replace(`/workspace/${workspaceId}/settings/general`)
49+
// Workspace and organization settings both end in /desktop beside /general.
50+
router.replace(pathname.replace(/\/desktop$/, '/general'))
5151
return
5252
}
5353
void bridge.settings
@@ -59,7 +59,7 @@ export function Desktop() {
5959
.then((device) => setRunsInBackground(device !== null))
6060
.catch(() => setRunsInBackground(false))
6161
return bridge.settings.onFullFileAccessChanged?.(setPreferences)
62-
}, [router, workspaceId])
62+
}, [router, pathname])
6363

6464
const updatePreference = async (key: DesktopPreferenceKey, value: boolean) => {
6565
const settings = getDesktopBridge()?.settings

‎apps/sim/components/settings/account-settings-renderer.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const Admin = dynamic(() =>
2020
(module) => module.Admin
2121
)
2222
)
23+
const Desktop = dynamic(() =>
24+
import('@/app/workspace/[workspaceId]/settings/components/desktop/desktop').then(
25+
(module) => module.Desktop
26+
)
27+
)
2328
const Mothership = dynamic(() =>
2429
import('@/app/workspace/[workspaceId]/settings/components/mothership/mothership').then(
2530
(module) => module.Mothership
@@ -34,6 +39,7 @@ export function AccountSettingsRenderer({ section }: AccountSettingsRendererProp
3439
useCaptureWhenReady('settings_tab_viewed', { plane: 'account', section }, section)
3540

3641
if (section === 'general') return <General />
42+
if (section === 'desktop') return <Desktop />
3743
if (section === 'billing') return <Billing scope='account' />
3844
if (section === 'api-keys') return <ApiKeys scope='personal' />
3945
if (section === 'admin') return <Admin />

‎apps/sim/components/settings/navigation.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ import { organizationRoutes } from '@/lib/navigation/paths'
3535

3636
export type SettingsPlane = 'account' | 'selfhost' | 'workspace'
3737

38-
export type AccountSettingsSection = 'general' | 'billing' | 'api-keys' | 'admin' | 'mothership'
38+
export type AccountSettingsSection =
39+
| 'general'
40+
| 'desktop'
41+
| 'billing'
42+
| 'api-keys'
43+
| 'admin'
44+
| 'mothership'
3945

4046
/**
4147
* Settings a self-hoster needs from the managed service: their profile, what
@@ -363,6 +369,8 @@ export const SETTINGS_SECTION_REGISTRY: readonly SettingsSectionRegistryEntry[]
363369
order: 2,
364370
requiresDesktopSurface: 'settings',
365371
},
372+
/** Device settings, not workspace data, so surfaces without a workspace host them too. */
373+
planes: { account: { id: 'desktop', group: 'account', order: 1 } },
366374
},
367375
{
368376
label: 'Browser',

‎apps/sim/components/settings/standalone-settings-shell.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import { SettingsPendingSection } from '@/components/settings/settings-pending-s
2424
import { SettingsSidebar } from '@/components/settings/settings-sidebar'
2525
import type { DeploymentShape } from '@/lib/api/contracts/workspaces'
2626
import { useDeploymentShape } from '@/lib/core/config/deployment-shape'
27+
import { hasDesktopSettings } from '@/lib/desktop'
2728
import { SIDEBAR_NO_MOTION_CLASS } from '@/app/workspace/[workspaceId]/w/components/sidebar/constants'
29+
import { useHydrated } from '@/hooks/use-hydrated'
2830
import { useSeedDeploymentShape } from '@/hooks/use-seed-deployment-shape'
2931
import { useSidebarWidth } from '@/hooks/use-sidebar-width'
3032

@@ -59,7 +61,9 @@ export function StandaloneSettingsShell(props: StandaloneSettingsShellProps) {
5961

6062
useSidebarWidth()
6163

64+
const desktopSettings = useHydrated() && hasDesktopSettings()
6265
const accountItems = ACCOUNT_SETTINGS_ITEMS.filter((item) => {
66+
if (item.id === 'desktop' && !desktopSettings) return false
6367
if (item.id === 'billing' && !billingEnabled) return false
6468
if ((item.id === 'admin' || item.id === 'mothership') && !isSuperUser) return false
6569
return true

0 commit comments

Comments
 (0)