Skip to content

feat(settings): add configurable font preferences#124

Open
MoozLee wants to merge 2 commits intoxintaofei:mainfrom
MoozLee:pr/font-settings-upstream
Open

feat(settings): add configurable font preferences#124
MoozLee wants to merge 2 commits intoxintaofei:mainfrom
MoozLee:pr/font-settings-upstream

Conversation

@MoozLee
Copy link
Copy Markdown
Contributor

@MoozLee MoozLee commented Apr 27, 2026

Summary / 摘要

中文

  • 新增可配置字体偏好,当前范围仅包含:界面字体与代码/编辑器字体。
  • 将代码字体应用到代码相关渲染面,包括 file/diff/merge 视图与内置 terminal;本 PR 不引入独立的 terminal 字体或 AI 回复字体设置。
  • 桌面端通过 system settings API 持久化字体设置;Web/Server 模式的字体列表仍是有意保留的通用 fallback,因为浏览器端无法枚举访问设备上安装的字体。
  • 为所有已支持语言补充字体设置相关的本地化文案。

English

  • Add configurable font preferences for interface text and code/editor content only.
  • Apply the shared code-font selection to code-oriented surfaces, including file/diff/merge views and the built-in terminal; this PR does not introduce separate terminal-font or AI-response-font settings.
  • Persist font settings through the system settings API on desktop/Tauri. Web/Server mode intentionally keeps a generic fallback font list because the browser cannot inspect fonts installed on the client device.
  • Add localized labels and helper text for the new font settings across all supported languages.

Follow-up for review feedback / 针对评审意见的后续修复

中文

  • 另有修复分支 fix/pr-124-font-settings-review,用于处理评审里指出的几点:
    • Web/Server 的 get/update_system_font_settings 路径补齐
    • fontdb 进程级缓存
    • AppearanceProvider 简化
    • fallback 文案明确化
    • fallback 模式下保留已持久化的字体选择,避免静默重置

English

  • A follow-up branch, fix/pr-124-font-settings-review, contains the review-driven fixes for:
    • shared Web/Server get/update_system_font_settings routes
    • process-level fontdb caching
    • AppearanceProvider simplification
    • clearer fallback limitation copy
    • preserving persisted selections in fallback mode instead of silently resetting them

Test plan / 测试计划

  • git diff --check origin/main...HEAD
  • pnpm -C /Users/lee/projects/codeg exec eslint .
  • pnpm -C /Users/lee/projects/codeg build
  • cargo check --manifest-path /Users/lee/projects/codeg/src-tauri/Cargo.toml
  • cargo check --manifest-path /Users/lee/projects/codeg/src-tauri/Cargo.toml --bin codeg-server --no-default-features

Notes / 说明

中文

  • 该 PR 当前描述已收紧到实际功能范围,不再宣称独立 terminal / AI 字体设置。
  • Web/Server 模式下显示通用字体列表是当前有意保留的限制,不是临时降级。
  • 本次 CLI 验证未进行手动桌面端 / Web UI 测试。

English

  • The description above now matches the actual feature scope and no longer claims separate terminal or AI font settings.
  • Showing a generic fallback font list in Web/Server mode is an intentional limitation, not a temporary degradation.
  • Manual desktop/Web UI verification was not performed during this CLI validation run.

@xintaofei
Copy link
Copy Markdown
Owner

🟥 PR 描述与实现不一致
PR Summary 写了 4 类字体:"interface text, code/editor content, terminal output, and AI responses",但实际:

SystemFontSettings 只有 ui_font_family + code_font_family 两个字段(models/system.rs)
终端 terminal-view.tsx 复用 codeFontFamilyStack,没有独立终端字体
AI 回复渲染部分 diff 里根本没有改动(搜不到 message/markdown/streamdown 的 fontFamily 注入)
PR 还写"Persist appearance font settings through the existing system settings API for both Tauri desktop and Web/Server paths",但 get_system_font_settings / update_system_font_settings 仅注册为 Tauri 命令,web/router.rs 只挂了 list_system_font_families,且 SystemFontSettings 本身被 #[cfg(feature = "tauri-runtime")] 门控 → Server 模式下完全没有落库通道,只能 localStorage,与 CLAUDE.md 约定的"双模式共用同一业务逻辑"冲突。

🟧 Web 模式体验静默降级
web/handlers/system_settings.rs::list_system_font_families 直接返 hardcoded fallback 列表,远端浏览器永远只能在 10 个通用字体里选,且 PR 未在 UI 文案中说明这是"远端无法枚举本机字体"——只有"Web 模式仅显示安全的通用字体选项"这种含糊提示,用户会误以为是临时降级。

🟧 性能:fontdb 没有缓存
list_system_font_families_core() 每次调用都 fontdb::Database::new() + load_system_fonts(),扫描整个系统字体目录。前端目前在 AppearanceProvider 与 AppearanceSettings 各自又调一次(且 Provider 内还有两个独立 useEffect 都触发它),macOS/Windows 上字体多时会反复扫盘,应做进程级 OnceCell 缓存。

🟧 AppearanceProvider 过度设计
为了"持久化字体设置"加了 5 个 ref + 0ms setTimeout + Promise 队列串行化 + dirty / ready 双 flag(appearance-provider.tsx 多了 ~280 行)。当前需求(用户偶尔切字体)一个简单防抖就够,目前的状态机给后续维护和回归带来不必要负担;两个 useEffect 重复调用 listSystemFontFamilies 也是冗余。

🟨 模型 cfg 标注不一致
SystemFontFamily{,List,Source} 公开无 cfg,SystemFontSettings 却被 #[cfg(feature="tauri-runtime")] 门控——结构上明显反映出"双模式没打通",未来要接入 Web 还得回头脱 cfg。

🟨 测试覆盖
Notes 里作者明确写:"Manual desktop/Web UI verification was not performed during this CLI validation run." 但本 PR 改的是全局 CSS 变量、xterm options、Monaco editor options、预水合 inline 脚本——cargo check + eslint + build 远远不够。Cherry-pick 自 feat/font-settings + 手工解冲突也增加了回归面。

建议

请作者修订后再合:

修正 PR 描述:要么删掉 terminal/AI 字体的措辞,要么把那两类真正实现出来
打通 Web 持久化:把 get_system_font_settings / update_system_font_settings 暴露到 web/router.rs,并脱掉 SystemFontSettings 的 cfg;或在 PR 中明确"Web 模式仅 localStorage"作为已知限制
fontdb 加进程级缓存(OnceLock)
精简 AppearanceProvider:去掉 0ms timer + Promise 队列 + 双 flag,合并两个加载 effect
手动测试桌面 + Web 两端的:默认值、切换即时生效、刷新保留、终端 refit、Monaco 字体生效、Web 模式提示文案
如果时间紧张,至少 (1) + (2)/(5) 是合入前必须的;(3)(4) 可作为 follow-up。

Share font settings persistence across desktop and web paths, cache font enumeration, and simplify appearance state so fallback mode keeps stored choices instead of silently resetting them.
@MoozLee
Copy link
Copy Markdown
Contributor Author

MoozLee commented May 1, 2026

已根据这轮 review feedback 补上一轮修复,PR head 现在已经包含最新提交:525bb62 (fix(settings): align font preferences across runtimes)。

这次主要处理了下面几项:

  1. 收紧功能范围到实际实现

    • 当前只保留 UI 字体代码字体 两项设置。
    • terminal 继续复用 code font。
    • 没有再宣称独立的 terminal 字体 / AI 回复字体设置。
  2. 补齐 Web / Server 的字体设置读写路径

    • 打通了 get_system_font_settings / update_system_font_settings 的 Web 路径。
    • SystemFontSettings 也改成双 runtime 共用,不再只在 Tauri runtime 下可用。
  3. fontdb 枚举加进程级缓存

    • list_system_font_families_core() 现在使用 OnceLock<SystemFontFamilyList>,避免重复扫系统字体目录。
  4. 简化 AppearanceProvider

    • 去掉之前那套较重的 ref / timer / queue 状态机。
    • 字体列表加载收敛到 provider 内,settings 页面不再重复调用 listSystemFontFamilies()
  5. 修正 fallback 模式行为

    • Web / Server 模式仍然保留通用 fallback 字体列表(这是有意限制,不是假降级)。
    • fallback 模式下不再静默重置已持久化的字体选择。
    • 也修掉了 settings 页面在 fallback 场景下可能自动覆盖当前选择的问题。
  6. 文案说明更明确

    • 现在会明确提示:Web / Server 模式无法枚举浏览器所在设备的已安装字体,因此只展示安全的通用字体选项。

另外我已经同步更新了 PR description,使其与当前实际实现一致。

本轮验证:

  • pnpm eslint .
  • pnpm build
  • cargo check --manifest-path src-tauri/Cargo.toml
  • cargo check --manifest-path src-tauri/Cargo.toml --bin codeg-server --no-default-features

说明:这次 CLI 修复里没有做手动桌面端 / Web UI smoke test;如果需要,我可以再补一轮针对字体切换、刷新保留、terminal refit 的手动验证说明。

@MoozLee MoozLee closed this May 2, 2026
@MoozLee MoozLee deleted the pr/font-settings-upstream branch May 2, 2026 06:21
@MoozLee MoozLee restored the pr/font-settings-upstream branch May 2, 2026 06:27
@MoozLee MoozLee reopened this May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants