Skip to content

fix(macos): handle the no-sensor case — report "N/A" and keep the fan turning - #5

Merged
kerwin2046 merged 2 commits into
mainfrom
fix/macos-sensor-unavailable
Sep 29, 2026
Merged

kerwin2046 merged 2 commits into
mainfrom
fix/macos-sensor-unavailable

Conversation

@yuxino

@yuxino yuxino commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4

Problem

Fan RPM and every temperature come from readHwmon(), which reads /sys/class/hwmon — Linux-only. On macOS there is no such path, so fanRpm and all temperatures are null. Two things then went wrong:

  1. The HUD claimed the fan was "Stopped" — a false statement, made while the real fan was spinning at full speed.
  2. The 3D fan never turned, because Cooling.tsx does live?.fanRpm ?? 0. It read as broken rather than merely unmeasured.

HUD before/after

Change 1 — stop claiming "Stopped"

LiveStats gains sensorsAvailable, true only when hwmon reported at least one device. The two places that render the fan now tell three cases apart:

state shown
no hwmon at all (macOS) "N/A" ← new
hwmon present, reading 0 (Linux) "Stopped" (unchanged)
a reading (Linux) "1234 RPM" (unchanged)

Change 2 — keep the fan turning

Cooling.tsx now picks its animation speed through one helper:

function fanRpm(live: LiveStats | null): number {
  if (!live) return 0;
  // On Linux hwmon exists, so a null reading genuinely means "stopped".
  return live.fanRpm ?? (live.sensorsAvailable ? 0 : FAN_IDLE_RPM);
}

On a platform with no sensors the blades idle-spin instead of sitting dead. Linux keeps its exact previous behaviour — including correctly showing a genuinely stopped fan.

Looped capture from this Mac — frozen before, turning after:

fan spin

What this does NOT do

It does not invent a macOS sensor source; there is none without root (routes checked in #4). The HUD and the cooling panel still say "N/A" because the speed genuinely is not measured — the idle spin is a visual affordance (a laptop fan is always turning), not a reading. Temperatures still show "—".

Tested

  • macOS — /api/live reports sensorsAvailable: false; the HUD went Fan Stopped → Fan N/A.
  • Motion check — 6 frames ~220 ms apart over the fan area: before this change 82 px differ between frames (noise); after, 3250–3851 px differ, i.e. the blades really are rotating.
  • pnpm typecheck passes.
  • Linux — sensorsAvailable: true, so both the text and the animation are unchanged.

Fan RPM and every temperature come from readHwmon(), which reads
/sys/class/hwmon — Linux-only. On macOS that path does not exist, so
fanRpm is null and the HUD rendered it as "Stopped", i.e. it stated the
fan was stopped while the fan was in fact spinning.

Add LiveStats.sensorsAvailable (true when hwmon reported any device) and
use it to show an "N/A" state instead of "Stopped" in the HUD and in the
cooling detail panel. Linux behaviour is unchanged: there hwmon exists, so
a null fanRpm still means the fan really is stopped.
On macOS there is no hwmon at all, so fanRpm is always null and the 3D fan
never turned — it read as broken rather than merely unmeasured, even while
the real fan was spinning.

When live data is present but sensorsAvailable is false, fall back to a slow
idle spin so the model stays alive. Linux is unchanged: there hwmon exists,
so a null reading genuinely means the fan is stopped.
@yuxino yuxino changed the title fix(hud): don't claim the fan is "Stopped" when no sensors exist fix(macos): handle the no-sensor case — report "N/A" and keep the fan turning Sep 29, 2026
@kerwin2046
kerwin2046 merged commit cf00bc7 into main Sep 29, 2026
0 of 2 checks passed
@kerwin2046

Copy link
Copy Markdown
Owner

@yuxino Thank you for the great contribution! 🙌

Really appreciate you digging into the macOS disk image issue and providing such a thorough fix. It’s great to have you contributing to PC·XRAY! 🚀

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.

macOS: fan reported as "Stopped" and every temperature blank (there is no sensor source)

2 participants