Peach: Local-first video metadata scraper and media manager.
fix(desktop): 快捷方式失败时报出 PowerShell 说的原因
longmeidaoae7ef08f538f
diff --git a/src/peach/desktop_startup.py b/src/peach/desktop_startup.pyindex 58b5fc65a..8075da56d 100644--- a/src/peach/desktop_startup.py+++ b/src/peach/desktop_startup.py@@ -59,7 +59,14 @@ def shortcut(action: str, path: Path, *, target: str = "", arguments: str = "",capture_output=True, text=True, encoding="utf-8", timeout=15,creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0), check=False)if result.returncode:- raise OSError("启动项未能保存,请检查当前用户的启动文件夹权限")+ # PowerShell 说的原因不能吞掉。只留「请检查权限」这一句时,Windows runner 上+ # 这一步失败了三次,而权限、`WScript.Shell` COM 不可用、路径没落地和扩展名+ # 校验不通过在消息里长得一模一样,谁都没法往下查。+ detail = next((line.strip() for line in+ (result.stderr or result.stdout or "").splitlines()+ if line.strip()), "")+ raise OSError("启动项未能保存,请检查当前用户的启动文件夹权限"+ + (f"(PowerShell:{detail})" if detail else ""))return json.loads(result.stdout.lstrip("\ufeff"))diff --git a/tests/test_desktop_settings.py b/tests/test_desktop_settings.pyindex 814c0b249..5eec0f2cd 100644--- a/tests/test_desktop_settings.py+++ b/tests/test_desktop_settings.py@@ -141,6 +141,20 @@ class DesktopSettingsTests(unittest.TestCase):desktop_startup.shortcut('remove', path, expected=result['target'])self.assertFalse(path.exists())+ @unittest.skipUnless(os.name == 'nt', 'Windows 原生快捷方式')+ def test_a_failed_shortcut_call_reports_what_powershell_said(self):+ """失败的消息带上 PowerShell 的第一行原因,不只给一句「请检查权限」。++ 权限不足、`WScript.Shell` COM 起不来、路径没落地、扩展名不是 `.lnk`——这几种+ 在只有一句提示的消息里长得一模一样。CI 的 Windows runner 上这一步失败过,日志里+ 除了那句提示什么都没有,无从判断是哪一种。+ """+ with self.assertRaises(OSError) as raised:+ desktop_startup.shortcut('write', self.root / '不是快捷方式.txt',+ target=str(self.program / 'Peach.exe'))+ self.assertIn('启动项未能保存', str(raised.exception))+ self.assertIn('PowerShell', str(raised.exception))+@unittest.skipUnless(os.name == 'nt', 'Windows 系统卸载助手')def test_native_uninstall_removes_only_temporary_owned_program_and_data(self):for key in settings_file.DIRECTORY_KEYS: