feat: windows adaptation (WMI thermal zones, battery fallback)

This commit is contained in:
snowy-yang committed 2026-09-12 19:53:24 +08:00
1 parent 28add64ae0
commit 8775c022bd
3 files changed
+59 -9

No files matched your search

+14 -8
View File
@@ -40,11 +40,14 @@ def _fmt_uptime(seconds: float) -> str:
def _power_str(p: dict) -> str:
if p["total_watts"] is None:
return "不支持(需要电池或Intel RAPL)"
src = {"battery": "电池", "rapl": "RAPL"}.get(p["source"], p["source"])
extra = f" (电池 {p['battery']}W)" if p["battery"] is not None and p["source"] == "rapl" else ""
return f"{p['total_watts']}W [{src}]{extra}"
if p["total_watts"] is not None:
src = {"battery": "电池", "rapl": "RAPL"}.get(p["source"], p["source"])
extra = f" (电池 {p['battery']}W)" if p["battery"] is not None and p["source"] == "rapl" else ""
return f"{p['total_watts']}W [{src}]{extra}"
if p.get("battery_percent") is not None:
state = "充电中" if p.get("plugged") else "放电中"
return f"电量 {p['battery_percent']}% ({state}),功率不可测"
return "不支持(需要电池或Intel RAPL)"
def _hottest(temps: dict):
@@ -78,15 +81,18 @@ def fmt_status(s: dict) -> str:
def fmt_power(s: dict) -> str:
p = s["power"]
if p["total_watts"] is None and p["battery"] is None:
if p["total_watts"] is None and p["battery"] is None and p.get("battery_percent") is None:
return templates.render(
"power",
power=("未获取到功耗数据。支持的来源:笔记本电池 /sys/class/power_supply,"
"Intel RAPL /sys/class/powercap (AMD/多数虚拟机不支持)。"),
power=("未获取到功耗数据。支持的来源:笔记本电池 /sys/class/power_supply 或系统电池接口,"
"Intel RAPL /sys/class/powercap (AMD/多数虚拟机/台式机不支持)。"),
)
lines = []
if p["battery"] is not None:
lines.append(f"电池功率: {p['battery']}W")
if p.get("battery_percent") is not None:
state = "充电中" if p.get("plugged") else "放电中"
lines.append(f"电量: {p['battery_percent']}% ({state})")
if p["domains"]:
lines.append("RAPL 域:")
lines += [f" {name}: {watts}W" for name, watts in p["domains"].items()]