新增: 历史对话收藏功能,重构 Tab 导航与平台检查

This commit is contained in:
2026-05-22 10:46:57 +08:00
parent 5e6708d049
commit e125ac6088
2 changed files with 476 additions and 243 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -88,6 +88,7 @@ type HistoryState struct {
FocusPanel int // 0=左栏 1=中栏
Loaded bool
Scanning bool
Favorites map[string]bool
}
// IsHistoryTab 判断当前是否在 HISTORY Tab
@@ -203,7 +204,6 @@ func scanSessionFile(path string, sessionID string) *Session {
scanner := bufio.NewScanner(f)
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
lineCount := 0
firstMsgFound := false
@@ -551,3 +551,76 @@ func saveSummaryToCache(sessionID, summary string, completed, pending []string)
entry.Pending = pending
saveCache(home, cache)
}
// --- 收藏 ---
func favoritesPath(home string) string {
return filepath.Join(home, ".u-tabs", "favorites.json")
}
func loadFavorites() map[string]bool {
home, err := os.UserHomeDir()
if err != nil {
return make(map[string]bool)
}
data, err := os.ReadFile(favoritesPath(home))
if err != nil {
return make(map[string]bool)
}
var ids []string
if json.Unmarshal(data, &ids) != nil {
return make(map[string]bool)
}
m := make(map[string]bool, len(ids))
for _, id := range ids {
m[id] = true
}
return m
}
func saveFavorites(favs map[string]bool) {
home, err := os.UserHomeDir()
if err != nil {
return
}
ids := make([]string, 0, len(favs))
for id := range favs {
ids = append(ids, id)
}
data, err := json.Marshal(ids)
if err != nil {
return
}
dir := filepath.Join(home, ".u-tabs")
if err := os.MkdirAll(dir, 0o755); err != nil {
log.Printf("[u-tabs] favorites mkdir fail: %v", err)
return
}
if err := os.WriteFile(favoritesPath(home), data, 0o644); err != nil {
log.Printf("[u-tabs] favorites write fail: %v", err)
}
}
func countFavorites(projects []*ProjectDir, favs map[string]bool) int {
n := 0
for _, pd := range projects {
for _, s := range pd.Sessions {
if favs[s.ID] {
n++
}
}
}
return n
}
func collectFavorites(projects []*ProjectDir, favs map[string]bool) []*Session {
var out []*Session
for _, pd := range projects {
for _, s := range pd.Sessions {
if favs[s.ID] {
out = append(out, s)
}
}
}
return out
}