Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(ui): 打开设置前记录会话宽度(撤销 #1096/#1100) (#1106)

Hairy39bc45afa94c
diff --git a/packages/dsh-tauri-ui/src/client/register/settings.shortcut.test.tsx b/packages/dsh-tauri-ui/src/client/register/settings.shortcut.test.tsx
index 916a406b..a3b25004 100644
--- a/packages/dsh-tauri-ui/src/client/register/settings.shortcut.test.tsx
+++ b/packages/dsh-tauri-ui/src/client/register/settings.shortcut.test.tsx
@@ -336,4 +336,18 @@ describe('patched settings shortcut store route', () => {
expect(screen.queryByRole('dialog')).toBeNull()
expect(modal.useModalLayer).not.toHaveBeenCalled()
})
+
+ it('mirrors the conversation content width recorded before opening', () => {
+ const dock = document.createElement('div')
+ dock.dataset.slot = 'conversation.input.dock'
+ dock.style.setProperty('--dsh-chat-content-width', '912px')
+ document.body.append(dock)
+ disposers.push(() => dock.remove())
+ const host = activate()
+ render(<host.Overlays />)
+
+ act(() => store.settings.openAt('general'))
+
+ expect(screen.getByRole('dialog').style.getPropertyValue('--dsh-chat-content-width')).toBe('912px')
+ })
})
diff --git a/packages/dsh-tauri-ui/src/client/store/modules/settings.test.ts b/packages/dsh-tauri-ui/src/client/store/modules/settings.test.ts
new file mode 100644
index 00000000..84c04e91
--- /dev/null
+++ b/packages/dsh-tauri-ui/src/client/store/modules/settings.test.ts
@@ -0,0 +1,44 @@
+// @vitest-environment jsdom
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { settings } from './settings'
+
+vi.mock('dsh-tauri/client', async () => await import('../../../../../dsh-tauri/src/client/modules/valtio-define'))
+
+function mountDock(width?: string): void {
+ document.body.innerHTML = '<div data-slot="conversation.input.dock"></div>'
+ const dock = document.querySelector('[data-slot="conversation.input.dock"]')
+ if (width !== undefined && dock instanceof HTMLElement)
+ dock.style.setProperty('--dsh-chat-content-width', width)
+}
+
+describe('settings 记录会话内容宽度', () => {
+ beforeEach(() => {
+ settings.close()
+ document.body.innerHTML = ''
+ })
+
+ it('打开设置前记录会话 dock 上的 --dsh-chat-content-width', () => {
+ mountDock('912px')
+
+ settings.openAt('general')
+
+ expect(settings.open).toBe(true)
+ expect(settings.chatContentWidth).toBe('912px')
+ })
+
+ it('会话 dock 不在时留空,由设置页回退默认宽度', () => {
+ settings.openAt()
+
+ expect(settings.chatContentWidth).toBeUndefined()
+ })
+
+ it('已打开时再次 openAt 沿用先记录的宽度,不读取塌缩后的值', () => {
+ mountDock('860px')
+ settings.openAt()
+ mountDock('640px')
+
+ settings.openAt('models')
+
+ expect(settings.chatContentWidth).toBe('860px')
+ })
+})
diff --git a/packages/dsh-tauri-ui/src/client/store/modules/settings.ts b/packages/dsh-tauri-ui/src/client/store/modules/settings.ts
index eacb33b2..8530d741 100644
--- a/packages/dsh-tauri-ui/src/client/store/modules/settings.ts
+++ b/packages/dsh-tauri-ui/src/client/store/modules/settings.ts
@@ -1,17 +1,28 @@
import type { SettingsUiState } from './settings.types'
import { defineStore } from 'dsh-tauri/client'
+function readChatContentWidth(): string | undefined {
+ const dock = document.querySelector('[data-slot="conversation.input.dock"]')
+ const width = dock === null
+ ? ''
+ : getComputedStyle(dock).getPropertyValue('--dsh-chat-content-width').trim()
+ return width === '' ? undefined : width
+}
+
export const settings = defineStore({
state: (): SettingsUiState => ({
open: false,
activeId: undefined,
query: '',
railWidth: undefined,
+ chatContentWidth: undefined,
launcherAvailable: false,
launcherShortcut: undefined,
}),
actions: {
openAt(sectionId?: string) {
+ if (!this.open)
+ this.chatContentWidth = readChatContentWidth()
this.open = true
if (sectionId !== undefined)
this.activeId = sectionId
diff --git a/packages/dsh-tauri-ui/src/client/store/modules/settings.types.ts b/packages/dsh-tauri-ui/src/client/store/modules/settings.types.ts
index e78eb57e..02c411fd 100644
--- a/packages/dsh-tauri-ui/src/client/store/modules/settings.types.ts
+++ b/packages/dsh-tauri-ui/src/client/store/modules/settings.types.ts
@@ -3,6 +3,11 @@ export interface SettingsUiState {
activeId: string | undefined
query: string
railWidth: number | undefined
+ /**
+ * 打开设置前记录的会话内容宽度(`--dsh-chat-content-width` 的当值,可能是 `clamp(...)` 表达式)。
+ * 设置页打开后会话区被盖住会塌缩到 640px,此值只能在打开前取。
+ */
+ chatContentWidth: string | undefined
/**
* 官方 `settings.launcher` 座位是否已声明(官方条目在注册时声明,早于本插件时装好)。
* 未声明(更老核心)时触发器渲染自有按钮——`SlotOutlet` 对未声明的槽位返回空,绝不能让
diff --git a/packages/dsh-tauri-ui/src/client/styles/index.ts b/packages/dsh-tauri-ui/src/client/styles/index.ts
index 2fc3ca56..c91b5f21 100644
--- a/packages/dsh-tauri-ui/src/client/styles/index.ts
+++ b/packages/dsh-tauri-ui/src/client/styles/index.ts
@@ -510,6 +510,9 @@ const TAILWINDCSS_GENERATED = `
.w-\\[min\\(760px\\,100\\%\\)\\]\\! {
width: min(760px, 100%) !important;
}
+ .w-\\[min\\(calc\\(var\\(--dsh-composer-card-max-width\\)_\\+_2_\\*_var\\(--dsh-composer-side-clearance\\)\\)\\,100\\%\\)\\] {
+ width: min(calc(var(--dsh-composer-card-max-width) + 2 * var(--dsh-composer-side-clearance)), 100%);
+ }
.w-\\[var\\(--dsh-settings-rail-width\\)\\] {
width: var(--dsh-settings-rail-width);
}
@@ -1563,6 +1566,15 @@ const TAILWINDCSS_GENERATED = `
.\\[--detail-gutter\\:24px\\] {
--detail-gutter: 24px;
}
+ .\\[--dsh-chat-content-width\\:748px\\] {
+ --dsh-chat-content-width: 748px;
+ }
+ .\\[--dsh-composer-card-max-width\\:calc\\(var\\(--dsh-chat-content-width\\)_\\+_32px\\)\\] {
+ --dsh-composer-card-max-width: calc(var(--dsh-chat-content-width) + 32px);
+ }
+ .\\[--dsh-composer-side-clearance\\:16px\\] {
+ --dsh-composer-side-clearance: 16px;
+ }
.\\[--dsh-scrollbar-thumb-border\\:2px\\] {
--dsh-scrollbar-thumb-border: 2px;
}
diff --git a/packages/dsh-tauri-ui/src/client/ui/settings-sidebar.test.tsx b/packages/dsh-tauri-ui/src/client/ui/settings-sidebar.test.tsx
deleted file mode 100644
index 99d584ff..00000000
--- a/packages/dsh-tauri-ui/src/client/ui/settings-sidebar.test.tsx
+++ /dev/null
@@ -1,113 +0,0 @@
-// @vitest-environment jsdom
-import { act, cleanup, render } from '@testing-library/react'
-import { afterEach, beforeEach, expect, it, vi } from 'vitest'
-import { store } from '../store'
-import { SettingsSidebar } from './settings-sidebar'
-
-const observer = vi.hoisted(() => ({ resize: () => {} }))
-vi.mock('dsh-tauri/client', async () => ({
- ...await import('../../../../dsh-tauri/src/client/modules/reause'),
- ...await import('../../../../dsh-tauri/src/client/modules/valtio-define'),
- clamp: (value: number, min: number, max: number) => Math.min(Math.max(value, min), max),
- isEmpty: (values: unknown[]) => values.length === 0,
- cn: (...values: unknown[]) => values.filter(Boolean).join(' '),
- useEventListener: () => {},
- useResizeObserver: (_ref: unknown, callback: () => void) => { observer.resize = callback },
-}))
-vi.mock('../locales', () => ({ locale: { text: (key: string) => key, useLocale: () => 'en' } }))
-vi.mock('../components/official', () => ({ Input: 'input' }))
-vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({ useModalLayer: undefined }))
-vi.mock('@deepseek-ai/dsh-client-ui-renderer', () => ({ SlotOutlet: () => <section>Settings</section> }))
-
-beforeEach(() => {
- store.settings.close()
- store.settings.openAt('general')
- store.sections.setRows([{ id: 'general', label: 'General', order: 0 }])
-})
-
-afterEach(() => {
- cleanup()
- store.settings.close()
- store.sections.setRows([])
- vi.restoreAllMocks()
- document.body.replaceChildren()
-})
-
-it.each([
- [64, undefined],
- [264, 264],
- [320, 320],
- [500, 420],
-])('syncs sidebar width %s on initial open and focuses search', (width, expected) => {
- const sidebar = document.createElement('div')
- sidebar.dataset.slot = 'sidebar'
- document.body.append(sidebar)
- const measure = vi.spyOn(sidebar, 'getBoundingClientRect').mockReturnValue({ width } as DOMRect)
- const focus = vi.spyOn(HTMLInputElement.prototype, 'focus')
- const view = render(<SettingsSidebar useSessions={selector => selector({} as never)} />)
-
- expect(store.settings.railWidth).toBe(expected)
- expect(measure).toHaveBeenCalledTimes(1)
- expect(focus).toHaveBeenCalledTimes(1)
- expect(document.activeElement).toBe(view.getByRole('textbox', { name: 'search' }))
-})
-
-it('syncs width and focuses only when opening, including reopening after close', () => {
- store.settings.close()
- const sidebar = document.createElement('div')
- sidebar.dataset.slot = 'sidebar'
- document.body.append(sidebar)
- const measure = vi.spyOn(sidebar, 'getBoundingClientRect').mockReturnValue({ width: 300 } as DOMRect)
- const focus = vi.spyOn(HTMLInputElement.prototype, 'focus')
- const view = render(<SettingsSidebar useSessions={selector => selector({} as never)} />)
- expect(view.queryByRole('dialog')).toBeNull()
- expect(measure).not.toHaveBeenCalled()
- expect(focus).not.toHaveBeenCalled()
- expect(store.settings.railWidth).toBeUndefined()
-
- act(() => store.settings.openAt('general'))
- expect(store.settings.railWidth).toBe(300)
- expect(document.activeElement).toBe(view.getByRole('textbox', { name: 'search' }))
- const other = document.createElement('button')
- document.body.append(other)
- other.focus()
- act(() => store.settings.setQuery('gen'))
- view.rerender(<SettingsSidebar useSessions={selector => selector({} as never)} />)
- expect(measure).toHaveBeenCalledTimes(1)
- expect(focus).toHaveBeenCalledTimes(1)
- expect(store.settings.railWidth).toBe(300)
- expect(document.activeElement).toBe(other)
-
- act(() => store.settings.close())
- expect(view.queryByRole('dialog')).toBeNull()
- expect(measure).toHaveBeenCalledTimes(1)
- expect(focus).toHaveBeenCalledTimes(1)
- expect(store.settings.railWidth).toBeUndefined()
- measure.mockReturnValue({ width: 380 } as DOMRect)
- act(() => store.settings.openAt('general'))
- expect(measure).toHaveBeenCalledTimes(2)
- expect(focus).toHaveBeenCalledTimes(2)
- expect(store.settings.railWidth).toBe(380)
- expect(document.activeElement).toBe(view.getByRole('textbox', { name: 'search' }))
-})
-
-it('uses the conversation content width on open and resize, excluding settings padding', () => {
- const dock = document.createElement('div')
- dock.dataset.slot = 'conversation.input.dock'
- dock.style.setProperty('--dsh-chat-content-width', '860px')
- document.body.append(dock)
- const view = render(<SettingsSidebar useSessions={selector => selector({} as never)} />)
- const content = view.container.querySelector<HTMLElement>('[data-slot="settings.content"]')!
- observer.resize()
- expect(content.style.getPropertyValue('--dsh-chat-content-width')).toBe('860px')
- const column = content.firstElementChild as HTMLElement
- expect(column.style.maxWidth).toBe('calc(var(--dsh-chat-content-width, 748px) + 72px)')
- expect(column.classList.contains('w-full')).toBe(true)
- expect(column.classList.contains('px-[36px]')).toBe(true)
- dock.style.setProperty('--dsh-chat-content-width', '700px')
- observer.resize()
- expect(content.style.getPropertyValue('--dsh-chat-content-width')).toBe('700px')
- dock.remove()
- observer.resize()
- expect(content.style.getPropertyValue('--dsh-chat-content-width')).toBe('')
-})
diff --git a/packages/dsh-tauri-ui/src/client/ui/settings-sidebar.tsx b/packages/dsh-tauri-ui/src/client/ui/settings-sidebar.tsx
index beba1939..f6a28204 100644
--- a/packages/dsh-tauri-ui/src/client/ui/settings-sidebar.tsx
+++ b/packages/dsh-tauri-ui/src/client/ui/settings-sidebar.tsx
@@ -4,8 +4,8 @@ import type { IconComponent } from '../components/icon'
import type { SelectorHook } from '../types/selector'
import { useModalLayer } from '@deepseek-ai/dsh-client-ui-primitives'
import { SlotOutlet } from '@deepseek-ai/dsh-client-ui-renderer'
-import { clamp, cn, isEmpty, useEventListener, useResizeObserver, useStore, useWatch } from 'dsh-tauri/client'
-import { useRef, useState } from 'react'
+import { clamp, cn, isEmpty, useEventListener, useStore } from 'dsh-tauri/client'
+import { useEffect, useRef, useState } from 'react'
import { Icon } from '../components/icon'
import { ArrowLeft, Cubes3Overlap, Database, Gear, Ghost, Globe, LayoutSplitSideContentRight, PersonPencil, Puzzle, Smartphone, Tray } from '../components/icons'
import { Input } from '../components/official'
@@ -43,12 +43,6 @@ export function SettingsSidebar(_props: SettingsSidebarProps): ReactElement | nu
locale.useLocale()
const searchRef = useRef<HTMLInputElement>(null)
const dialogRef = useRef<HTMLDivElement>(null)
- const contentRef = useRef<HTMLDivElement>(null)
- useResizeObserver(contentRef, () => {
- const conversation = document.querySelector('[data-slot="conversation.input.dock"]')
- const width = conversation ? getComputedStyle(conversation).getPropertyValue('--dsh-chat-content-width') : ''
- contentRef.current?.style.setProperty('--dsh-chat-content-width', width)
- })
// 官方 `Input` 的 props 类型没声明 ref(实现里 `...rest` 会落到 <input>),官方类型补全后可直接写 ref。
const searchInputRefProps = { ref: searchRef }
const [dragging, setDragging] = useState(false)
@@ -89,15 +83,15 @@ export function SettingsSidebar(_props: SettingsSidebarProps): ReactElement | nu
store.settings.close()
})
- useWatch(ui.open, (open) => {
- if (!open)
+ useEffect(() => {
+ if (!ui.open)
return
const el = document.querySelector('[data-slot="sidebar"]')
const width = el?.getBoundingClientRect().width
if (typeof width === 'number' && width >= RAIL_WIDTH_MIN)
store.settings.setRailWidth(clamp(width, RAIL_WIDTH_MIN, RAIL_WIDTH_MAX))
searchRef.current?.focus()
- }, { immediate: true })
+ }, [ui.open])
if (!ui.open)
return null
@@ -118,7 +112,8 @@ export function SettingsSidebar(_props: SettingsSidebarProps): ReactElement | nu
<>
<div
ref={dialogRef}
- className="fixed inset-0 z-[1000] flex bg-[var(--dsw-specific-sidebar-fill)] text-primary"
+ style={ui.chatContentWidth === undefined ? undefined : { '--dsh-chat-content-width': ui.chatContentWidth } as CSSProperties}
+ className="fixed inset-0 z-[1000] flex bg-[var(--dsw-specific-sidebar-fill)] text-primary [--dsh-chat-content-width:748px] [--dsh-composer-card-max-width:calc(var(--dsh-chat-content-width)_+_32px)] [--dsh-composer-side-clearance:16px]"
data-slot-sidebar="dsh-tauri-ui"
data-shortcut-modal="settings"
role="dialog"
@@ -174,11 +169,10 @@ export function SettingsSidebar(_props: SettingsSidebarProps): ReactElement | nu
onPointerDown={onHandlePointerDown}
/>
<div
- ref={contentRef}
data-slot="settings.content"
className="flex-1 min-w-0 h-full box-border overflow-y-auto flex bg-[var(--dsw-alias-bg-base)] rounded-tl-[16px] [corner-shape:round]"
>
- <div className="w-full mx-auto box-border px-[36px] py-[28px]" style={{ maxWidth: 'calc(var(--dsh-chat-content-width, 748px) + 72px)' }}>
+ <div className="w-[min(calc(var(--dsh-composer-card-max-width)_+_2_*_var(--dsh-composer-side-clearance)),100%)] mx-auto box-border px-[36px] py-[28px]">
{activeId !== undefined && (
<SlotOutlet
slotKey={SETTINGS_SECTION_SLOT}
diff --git a/packages/dsh-tauri/src/client/modules/reause.ts b/packages/dsh-tauri/src/client/modules/reause.ts
index 27d53ed7..28c174b7 100644
--- a/packages/dsh-tauri/src/client/modules/reause.ts
+++ b/packages/dsh-tauri/src/client/modules/reause.ts
@@ -13,5 +13,5 @@
* 具名清单只保留真正被消耗的 hook,其余被 tree-shake(941KB → 70KB)。
* 新增 hook 在此登记即可(dts 同步收窄,漏登记时插件侧直接类型报错)。
*/
-export { noop, useAsyncState, useEventListener, useMount, useResizeObserver, useTimeoutPoll, useUnmount, useWatch, useWatchImmediate } from '@reause/core'
+export { noop, useAsyncState, useEventListener, useMount, useResizeObserver, useTimeoutPoll, useUnmount, useWatchImmediate } from '@reause/core'
export { If } from 'react-if-lite'