DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(navbar): 最大化按钮图标随窗口状态切换,补齐 nav.restore (#673)
walker184ed22a9bd7
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex bff1c5bb..256714ce 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -164,6 +164,7 @@"nav.forward": "Forward","nav.minimize": "Minimize","nav.maximize": "Maximize",+ "nav.restore": "Restore","nav.background": "Background","messages.logs_copied": "Logs copied to clipboard","messages.logs_read_failed": "Failed to read logs. Please try again.",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 2a46b295..78105296 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -164,6 +164,7 @@"nav.forward": "前进","nav.minimize": "最小化","nav.maximize": "最大化",+ "nav.restore": "还原","nav.background": "后台化","messages.logs_copied": "日志已复制到剪贴板","messages.logs_read_failed": "读取日志失败,请稍后重试",diff --git a/src/layout/components/navbar.tsx b/src/layout/components/navbar.tsxindex 80900cf3..7ac64662 100644--- a/src/layout/components/navbar.tsx+++ b/src/layout/components/navbar.tsx@@ -1,6 +1,7 @@import type { DshPlugin } from '@/types'import type { ConfigTab } from '@/ui/dialog/config'import {+ Copy,LayoutSideContent,LayoutSideContentLeft,Minus,@@ -56,7 +57,8 @@ import { toast } from '@/utils/toast'* 由 Rust 测试 `shell_nav_height_matches_navbar_height_class` 守住——改这个* class 就必须同步那个常量,否则 CI 失败(issue #524)。* - Windows/Linux:右侧窗口按钮直接调用 Tauri API;- * 后台化 = 隐藏到托盘(服务保持运行)。+ * 最大化的字形随窗口状态在「最大化 / 还原」间切换(`useMaximized` 订阅 `onResized`,+ * 因此按钮、拖拽区双击、Win+↑ 等任何原生路径都同步),后台化 = 隐藏到托盘(服务保持运行)。** 未传入 onToggleSidebar(安装/错误/预装引导页,无 iframe 可操控)时* 只渲染窗口控制与不依赖 iframe 的菜单项。@@ -142,6 +144,53 @@ function useMacOSFullscreen() {return isFullscreen}+/** 最大化状态:Windows/Linux 自绘的最大化按钮据此在「最大化 / 还原」字形间切换(issue #673)。 */+function useMaximized() {+ const [isMaximized, setIsMaximized] = useState(false)++ // keep:effect 显式注册/注销原生窗口 onResized 订阅(@reause/core 不覆盖窗口事件)+ useEffect(() => {+ const appWindow = getCurrentWindow()+ let mounted = true+ let unlisten: (() => void) | undefined++ async function syncMaximized() {+ try {+ const maximized = await appWindow.isMaximized()+ if (mounted)+ setIsMaximized(maximized)+ }+ catch (error) {+ console.error('[Navbar] failed to sync maximized state:', error)+ }+ }++ async function setupListener() {+ try {+ await syncMaximized()+ const stopListening = await appWindow.onResized(() => {+ void syncMaximized()+ })+ if (mounted)+ unlisten = stopListening+ else+ stopListening()+ }+ catch (error) {+ console.error('[Navbar] failed to listen for maximized state:', error)+ }+ }++ void setupListener()+ return () => {+ mounted = false+ unlisten?.()+ }+ }, [])++ return isMaximized+}+export interface NavbarProps {/** iframe 回报的 dsh 侧边栏折叠状态(导航桥逻辑在 `iframe.tsx`) */sidebarCollapsed?: boolean@@ -156,6 +205,7 @@ export interface NavbarProps {export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, onOpenFolder }: NavbarProps) {const { t } = useTranslation()const isFullscreen = useMacOSFullscreen()+ const isMaximized = useMaximized()// 只读取「dsh-tauri 插件是否已安装」;查询键与「插件」面板共用(同一份缓存),// 挂载时自动拉取,服务重启 / 插件操作后的失效由 store 与该缓存同步共同保证。const { data: plugins = [] } = useQuery({@@ -571,10 +621,14 @@ export function Navbar({ sidebarCollapsed = false, onToggleSidebar, onNewChat, oisIconOnlysize="sm"variant="ghost"- aria-label={t('nav.maximize')}+ aria-label={t(isMaximized ? 'nav.restore' : 'nav.maximize')}onPress={() => { handleWindowAction('maximize') }}>- <Square style={{ width: 14, height: 14 }} />+ <If+ cond={isMaximized}+ then={<Copy style={{ width: 14, height: 14 }} />}+ else={<Square style={{ width: 14, height: 14 }} />}+ /></Button><Buttondiff --git a/test/navbar-maximize-icon.test.ts b/test/navbar-maximize-icon.test.tsnew file mode 100644index 00000000..e5d8ad95--- /dev/null+++ b/test/navbar-maximize-icon.test.ts@@ -0,0 +1,56 @@+/**+ * navbar-maximize-icon.test.ts — 标题栏最大化按钮的字形契约(issue #673)。+ *+ * 该按钮是自绘的:最大化后必须换成「还原」字形并同步 aria-label,未最大化时保持+ * 单方块。与 `menu-restart.test.ts` 同一姿势——壳层组件的契约以源码关系断言锁定,+ * 因为 `unit` project 是 node 环境(无 DOM/渲染器),拿不到真实渲染结果。+ */+import { readFileSync } from 'node:fs'+import { describe, expect, it } from 'vitest'++const navbarSource = readFileSync(+ new URL('../src/layout/components/navbar.tsx', import.meta.url),+ 'utf8',+)++function readLocale(name: string): Record<string, string> {+ return JSON.parse(+ readFileSync(new URL(`../src/i18n/locales/${name}.json`, import.meta.url), 'utf8'),+ ) as Record<string, string>+}++const zhCN = readLocale('zh-CN')+const enUS = readLocale('en-US')++describe('maximize button follows the window state', () => {+ it('reads isMaximized() and subscribes to onResized for the maximize state', () => {+ // 断言「订阅来源」而非孤立 token:初读 + resize 重读缺一不可,+ // 只留其中一个都会让拖拽区双击 / Win+↑ 等原生路径漏同步。+ expect(navbarSource).toMatch(/const isMaximized = useMaximized\(\)/)+ expect(navbarSource).toMatch(/await appWindow\.isMaximized\(\)/)+ expect(navbarSource).toMatch(/await appWindow\.onResized\(/)+ })++ it('swaps the glyph between Copy (restore) and Square (maximize)', () => {+ // 断言 then/else 与 cond 的绑定关系:把 Copy/Square 写反、或丢掉 cond 都判红。+ expect(navbarSource).toMatch(+ /cond=\{isMaximized\}[\s\S]*?then=\{<Copy[\s\S]*?else=\{<Square/,+ )+ })++ it('switches the aria-label together with the glyph', () => {+ expect(navbarSource).toMatch(+ /aria-label=\{t\(isMaximized \? 'nav\.restore' : 'nav\.maximize'\)\}/,+ )+ })+})++describe('nav.restore locale keys', () => {+ it('provides the restore label in both locales, next to nav.maximize', () => {+ // 断言键→值的关系:token 出现在无关位置(如注释)不算通过。+ expect(zhCN['nav.restore']).toBe('还原')+ expect(enUS['nav.restore']).toBe('Restore')+ expect(zhCN['nav.maximize']).toBe('最大化')+ expect(enUS['nav.maximize']).toBe('Maximize')+ })+})