Skip to content

fix: skip shell fork when temperature tools unavailable (#8)#22

Merged
ShadyUnderLight merged 1 commit into
mainfrom
fix/issue8-command-temperature-cache
Apr 20, 2026
Merged

fix: skip shell fork when temperature tools unavailable (#8)#22
ShadyUnderLight merged 1 commit into
mainfrom
fix/issue8-command-temperature-cache

Conversation

@ShadyUnderLight
Copy link
Copy Markdown
Owner

改动说明

SystemMetricsProvider.bestEffortCPUTemperature 在 Apple Silicon 温度读取失败后 fallback 到 shell 命令时,每次 cache 失效都会 fork/exec 一个 zsh + 两条 command -v 检测,工具不存在时 exit 127,白跑进程。

解决方案

  1. 引入 availableCommandCache: String? 缓存已确认可用的命令路径
  2. 首次检测时在单次 zsh 调用里并行检测 istatsosx-cpu-temp,确认后再执行实际命令
  3. 两个工具均不存在时返回 nil,并将 cache 设为 nil;后续调用跳过检测直接返回

关键语义

  • availableCommandCache == nil(初始态):尚未检测,需要检测
  • availableCommandCache == ""(检测后):两个工具都找不到,后续跳过
  • availableCommandCache == "/path/to/istats"(检测后):找到可用的,后续直接用

行为变化

场景 旧行为 新行为
两个工具都不存在 每次刷新都 fork zsh + 两条 command-v + exit 127 第一次检测后跳过,后续不再 fork
istats 存在 每次刷新 fork zsh + 两条检测 + istats 第一次 fork 检测,之后只 fork istats

Closes #8

@ShadyUnderLight ShadyUnderLight force-pushed the fix/issue8-command-temperature-cache branch from aebd833 to 40aa50f Compare April 20, 2026 06:33
- 3-state TemperatureToolState enum: .unchecked / .unavailable / .resolved(kind:, path:)
- resolveTemperatureTool() now echoes both tool kind and resolved path via command -v
- runTemperatureCommand takes resolved path directly — no more hardcoded /usr/local/bin
- detection and execution share the same source-of-truth resolved path
- 3-state caching behavior preserved: unresolved = detects once, unavailable = skips detection
@ShadyUnderLight ShadyUnderLight force-pushed the fix/issue8-command-temperature-cache branch from 40aa50f to fae91bb Compare April 20, 2026 06:39
@ShadyUnderLight ShadyUnderLight merged commit 99f106d into main Apr 20, 2026
2 checks passed
@ShadyUnderLight ShadyUnderLight deleted the fix/issue8-command-temperature-cache branch April 20, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] commandTemperature 每次调用都 fork 新 shell,istats/osx-cpu-temp 不存在时白跑进程

1 participant