Documentation
¶
Overview ¶
Package store 把用户设置和界面状态落到磁盘。
目录由调用方给(桌面包传 mygo 的用户数据目录),所以这个包不依赖 mygo, 测试里给个 t.TempDir() 就能完整跑。
三条约定:
- 读文件失败(第一次启动没有文件、JSON 损坏)一律当作空,绝不因此 让应用起不来 —— 配置文件坏了可以重建,应用打不开就全完了。
- 写入先落临时文件再 rename:中途崩掉也不会留下半个 JSON。
- 有 API key,config.json 用 0600。
Index ¶
- type Config
- type State
- type Store
- func (s *Store) AddRecentRepo(path string)
- func (s *Store) ClearRecentRepos()
- func (s *Store) Config() Config
- func (s *Store) Dir() string
- func (s *Store) Provider() *llm.Provider
- func (s *Store) Save() error
- func (s *Store) SetConfig(c Config)
- func (s *Store) SetDraft(repo, msg string)
- func (s *Store) SetLastRepo(path string)
- func (s *Store) SetOpenRepos(paths []string)
- func (s *Store) SetViewed(m map[string]string)
- func (s *Store) State() State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Providers []llm.Provider `json:"providers,omitempty"`
// Active 是当前使用的供应商下标。
Active int `json:"active,omitempty"`
// CodeSize 是代码字号,0 表示用默认值。
CodeSize float32 `json:"codeSize,omitempty"`
// Split 为 true 时用左右对照视图。
Split bool `json:"split,omitempty"`
// Unified 为 true 时用单栏统一视图(默认左右对照)。
Unified bool `json:"unified,omitempty"`
// SidebarOff 而不是 SidebarOn:侧栏默认是开的,零值正好表示这个默认。
SidebarOff bool `json:"sidebarOff,omitempty"`
// SidebarWidth 是侧栏宽度,0 表示默认值。
SidebarWidth float32 `json:"sidebarWidth,omitempty"`
// FilePaneWidth 是主区文件列表栏宽度,0 表示默认值。
FilePaneWidth float32 `json:"filePaneWidth,omitempty"`
// ThemeMode 是外观模式偏好:"" 或 "system"(跟随系统)、"light"(浅色模式)、"dark"(暗黑模式)。
ThemeMode string `json:"themeMode,omitempty"`
// Locale 是界面语言设定:"" 或 "zh"(简体中文)、"en"(English)。
Locale string `json:"locale,omitempty"`
// AppIcon 是应用图标风格:"black"(纯黑曜石)或 "white"(纯白极简)。
AppIcon string `json:"appIcon,omitempty"`
// CommitPrompt 是自定义 Git 提交信息提示词,留空使用内置预设。
CommitPrompt string `json:"commitPrompt,omitempty"`
// BranchPrompt 是自定义 Git 分支名生成提示词,留空使用内置预设。
BranchPrompt string `json:"branchPrompt,omitempty"`
}
Config 是用户设置。
func (Config) EffectiveBranchPrompt ¶
EffectiveBranchPrompt 返回生效的 Git 分支名生成系统提示词。
func (Config) EffectiveCommitPrompt ¶
EffectiveCommitPrompt 返回生效的 Git 提交信息生成系统提示词。
type State ¶
type State struct {
LastRepo string `json:"lastRepo,omitempty"`
RecentRepos []string `json:"recentRepos,omitempty"`
OpenRepos []string `json:"openRepos,omitempty"`
// Viewed 是「已 review」标记:文件路径 -> 当时的内容指纹。
Viewed map[string]string `json:"viewed,omitempty"`
// Drafts 是各仓库的提交信息草稿:仓库根路径 -> 还没提交出去的消息。
// 消息写到一半切去看别的仓库、或者关掉窗口,回来还应该在。
Drafts map[string]string `json:"drafts,omitempty"`
}
State 是跟着仓库走的界面状态。
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store 是两份文件(设置、状态)的门面,可被多个 goroutine 同时使用。
func Open ¶
Open 从 dir 读取已有的设置和状态。文件不存在或读不动都当作空, 返回值不会是 nil。dir 为空表示「没有数据目录」:读写都变成空操作, 应用照常能跑,只是这次的改动不会被保存。
func (*Store) AddRecentRepo ¶
AddRecentRepo 将 path 记为最近打开的仓库(最新的在最前),并更新 LastRepo。
func (*Store) Save ¶
Save 把两份文件写回磁盘。
用法是「改完就存」:文件都很小,写一次在毫秒级,不值得为它做脏标记或者 防抖。整段加锁,所以并发调用是安全的(后一次写覆盖前一次,结果一致)。
func (*Store) SetLastRepo ¶
SetLastRepo 记住最后打开的仓库,下次启动直接打开。
func (*Store) SetOpenRepos ¶
SetOpenRepos 记住当前打开的多个项目仓库路径列表。