1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-12 10:33:30 +00:00

feat: enhance status UI with new styles and icons, refactor battery metrics with caching, and centralize Apple Silicon clean logic.

This commit is contained in:
Tw93
2025-12-19 20:34:23 +08:00
parent 4b740ee543
commit be43f68cc1
5 changed files with 138 additions and 62 deletions

View File

@@ -93,26 +93,42 @@ func collectDisks() ([]DiskStatus, error) {
return disks, nil
}
var (
// Package-level cache for external disk status
lastDiskCacheAt time.Time
diskTypeCache = make(map[string]bool)
diskCacheTTL = 2 * time.Minute
)
func annotateDiskTypes(disks []DiskStatus) {
if len(disks) == 0 || runtime.GOOS != "darwin" || !commandExists("diskutil") {
return
}
cache := make(map[string]bool)
now := time.Now()
// Clear cache if stale
if now.Sub(lastDiskCacheAt) > diskCacheTTL {
diskTypeCache = make(map[string]bool)
lastDiskCacheAt = now
}
for i := range disks {
base := baseDeviceName(disks[i].Device)
if base == "" {
base = disks[i].Device
}
if val, ok := cache[base]; ok {
if val, ok := diskTypeCache[base]; ok {
disks[i].External = val
continue
}
external, err := isExternalDisk(base)
if err != nil {
external = strings.HasPrefix(disks[i].Mount, "/Volumes/")
}
disks[i].External = external
cache[base] = external
diskTypeCache[base] = external
}
}