Skip to content

feat(vocab): 增加词汇表场景预设#233

Merged
H-Chris233 merged 7 commits into
Open-Less:mainfrom
H-Chris233:main
May 4, 2026
Merged

feat(vocab): 增加词汇表场景预设#233
H-Chris233 merged 7 commits into
Open-Less:mainfrom
H-Chris233:main

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

@H-Chris233 H-Chris233 commented May 4, 2026

User description

摘要

Fixes #224

本 PR 为词汇表增加场景预设能力,方便用户按使用场景批量启用常用词,而不是逐条手动输入。

当前实现支持内置场景预设、多选批量启用、编辑预设、新建自定义预设,并将用户预设保存到 app data 目录的 JSON 文件中。内置预设也改为仓库内 JSON 文件,保证内置预设和用户预设使用同一套 VocabPreset 数据结构,为后续导入 / 导出功能保留兼容的 JSON 形状。

修复 / 新增 / 改进

  • 新增词汇表场景预设:

    • 程序员
    • 厨师
    • 公务员
  • 新增内置预设文件:

    • openless-all/app/src/lib/vocab-presets.json
  • 新增统一预设类型:

    • Rust: VocabPreset
    • TypeScript: VocabPreset
  • 新增预设读写 Tauri command:

    • list_vocab_presets
    • save_vocab_presets
  • 用户自定义预设保存到 app data 目录:

    • vocab-presets.json
  • 词汇表页面新增场景预设区域:

    • 支持多选预设
    • 支持批量启用所选预设
    • 支持编辑预设名称和词条
    • 支持新建自定义预设
    • 支持保存用户自定义预设
  • 批量启用预设时会复用现有词汇表入口:

    • 通过 addVocab() 添加词条
    • 已存在词条会跳过,避免重复添加
    • 添加后刷新词汇表
  • 编辑预设时支持用逗号或换行分隔词条。

  • 保存预设时会对词条做基础清洗:

    • trim 空白
    • 过滤空项
    • 去重
  • 补充中英文 i18n 文案:

    • 场景预设
    • 新建预设
    • 启用所选
    • 保存预设
    • 编辑预设
    • 预设名称
    • 词条输入提示

兼容

  • 不包含:

    • 不改变现有词汇表条目的后端存储结构。
    • 不改变词汇表原有新增、删除、启用、禁用行为。
    • 不改变 polish / 热词注入逻辑。
    • 不实现完整导入 / 导出功能。
    • 不使用 localStorage 保存预设。
    • 不把预设硬编码在 TS 常量里作为唯一来源。
    • 不引入新依赖。
  • 对现有用户 / 本地环境 / 构建流程的影响:

    • 现有词汇表数据继续沿用原来的 dictionary.json
    • 新增的预设数据单独保存到 vocab-presets.json
    • 用户未保存自定义预设时,会使用仓库内置默认预设。
    • 用户保存自定义预设后,会优先使用用户本地预设。
    • 词汇表原有交互保持不变,预设只是新增的批量启用入口。
    • 为后续导入 / 导出保留统一 JSON schema。

测试计划

  • 命令:cargo check --manifest-path openless-all/app/src-tauri/Cargo.toml

  • 结果:通过

  • 证据路径:本地 src-tauri 检查输出

  • 命令:npm run build

  • 结果:未完成

  • 说明:当前 npm build 受既有 Settings.tsx typing 问题阻塞,和本次词汇表预设改动无关。

主要改动文件

  • openless-all/app/src-tauri/src/commands.rs
  • openless-all/app/src-tauri/src/lib.rs
  • openless-all/app/src-tauri/src/persistence.rs
  • openless-all/app/src-tauri/src/types.rs
  • openless-all/app/src/i18n/en.ts
  • openless-all/app/src/i18n/zh-CN.ts
  • openless-all/app/src/lib/ipc.ts
  • openless-all/app/src/lib/types.ts
  • openless-all/app/src/lib/vocab-presets.json
  • openless-all/app/src/lib/vocabPresets.ts
  • openless-all/app/src/pages/Vocab.tsx

备注

本 PR 只实现词汇表预设的新增、编辑、保存和批量启用。导入 / 导出没有在本次实现中落地,但预设已经统一为 JSON 结构,后续可以直接基于当前 schema 扩展。


PR Type

Enhancement, Bug fix, Tests


Description

  • Add vocabulary scenario presets with multi‑select apply, create, and edit

  • Store built‑in presets in repo JSON and user presets via Tauri commands

  • Fix web build failure by lazy‑loading the autostart plugin in Settings

  • Add regression test for preset JSON persistence roundtrip


Diagram Walkthrough

flowchart LR
  A["User selects presets"] --> B["Frontend loads preset list"]
  B --> C["Backend reads built‑in/user JSON files"]
  C --> D["Apply phrases to vocab entries"]
  E["Create/edit preset"] --> F["Persist via Tauri command"]
Loading

File Walkthrough

Relevant files
Enhancement
10 files
commands.rs
Add list_vocab_presets and save_vocab_presets Tauri commands
+11/-1   
lib.rs
Register new vocab preset commands in the invoke handler 
+2/-0     
persistence.rs
Implement vocab preset persistence with atomic write and roundtrip
test
+50/-1   
types.rs
Define VocabPreset and VocabPresetStore Rust types             
+16/-0   
en.ts
Add English i18n strings for scenario presets                       
+11/-0   
zh-CN.ts
Add Chinese i18n strings for scenario presets                       
+11/-0   
ipc.ts
Add listVocabPresets and saveVocabPresets IPC wrappers     
+14/-0   
types.ts
Add TypeScript interfaces for VocabPreset and VocabPresetStore
+12/-0   
vocabPresets.ts
Add vocab preset loading, merging, and persistence logic 
+46/-0   
Vocab.tsx
Add scenario preset UI with multi-select, create, and edit
+137/-1 
Bug fix
2 files
Settings.tsx
Fix web build by lazy‑loading autostart plugin imports     
+26/-6   
tauri-plugin-autostart.d.ts
Add type declaration for the autostart plugin                       
+5/-0     
Configuration changes
1 files
vocab-presets.json
Add built‑in vocab preset definitions in JSON                       
+17/-0   

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

PR Reviewer Guide 🔍

(Review updated until commit 647fc2d)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

224 - Fully compliant

Compliant requirements:

  • 增加场景预设
  • 支持多选批量启用
  • 支持编辑预设
  • 支持新建并保存自定义预设
  • 使用统一的 JSON 数据结构并拆分内置/用户预设存储
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit 2f7cd05

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit 044b2de

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit b9a0b13

H-Chris233 added 5 commits May 4, 2026 16:09
Issue Open-Less#224 requires scenario presets with multi-select apply and editable custom
presets, while preparing for import/export. This revision moves built-in presets
into a repository JSON file and stores user presets in the app data directory as
JSON via Tauri commands, so preset persistence uses one JSON shape both in repo
and user space.

Constraint: Keep vocabulary entry backend and UI interaction model unchanged
Rejected: Keep presets in localStorage/TS constants | does not satisfy unified JSON storage requirement
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Preserve vocab-presets JSON schema compatibility for future import/export
Tested: cargo check (src-tauri) passed
Not-tested: npm build currently fails on pre-existing Settings.tsx typing issues unrelated to this change
The frontend build failed because the autostart plugin import could not be
resolved in the browser-targeted Vite bundle, and strict TS also flagged
implicit any in the same flow. Switch the autostart integration to runtime
lazy-loading behind the Tauri guard and type the callback parameters explicitly.

Constraint: Keep autostart UX behavior unchanged on Tauri runtime
Rejected: Add Vite external alias for plugin package | hides integration mismatch in app code
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Tauri-only plugin modules should stay runtime-gated to keep web build healthy
Tested: npm run build (openless-all/app) passed
Not-tested: End-to-end autostart toggle interaction on all desktop platforms
New preset previously persisted an empty entry immediately on click, so cancel
or navigation left permanent junk rows without any delete path. Keep new preset
as in-memory draft and persist only after explicit save.

Also add a regression test for vocab preset JSON persistence roundtrip to cover
the new preset storage workflow with automated verification.

Constraint: Minimal UI change without introducing preset delete UX in this patch
Rejected: Auto-delete blank presets on load | implicit cleanup can remove user-intended drafts
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep create flow non-persistent until user confirms save
Tested: cargo test vocab_presets_roundtrip_json_file -- --nocapture; npm run build
Not-tested: Manual UX walkthrough for preset draft cancel across app restart
Loading presets from app-data JSON previously replaced bundled defaults entirely,
so adding any custom preset made shipped scenarios disappear on the next load.
Merge user presets onto bundled defaults by id so built-ins always remain
available while still allowing user overrides.

Constraint: Minimal change in preset loading path without altering storage schema
Rejected: Persist defaults into user file on first run | unnecessary write churn and migration complexity
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Preserve default+user merge behavior when adding future preset sources
Tested: npm run build
Not-tested: Manual Tauri UI check for merged list ordering
Saving presets previously wrote the merged list (including built-ins) into user
storage, which froze old builtin copies and shadowed future app updates with the
same preset ids. Switch preset persistence to a delta store: custom presets,
overrides for edited built-ins, and disabled builtin ids.

Constraint: Keep current preset UI and command names unchanged
Rejected: Force builtin presets to always overwrite user file | would discard intentional user edits
Confidence: high
Scope-risk: moderate
Reversibility: clean
Directive: Never persist untouched builtin presets into user store
Tested: cargo test vocab_presets_roundtrip_json_file -q; npm run build
Not-tested: Manual end-to-end UX for builtin delete/restore (no delete UI yet)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit aad7953

Preset edits were applied to local UI state before persistence finished, so
storage failures could show a misleading saved state and then lose changes on
reload. Also, batch apply aborted on first add_vocab error and skipped later
selected presets.

Make preset save await persistence before mutating UI/closing editor, and make
batch apply continue across per-term failures while reporting aggregated errors.

Constraint: Minimal behavior fix within existing Vocab page flow
Rejected: Add transactional backend endpoint for batch apply | larger cross-layer change
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep UI success states aligned with durable persistence completion
Tested: npm run build
Not-tested: Manual readonly-disk simulation for persist failure
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit f2122dc

Address review feedback by removing fragile runtime import of the autostart
plugin package and invoking plugin commands via Tauri core bridge, so production
bundles no longer depend on unresolved bare imports.

Also update preset batch apply to re-enable existing disabled terms and continue
processing remaining terms/presets when one add operation fails.

Constraint: Minimal changes limited to existing Settings/Vocab flows
Rejected: New backend batch endpoint for preset apply | broader cross-layer change
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Preset apply should be idempotent and restore disabled matching terms
Tested: npm run build
Not-tested: Manual autostart toggle check on packaged desktop build
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit 47069ce

@H-Chris233 H-Chris233 merged commit d81bbc4 into Open-Less:main May 4, 2026
2 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Persistent review updated to latest commit 647fc2d

appergb pushed a commit that referenced this pull request May 4, 2026
包含自 1.2.13 以来的修复与新功能:
- feat(autostart): 跨端开机自启 (#194)
- feat(asr): SiliconFlow / GLM-ASR / Groq / OpenAI Whisper preset (#212)
- fix(qa): Windows / Linux 划词追问浮窗 Esc + 拖拽 + 文案 (#205 / #206)
- fix(settings): preset 切换 race + per-provider 凭据隔离 (#219 / #220)
- fix(overview): 概览整屏适配 + 嵌套 scroller 细滚动条 (#243 / #248)
- 一系列 Windows IME (TSF) 模块 (#233 / #240 等)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Vocabulary)增加词汇表预设

1 participant