Peach: Local-first video metadata scraper and media manager.
fix(installer): 停止消息一条都没投出时立即报失败
longmeidaoaa3582423aa5
diff --git a/src/peach/desktop_installer.py b/src/peach/desktop_installer.pyindex 5902bb093..9546d13b4 100644--- a/src/peach/desktop_installer.py+++ b/src/peach/desktop_installer.py@@ -81,8 +81,11 @@ def stop(program: Path, *, timeout: float = 60) -> bool:托盘管,只能按镜像路径清场,否则覆盖安装写不进被占用的 DLL。"""from .windows_restart import find_tray_windows, post_stop- for window in find_tray_windows(program / "Peach.exe"):- post_stop(window.handle)+ windows = find_tray_windows(program / "Peach.exe")+ # 每个窗口都投递一次;一条都没投出去、窗口又还在,托盘收不到停止消息,等也不会退。+ sent = [post_stop(window.handle) for window in windows]+ if windows and not any(sent) and find_tray_windows(program / "Peach.exe"):+ return Falsedeadline = time.monotonic() + timeoutwhile find_tray_windows(program / "Peach.exe"):if time.monotonic() > deadline:diff --git a/tests/test_desktop_installer.py b/tests/test_desktop_installer.pyindex 7cad80d5a..6f122d453 100644--- a/tests/test_desktop_installer.py+++ b/tests/test_desktop_installer.py@@ -195,6 +195,21 @@ class InstallerHandoffTests(unittest.TestCase):with patch.object(desktop_installer.distribution, "standalone", return_value=False):self.assertEqual(desktop_installer.main("--installer-stop"), 2)+ def test_stop_gives_up_at_once_when_no_stop_message_reaches_the_tray(self):+ with patch("peach.windows_restart.find_tray_windows", return_value=(TrayWindow(10, 20),)), \+ patch("peach.windows_restart.post_stop", return_value=False), \+ patch.object(desktop_installer.time, "sleep") as sleep:+ self.assertFalse(desktop_installer.stop(self.root))+ sleep.assert_not_called()++ def test_a_tray_that_closed_before_the_message_counts_as_stopped(self):+ windows = [(TrayWindow(10, 20),), (), ()]+ with patch("peach.windows_restart.find_tray_windows", side_effect=lambda _: windows.pop(0)), \+ patch("peach.windows_restart.post_stop", return_value=False), \+ patch.object(desktop_installer, "_running_from", return_value=[]), \+ patch.object(desktop_installer.time, "sleep"):+ self.assertTrue(desktop_installer.stop(self.root))+def test_stop_waits_for_the_tray_to_exit(self):windows = [(TrayWindow(10, 20),), (TrayWindow(10, 20),), ()]with patch("peach.windows_restart.find_tray_windows", side_effect=lambda _: windows.pop(0)), \