Repository navigation
feat: Prompt 增加稳定 Id 字段(供插件持久化绑定) - #801
Open
SwiftFloatFlow wants to merge 1 commit into
Open
SwiftFloatFlow wants to merge 1 commit into
SwiftFloatFlow wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
描述
背景 / Background
当前
Prompt类型(src/STranslate.Plugin/Prompt.cs)仅以Name作为标识,存在以下问题:Name建立的持久关联(如插件绑定)会随改名而失效这导致任何需要"稳定引用某个 Prompt"的场景(如插件将 Prompt 与外部配置做持久绑定)都无法可靠实现。
解决方案 / Solution
给
Prompt增加一个稳定的唯一标识字段Id:设计要点:
new Prompt(...))Clone()CopyPrompt()关键设计决策:
Id 为可空类型(
string?):有意设计。反序列化老配置(无 id 字段)时走无参构造函数,Id 保持null,供插件检测"这是老配置"并触发迁移。这是解决"老配置 Id 每次加载都变"问题的前提——如果直接在属性初始化器生成 Id,插件将永远检测不到老配置。Clone()保留原 Id:用于运行时读取副本时保持身份一致;需要"复制为新 Prompt"时,调用方必须显式覆盖新 Id(如CopyPrompt()中的做法)。不强制迁移,不主动写盘:SDK 只提供 Id 能力,迁移是使用方(插件)的自由。不想用 Id 的插件完全无感;想用 Id 做持久绑定的插件,在
Init()中补一次并写盘即可。插件迁移参考代码:
改动范围 / Changes
仅 2 个文件:
src/STranslate.Plugin/Prompt.csId属性、无参构造不生成、带参构造生成、Clone()保留原 Idsrc/STranslate/ViewModels/PromptEditViewModel.csCopyPrompt()中显式重生成新 Id(1 行)未改动:
Settings.cs、PluginContext、StorageBase等)PromptItem兼容性 / Compatibility
null,插件可检测;用户下次自然保存时写盘,或插件主动补一次并写盘SaveSettingStorage:避免"加载即写盘"意外覆盖用户文件验证 / Verification
已通过 Windows 实机运行验证(临时日志 + 实机操作):
关闭的 Issue / Closes
Closes #800