Peach: Local-first video metadata scraper and media manager.
fix(desktop): 补齐快捷方式操作超时反馈
longmeidao74d359088a14
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fb2973c3e..ed5094d2b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -29,6 +29,7 @@ Removed / Fixed / Security。- **桌面**:Windows 安装包与免安装包使用完整的锁定依赖构建;安装包支持选择程序目录。- **桌面**:Windows 桌面处于共享 Job 时可独立启动托盘,终端或智能体退出后保持运行。+- **桌面**:快捷方式操作超时会显示等待时长和重试提示。- **配置**:首次设置可接回已有数据目录;升级沿用配置、账本和访问密码,并记住数据目录。- **配置**:媒体目录校验保留 NAS 映射盘的盘符路径。diff --git a/src/peach/desktop_startup.py b/src/peach/desktop_startup.pyindex 50501f8e0..da027b0b9 100644--- a/src/peach/desktop_startup.py+++ b/src/peach/desktop_startup.py@@ -65,6 +65,9 @@ try {#: 读到的快捷方式状态,键是路径,值是 `(指纹, 结论)`。指纹见 `_fingerprint`。_READ_CACHE: dict[str, tuple[tuple, dict]] = {}+#: PowerShell 冷启动与快捷方式操作的总等待时限。+_SHORTCUT_TIMEOUT = 60+def _fingerprint(path: Path) -> tuple:"""这个 `.lnk` 的当前身份。文件不在就是 `()`,内容变了指纹一定跟着变。"""@@ -95,11 +98,14 @@ def shortcut(action: str, path: Path, *, target: str = "", arguments: str = "",encoded = base64.b64encode(_SHORTCUT_SCRIPT.encode("utf-16-le")).decode("ascii")# 和 folder_picker 相同:发行包使用 Windows 自带的 PowerShell,不要求用户安装 pwsh。shell = Path(os.environ.get("SystemRoot", r"C:\Windows")) / "System32/WindowsPowerShell/v1.0/powershell.exe"- result = subprocess.run([str(shell), "-NoProfile", "-NonInteractive", "-EncodedCommand", encoded],- input=json.dumps(dict(action=action, path=str(path), target=target, arguments=arguments,- directory=directory, expected=expected)),- capture_output=True, text=True, encoding="utf-8", timeout=15,- creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0), check=False)+ try:+ result = subprocess.run([str(shell), "-NoProfile", "-NonInteractive", "-EncodedCommand", encoded],+ input=json.dumps(dict(action=action, path=str(path), target=target, arguments=arguments,+ directory=directory, expected=expected)),+ capture_output=True, text=True, encoding="utf-8", timeout=_SHORTCUT_TIMEOUT,+ creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0), check=False)+ except subprocess.TimeoutExpired as exc:+ raise OSError(f"Windows 快捷方式操作超时(等待 {_SHORTCUT_TIMEOUT} 秒),请稍后重试。") from exctry:payload = json.loads(result.stdout.lstrip(""))except ValueError:diff --git a/tests/test_desktop_settings.py b/tests/test_desktop_settings.pyindex cb49ae892..648c7a758 100644--- a/tests/test_desktop_settings.py+++ b/tests/test_desktop_settings.py@@ -34,6 +34,14 @@ class DesktopSettingsTests(unittest.TestCase):desktop_startup._READ_CACHE.clear()self.addCleanup(desktop_startup._READ_CACHE.clear)+ def test_shortcut_timeout_has_an_actionable_error_and_original_cause(self):+ failure = subprocess.TimeoutExpired(['powershell.exe'], 60)+ with patch('peach.desktop_startup.subprocess.run', side_effect=failure):+ with self.assertRaisesRegex(OSError, '快捷方式操作超时.*60 秒') as raised:+ desktop_startup.shortcut('write', self.root / 'Peach.lnk',+ target=str(self.program / 'Peach.exe'))+ self.assertIs(raised.exception.__cause__, failure)+def test_uninstall_plan_keeps_media_and_can_preserve_all_data(self):keep = desktop_uninstall.plan(self.config, delete_data=False, program=self.program)self.assertEqual(keep['directories'], [])