A full-featured download manager.
fix(sidebar): unify selection and default to cyan (#2208)
Dr_rOot45c9a7fa3fd6
diff --git a/e2e/settings-persistence.spec.ts b/e2e/settings-persistence.spec.tsindex 7050ec2b..3641c392 100644--- a/e2e/settings-persistence.spec.ts+++ b/e2e/settings-persistence.spec.ts@@ -231,15 +231,16 @@ test('sidebar glass color previews, cancels, and survives restart after save', atry {let main = await openMain(app)await openAppearance(main)- await main.getByRole('radio', { name: 'Cyan' }).check()+ await expect(main.getByRole('radio', { name: 'Cyan' })).toBeChecked()+ await main.getByRole('radio', { name: 'Gray' }).check()await expect(main.locator('html')).toHaveAttribute('data-sidebar-color',- 'cyan'+ 'gray')await main.getByRole('button', { name: 'Cancel', exact: true }).click()await expect(main.locator('html')).toHaveAttribute('data-sidebar-color',- 'gray'+ 'cyan')await openAppearance(main)await main.getByRole('radio', { name: 'Violet' }).check()diff --git a/e2e/sidebar-selection.spec.ts b/e2e/sidebar-selection.spec.tsnew file mode 100644index 00000000..957b5fe0--- /dev/null+++ b/e2e/sidebar-selection.spec.ts@@ -0,0 +1,90 @@+import { expect, test } from './fixtures/electron-app'++const destinations = [+ 'Dashboard',+ 'Downloads',+ 'Trackers',+ 'Plugins',+ 'Notifications',+ 'Settings',+]++for (const platform of ['win32', 'linux', 'darwin']) {+ test(`sidebar selection remains distinct across the gradient (${platform} CSS)`, async ({+ mainWindow,+ }, testInfo) => {+ test.setTimeout(120_000)+ await expect(mainWindow.locator('html')).toHaveAttribute(+ 'data-sidebar-color',+ 'cyan'+ )++ // Exercise platform CSS in the real renderer, without pretending to test+ // native Windows/Linux window materials on a macOS test host.+ for (const theme of ['light', 'dark']) {+ for (const color of ['gray', 'blue', 'cyan']) {+ await mainWindow.evaluate(+ ({ platform, theme, color }) => {+ const root = document.documentElement+ root.classList.remove(+ 'platform-win32',+ 'platform-linux',+ 'platform-darwin'+ )+ root.classList.add(`platform-${platform}`)+ root.classList.toggle('dark', theme === 'dark')+ root.dataset.sidebarColor = color+ },+ { platform, theme, color }+ )++ let selectedBackground: string | undefined+ for (const destination of destinations) {+ const link = mainWindow.getByRole('link', {+ name: destination,+ exact: true,+ })+ const button = link.locator('[data-sidebar="menu-button"]')+ await link.click()+ await mainWindow.mouse.move(500, 45)+ await expect(button).toHaveAttribute('data-active', 'true')+ const background = await button.evaluate(+ (element) => getComputedStyle(element).backgroundColor+ )+ const channels = background.match(/[\d.]+/g)?.map(Number)+ expect(channels).toHaveLength(4)+ const [red, green, blue, alpha] = channels!+ expect([red, green, blue]).toEqual(+ theme === 'light' ? [0, 0, 0] : [255, 255, 255]+ )+ expect(alpha).toBeGreaterThan(0)+ expect(alpha).toBeLessThan(1)+ selectedBackground ??= background+ expect(background).toBe(selectedBackground)++ // Hovering a selected item must not replace the selected fill.+ await link.hover()+ await expect(button).toHaveCSS('background-color', background)+ const other = mainWindow.getByRole('link', {+ name: destination === 'Dashboard' ? 'Settings' : 'Dashboard',+ exact: true,+ })+ await other.hover()+ const hoverBackground = await other+ .locator('[data-sidebar="menu-button"]')+ .evaluate((element) => getComputedStyle(element).backgroundColor)+ const hoverAlpha = Number(hoverBackground.match(/[\d.]+/g)?.[3])+ expect(hoverAlpha).toBeGreaterThan(0)+ expect(hoverAlpha).toBeLessThan(alpha)+ }++ await mainWindow.mouse.move(500, 45)+ await mainWindow.screenshot({+ path: testInfo.outputPath(+ `sidebar-${platform}-${theme}-${color}.png`+ ),+ })+ }+ }+ })+}diff --git a/src/renderer/components/ui/sidebar.tsx b/src/renderer/components/ui/sidebar.tsxindex d8be95b2..3289a47c 100644--- a/src/renderer/components/ui/sidebar.tsx+++ b/src/renderer/components/ui/sidebar.tsx@@ -503,7 +503,7 @@ function SidebarMenuItem({ className, ...props }: React.ComponentProps<'li'>) {}const sidebarMenuButtonVariants = cva(- 'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground data-popup-open:hover:bg-sidebar-accent data-popup-open:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',+ 'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-active active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-active data-[active=true]:hover:bg-sidebar-active data-[active=true]:text-sidebar-accent-foreground data-popup-open:hover:bg-sidebar-accent data-popup-open:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',{variants: {variant: {@@ -723,8 +723,8 @@ function SidebarMenuSubButton({'data-size': size,'data-active': isActive,className: cn(- 'flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground ring-sidebar-ring outline-hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground',- 'data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground',+ 'flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground ring-sidebar-ring outline-hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-active active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground',+ 'data-[active=true]:bg-sidebar-active data-[active=true]:hover:bg-sidebar-active data-[active=true]:text-sidebar-accent-foreground',size === 'sm' && 'text-xs',size === 'md' && 'text-sm','group-data-[collapsible=icon]:hidden',diff --git a/src/renderer/hooks/use-sidebar-color.test.tsx b/src/renderer/hooks/use-sidebar-color.test.tsxindex 5afb87f2..3c12e42b 100644--- a/src/renderer/hooks/use-sidebar-color.test.tsx+++ b/src/renderer/hooks/use-sidebar-color.test.tsx@@ -2,6 +2,7 @@ import { refreshRendererSettings } from '@renderer/lib/settings-refresh'import { useSidebarColorState } from '@renderer/lib/sidebar-color'import { transport } from '@renderer/lib/transport'import { Events } from '@shared/protocol/events'+import { DEFAULT_APP_SETTINGS } from '@shared/schemas/app-settings'import { act, renderHook, waitFor } from '@testing-library/react'import { beforeEach, expect, it, vi } from 'vitest'import { useSidebarColor } from './use-sidebar-color'@@ -16,7 +17,11 @@ vi.mock('@renderer/lib/transport', () => ({}))beforeEach(() => {vi.clearAllMocks()- useSidebarColorState.setState({ saved: 'gray', preview: null, revision: 0 })+ useSidebarColorState.setState({+ saved: DEFAULT_APP_SETTINGS.sidebarColor,+ preview: null,+ revision: 0,+ })})it('hydrates, previews, restores, and refreshes the saved tint after reconnect', async () => {vi.mocked(transport.invoke).mockResolvedValue({@@ -116,3 +121,14 @@ it('follows system accent changes in Auto and leaves manual choices independent'await act(async () => refresh())expect(document.documentElement.dataset.sidebarColor).toBe('gray')})++it.each([undefined, 'unknown'])(+ 'uses the cyan default for missing or invalid saved color %s',+ async (sidebarColor) => {+ vi.mocked(transport.invoke).mockResolvedValue({ app: { sidebarColor } })+ renderHook(useSidebarColor)+ await waitFor(() =>+ expect(document.documentElement.dataset.sidebarColor).toBe('cyan')+ )+ }+)diff --git a/src/renderer/hooks/use-sidebar-color.ts b/src/renderer/hooks/use-sidebar-color.tsindex f8708f58..35772eb5 100644--- a/src/renderer/hooks/use-sidebar-color.ts+++ b/src/renderer/hooks/use-sidebar-color.ts@@ -3,6 +3,7 @@ import { systemAccentHue } from '@renderer/lib/system-accent-color'import { transport } from '@renderer/lib/transport'import { Events } from '@shared/protocol/events'import { Queries } from '@shared/protocol/queries'+import { DEFAULT_APP_SETTINGS } from '@shared/schemas/app-settings'import { sidebarColorSchema } from '@shared/schemas/sidebar-color'import type { AppSettings } from '@shared/types/settings'import { useEffect, useState } from 'react'@@ -36,7 +37,7 @@ export function useSidebarColor() {returnuseSidebarColorState.setState({saved: sidebarColorSchema- .catch('gray')+ .catch(DEFAULT_APP_SETTINGS.sidebarColor).parse(settings?.app?.sidebarColor),})},diff --git a/src/renderer/lib/sidebar-color.ts b/src/renderer/lib/sidebar-color.tsindex c34ab96c..a45ab45d 100644--- a/src/renderer/lib/sidebar-color.ts+++ b/src/renderer/lib/sidebar-color.ts@@ -1,3 +1,4 @@+import { DEFAULT_APP_SETTINGS } from '@shared/schemas/app-settings'import type { SidebarColor } from '@shared/schemas/sidebar-color'import { create } from 'zustand'@@ -6,4 +7,8 @@ export const useSidebarColorState = create<{saved: SidebarColorpreview: SidebarColor | nullrevision: number-}>(() => ({ saved: 'gray', preview: null, revision: 0 }))+}>(() => ({+ saved: DEFAULT_APP_SETTINGS.sidebarColor,+ preview: null,+ revision: 0,+}))diff --git a/src/renderer/routes/settings/cards/appearance-dialog.test.tsx b/src/renderer/routes/settings/cards/appearance-dialog.test.tsxindex 1499aee9..c0016ae0 100644--- a/src/renderer/routes/settings/cards/appearance-dialog.test.tsx+++ b/src/renderer/routes/settings/cards/appearance-dialog.test.tsx@@ -28,6 +28,7 @@ class MockResizeObserver {const FIXTURE = {app: {theme: 'system',+ sidebarColor: 'gray',language: 'en-US',traySpeedometer: false,runMode: 1, // RunMode.Standard — numeric enumdiff --git a/src/renderer/styles/globals.css b/src/renderer/styles/globals.cssindex 13b2dd7f..8ec835b0 100644--- a/src/renderer/styles/globals.css+++ b/src/renderer/styles/globals.css@@ -89,6 +89,7 @@--color-sidebar-primary: var(--sidebar-primary);--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);--color-sidebar-accent: var(--sidebar-accent);+ --color-sidebar-active: var(--sidebar-active);--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);--color-sidebar-border: var(--sidebar-border);--color-sidebar-ring: var(--sidebar-ring);@@ -155,7 +156,9 @@--sidebar-foreground: oklch(0.145 0 0);--sidebar-primary: oklch(0.205 0 0);--sidebar-primary-foreground: oklch(0.985 0 0);- --sidebar-accent: oklch(0.97 0 0);+ /* Neutral overlays keep navigation states legible across the sidebar gradient. */+ --sidebar-accent: rgb(0 0 0 / 4%);+ --sidebar-active: rgb(0 0 0 / 9%);--sidebar-accent-foreground: oklch(0.205 0 0);--sidebar-border: oklch(0.922 0 0);--sidebar-ring: oklch(0.708 0 0);@@ -276,7 +279,8 @@--sidebar-foreground: oklch(0.985 0 0);--sidebar-primary: oklch(0.488 0.243 264.376);--sidebar-primary-foreground: oklch(0.985 0 0);- --sidebar-accent: oklch(0.269 0 0);+ --sidebar-accent: rgb(255 255 255 / 6%);+ --sidebar-active: rgb(255 255 255 / 14%);--sidebar-accent-foreground: oklch(0.985 0 0);--sidebar-border: oklch(1 0 0 / 10%);--sidebar-ring: oklch(0.556 0 0);@@ -463,45 +467,6 @@ body.is-dashboard-resizing * {user-select: none;}-/*- * macOS main window: sidebar menu item hover/active color.- * Overrides --sidebar-accent, which is referenced by BOTH hover- * (sidebar.tsx:485) and data-[active=true] (sidebar.tsx:489) in- * the menu button. Scoping to .platform-darwin.window-main means- * non-darwin platforms keep their solid #ebebf2 / #3d4056 fallback.- *- * Custom-property overrides aren't subject to the @layer ordering- * trap that bit us earlier — properties are resolved at use site,- * so utility classes like bg-sidebar-accent pick up our value- * regardless of where this block lives.- *- * Estimated to match macOS 26 Finder focused-selection tint.- * Verify with Digital Color Meter (⇧⌘C) and tune alpha if needed.- */--/* Pair A: macOS 26 Finder style — neutral grey fill + system-blue label.- The label (text + icon) shifts to accent blue, while the fill stays- neutral. This is the Liquid Glass design language: fill carries the- "selected" signal, accent color carries the "emphasized" signal. */-.platform-darwin.window-main {- --sidebar-accent: oklch(0 0 0 / 0.06);-}-.dark.platform-darwin.window-main {- --sidebar-accent: oklch(1 0 0 / 0.1);-}--/* Pair B: neutral fill only — keeps default foreground (near-black /- near-white). Use if the blue label feels too loud, or if you've- customized the system accent color away from blue.- Comment out Pair A above and uncomment this block to switch.-.platform-darwin.window-main {- --sidebar-accent: oklch(0 0 0 / 0.06);-}-.dark.platform-darwin.window-main {- --sidebar-accent: oklch(1 0 0 / 0.1);-}-*/-@keyframes drawer-slide-in-from-bottom {from {transform: translate3d(0, 100%, 0);diff --git a/src/shared/schemas/app-settings.ts b/src/shared/schemas/app-settings.tsindex 30153b44..4cb863be 100644--- a/src/shared/schemas/app-settings.ts+++ b/src/shared/schemas/app-settings.ts@@ -28,7 +28,7 @@ export const appSettingsSchema = z.object({launchAtStartup: z.boolean().catch(false),showMainWindowAtLogin: z.boolean().catch(false),theme: z.enum(['system', 'light', 'dark']).catch('system'),- sidebarColor: sidebarColorSchema.catch('gray'),+ sidebarColor: sidebarColorSchema.catch('cyan'),reduceMotion: z.boolean().catch(false),language: supportedLocaleSchema.catch(DEFAULT_LOCALE),byteUnitSystem: byteUnitSystemSchema.catch(DEFAULT_BYTE_UNIT_PREFERENCE),diff --git a/src/shared/schemas/sidebar-color.test.ts b/src/shared/schemas/sidebar-color.test.tsindex bcbe5c45..2a67685e 100644--- a/src/shared/schemas/sidebar-color.test.ts+++ b/src/shared/schemas/sidebar-color.test.ts@@ -2,12 +2,15 @@ import { expect, it } from 'vitest'import { appSettingsInputSchema, appSettingsSchema } from './app-settings'import { sidebarColorSchema } from './sidebar-color'-it('preserves existing gray and recovers invalid persisted colors while rejecting invalid edits', () => {- expect(appSettingsSchema.parse({}).sidebarColor).toBe('gray')+it('defaults to cyan and recovers invalid persisted colors while preserving saved choices', () => {+ expect(appSettingsSchema.parse({}).sidebarColor).toBe('cyan')expect(appSettingsSchema.parse({ sidebarColor: 'unknown' }).sidebarColor- ).toBe('gray')+ ).toBe('cyan')for (const sidebarColor of sidebarColorSchema.options) {+ expect(appSettingsSchema.parse({ sidebarColor }).sidebarColor).toBe(+ sidebarColor+ )expect(appSettingsInputSchema.pick({ sidebarColor: true })