Peach: Local-first video metadata scraper and media manager.
fix: name the service that is down instead of saying 部分运行
Peach local maintenance40180e97e707
diff --git a/src/peach/tray.py b/src/peach/tray.pyindex 4d31e0b7d..f5da3b92a 100644--- a/src/peach/tray.py+++ b/src/peach/tray.py@@ -162,13 +162,19 @@ class ServiceManager:return resultdef status(self) -> str:+ """菜单里那一行状态。++ 原来只说「部分运行」,看不出是谁没起来、也就不知道该去查什么——两个服务+ (HTTP 和 HTTPS)各自会因为端口占用、证书过期、pf 转发写错等完全不同的原因+ 挂掉。直接把没起来的那个点名。+ """with self._lock:- results = [self._last_health[spec.name] for spec in self.specs]- if all(results):+ down = [spec.name for spec in self.specs if not self._last_health[spec.name]]+ if not down:return "运行中"- if any(results):- return "部分运行"- return "未运行"+ if len(down) == len(self.specs):+ return "未运行"+ return "、".join(name.upper() for name in down) + " 未运行"def start_missing(self) -> None:LOG_DIR.mkdir(parents=True, exist_ok=True)@@ -504,6 +510,7 @@ def run_macos_menu_bar(manager: "ServiceManager") -> None:[("打开 Peach", lambda: webbrowser.open(OPEN_URL)),(lambda: f"状态:{manager.status()}", None),+ (f"地址:{OPEN_URL}", None),(None, None),("重启服务", restart),("查看日志", lambda: subprocess.run(["open", str(LOG_DIR)], check=False)),diff --git a/tests/test_tray.py b/tests/test_tray.pyindex 23b4eba2d..9f367a457 100644--- a/tests/test_tray.py+++ b/tests/test_tray.py@@ -113,6 +113,33 @@ class TrayTests(unittest.TestCase):first.close()+class ServiceStatusTests(unittest.TestCase):+ """状态文案要点名是谁没起来。++ 只说「部分运行」看不出该去查什么:HTTP 和 HTTPS 会因为端口占用、证书过期、+ pf 转发写错等完全不同的原因挂掉。+ """++ def manager(self, health: dict) -> ServiceManager:+ specs = tuple(+ ServiceSpec(name, f"http://127.0.0.1/{name}", ("noop",), True)+ for name in health+ )+ manager = ServiceManager(specs)+ manager._last_health.update(health)+ return manager++ def test_all_healthy(self):+ self.assertEqual(self.manager({"http": True, "https": True}).status(), "运行中")++ def test_none_healthy(self):+ self.assertEqual(self.manager({"http": False, "https": False}).status(), "未运行")++ def test_partial_names_the_broken_one(self):+ self.assertEqual(self.manager({"http": True, "https": False}).status(), "HTTPS 未运行")+ self.assertEqual(self.manager({"http": False, "https": True}).status(), "HTTP 未运行")++@unittest.skipUnless(sys.platform == "darwin", "菜单栏图标与服务规格是 macOS 专属")class MacMenuBarTests(unittest.TestCase):def test_template_icon_is_a_black_silhouette(self):