1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-12 22:10:14 +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

@@ -84,6 +84,13 @@ func isZeroLoad(avg load.AvgStat) bool {
return avg.Load1 == 0 && avg.Load5 == 0 && avg.Load15 == 0
}
var (
// Package-level cache for core topology
lastTopologyAt time.Time
cachedP, cachedE int
topologyTTL = 10 * time.Minute
)
// getCoreTopology returns P-core and E-core counts on Apple Silicon.
// Returns (0, 0) on non-Apple Silicon or if detection fails.
func getCoreTopology() (pCores, eCores int) {
@@ -91,6 +98,13 @@ func getCoreTopology() (pCores, eCores int) {
return 0, 0
}
now := time.Now()
if cachedP > 0 || cachedE > 0 {
if now.Sub(lastTopologyAt) < topologyTTL {
return cachedP, cachedE
}
}
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
@@ -130,6 +144,8 @@ func getCoreTopology() (pCores, eCores int) {
eCores = level1Count
}
cachedP, cachedE = pCores, eCores
lastTopologyAt = now
return pCores, eCores
}