Skip to content

The agent that grows with you

fix(desktop): the statusbar profile picker in native Desktop is main's again

emozilla352ae01efce9
diff --git a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.test.tsx b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.test.tsx
index ae1141f4df5..47f2f00529f 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.test.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.test.tsx
@@ -3,6 +3,7 @@ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
import { atom } from 'nanostores'
import { afterEach, expect, it, vi } from 'vitest'
+import { refreshActiveProfile } from '@/store/profile'
import { $profileRailVisible } from '@/store/profile-rail-prefs'
import { ProfileSwitcher } from './profile-dropdown-switcher'
@@ -70,6 +71,44 @@ afterEach(() => {
cleanup()
$profileRailVisible.set(true)
vi.clearAllMocks()
+ vi.unstubAllGlobals()
+ delete window.document.documentElement.dataset.hermesDesktopHost
+})
+
+async function openDropdown() {
+ render(<ProfileSwitcher compact />)
+
+ const trigger = screen.getByRole('button', { name: 'Profiles: default' })
+ await act(async () => {
+ fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false, pointerType: 'mouse' })
+ await Promise.resolve()
+ })
+ await screen.findByRole('menuitemradio', { name: /clippy/ })
+}
+
+const launchMenuTriggers = () => window.document.querySelectorAll('[data-hermes-context-menu-trigger]')
+
+// Native Desktop's statusbar picker is main's: its rows carry no right-click
+// launch menu, and it leaves refreshing the profile list to the rail and
+// Manage Profiles.
+it('adds no right-click launch menu and no focus refresh in native Desktop', async () => {
+ vi.stubGlobal('hermesDesktop', {})
+ act(() => $profileRailVisible.set(false))
+ await openDropdown()
+
+ expect(launchMenuTriggers()).toHaveLength(0)
+ expect(refreshActiveProfile).not.toHaveBeenCalled()
+})
+
+// The Webapp always shows this dropdown instead of the rail's squares, so it
+// carries the rail's right-click launch menu and refreshes the list on focus.
+it('carries the rail\'s launch menu and focus refresh in browser-hosted Desktop', async () => {
+ window.document.documentElement.dataset.hermesDesktopHost = 'browser'
+ act(() => $profileRailVisible.set(false))
+ await openDropdown()
+
+ expect(launchMenuTriggers().length).toBeGreaterThan(0)
+ expect(refreshActiveProfile).toHaveBeenCalled()
})
it('switches profiles from the statusbar dropdown while the rail is hidden', async () => {
diff --git a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
index d9f8b6f076c..08699e9616b 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-dropdown-switcher.tsx
@@ -18,6 +18,7 @@ import { ProfileGlyph } from '@/components/ui/profile-glyph'
import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
import { Loader2 } from '@/lib/icons'
+import { isBrowserHostedDesktop } from '@/lib/platform'
import { resolveProfileColor } from '@/lib/profile-color'
import { cn } from '@/lib/utils'
import {
@@ -61,10 +62,10 @@ import { useProfileRailRefreshOnActive } from './use-profile-rail-refresh-on-act
* The profile picker that sits beside the gateway switcher in the statusbar
* while the colored rail is hidden — the same choices the rail offers (this
* gateway's profiles, every other gateway's agents in fleet mode, new / import
- * / manage, right-click open-in-new-window / set-as-default) in a dropdown that
- * reads like its neighbour. The rail keeps the gestures that need squares
- * (drag-order, hold-to-recolor); this is the plain-dropdown door for people who
- * run profiles as bots and don't want a strip of them.
+ * / manage; in the Webapp also right-click open-in-new-window / set-as-default)
+ * in a dropdown that reads like its neighbour. The rail keeps the gestures that
+ * need squares (drag-order, hold-to-recolor); this is the plain-dropdown door
+ * for people who run profiles as bots and don't want a strip of them.
*/
export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
const { t } = useI18n()
@@ -84,8 +85,11 @@ export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
const { dialog: localDeviceDialog, request: requestLocalDevice } = useLocalDeviceSwitch()
useFleetRoster(multipleConnections)
- // Stands in for the rail, so it keeps the list fresh the same way.
- useProfileRailRefreshOnActive()
+ // The Webapp always takes this dropdown in place of the rail's squares
+ // (profile-switcher.tsx), so there it keeps the list fresh the same way and
+ // carries the rail's right-click launch menu. Native Desktop's picker is main's.
+ const browserHost = isBrowserHostedDesktop()
+ useProfileRailRefreshOnActive(browserHost)
// The `profile.create` hotkey bumps this request atom; the rail answers it
// while mounted, so with the rail hidden this picker owns the dialog instead.
@@ -219,6 +223,7 @@ export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
isDefault={profile.is_default}
key={profile.name}
label={profileLabel(profile)}
+ launchMenu={browserHost}
name={profile.name}
/>
))}
@@ -239,16 +244,20 @@ export function ProfileSwitcher({ compact = false }: { compact?: boolean }) {
key={group.connectionId}
onSelect={switchToRest}
slot="profile-switcher-gateway"
- wrapRow={(row, agent, label) => (
- <ProfileLaunchContextMenu
- connectionId={agent.connectionId}
- key={agent.profile}
- label={label}
- profile={agent.profile}
- >
- {row}
- </ProfileLaunchContextMenu>
- )}
+ wrapRow={
+ browserHost
+ ? (row, agent, label) => (
+ <ProfileLaunchContextMenu
+ connectionId={agent.connectionId}
+ key={agent.profile}
+ label={label}
+ profile={agent.profile}
+ >
+ {row}
+ </ProfileLaunchContextMenu>
+ )
+ : undefined
+ }
/>
))}
<DropdownMenuSeparator />
@@ -286,26 +295,34 @@ interface ProfileItemProps {
connectionId: null | string
isDefault: boolean
label: string
+ /** Wrap the row in the rail's right-click launch menu (the Webapp's picker). */
+ launchMenu: boolean
name: string
}
-function ProfileItem({ color, connectionId, isDefault, label, name }: ProfileItemProps) {
+function ProfileItem({ color, connectionId, isDefault, label, launchMenu, name }: ProfileItemProps) {
const { cancelPrewarm, notePointerMove, startPrewarm } = useProfilePrewarm(name, prewarmProfilePick)
- return (
+ const row = (
+ <DropdownMenuRadioItem
+ className="min-w-0"
+ onPointerEnter={startPrewarm}
+ onPointerLeave={cancelPrewarm}
+ onPointerMove={notePointerMove}
+ value={name}
+ >
+ <span className="flex min-w-0 items-center gap-1.5">
+ <ProfileGlyph aria-hidden="true" color={color} isDefault={isDefault} name={name} />
+ <span className="truncate">{label}</span>
+ </span>
+ </DropdownMenuRadioItem>
+ )
+
+ return launchMenu ? (
<ProfileLaunchContextMenu connectionId={connectionId} label={label} profile={name}>
- <DropdownMenuRadioItem
- className="min-w-0"
- onPointerEnter={startPrewarm}
- onPointerLeave={cancelPrewarm}
- onPointerMove={notePointerMove}
- value={name}
- >
- <span className="flex min-w-0 items-center gap-1.5">
- <ProfileGlyph aria-hidden="true" color={color} isDefault={isDefault} name={name} />
- <span className="truncate">{label}</span>
- </span>
- </DropdownMenuRadioItem>
+ {row}
</ProfileLaunchContextMenu>
+ ) : (
+ row
)
}
diff --git a/apps/desktop/src/app/chat/sidebar/use-profile-rail-refresh-on-active.ts b/apps/desktop/src/app/chat/sidebar/use-profile-rail-refresh-on-active.ts
index 685ba3deee5..0cc22fd7a84 100644
--- a/apps/desktop/src/app/chat/sidebar/use-profile-rail-refresh-on-active.ts
+++ b/apps/desktop/src/app/chat/sidebar/use-profile-rail-refresh-on-active.ts
@@ -14,9 +14,15 @@ import { refreshActiveProfile } from '@/store/profile'
* used elsewhere in the sidebar (see refreshProjects/refreshProjectTree).
* Extracted into its own hook (rather than left inline in ProfileRail) so the
* focus/visibility wiring is unit-testable without rendering the whole rail.
+ * `enabled` false skips it, for a picker that only stands in for the rail on
+ * some hosts.
*/
-export function useProfileRailRefreshOnActive(): void {
+export function useProfileRailRefreshOnActive(enabled = true): void {
useEffect(() => {
+ if (!enabled) {
+ return
+ }
+
void refreshActiveProfile()
const onActive = () => {
@@ -34,5 +40,5 @@ export function useProfileRailRefreshOnActive(): void {
window.removeEventListener('focus', onActive)
document.removeEventListener('visibilitychange', onActive)
}
- }, [])
+ }, [enabled])
}