feat: 完成账号桌面快捷方式
- 新增 chrome.create_shortcut 使用 PowerShell WScript.Shell 生成 .lnk - 快捷方式参数复用 Chrome 启动参数,包含调试端口、allow-origins 和账号 user-data-dir - 在账号服务层和 Tab④ 增加快捷方式入口,不包含密码或密钥 - 补充 chrome/accounts/gui 测试并同步任务、API、路由、当前状态和进度文档
This commit is contained in:
@@ -90,6 +90,32 @@ class AccountsTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_create_shortcut_uses_account_record(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
account = accounts.create_account("主店", "alias", debug_port=9222, config=cfg)
|
||||
shortcut_path = os.path.join(temp_dir, "Desktop", "主店.lnk")
|
||||
|
||||
with mock.patch(
|
||||
"app.accounts.chrome.create_shortcut",
|
||||
return_value=shortcut_path,
|
||||
) as create_shortcut:
|
||||
result = accounts.create_shortcut(
|
||||
"alias",
|
||||
shortcut_path=shortcut_path,
|
||||
config=cfg,
|
||||
)
|
||||
|
||||
self.assertEqual(shortcut_path, result)
|
||||
create_shortcut.assert_called_once_with(
|
||||
account,
|
||||
shortcut_path=shortcut_path,
|
||||
desktop_dir=None,
|
||||
config=cfg,
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_detect_login_updates_last_login_at_when_logged_in(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
@@ -111,6 +111,38 @@ class ChromeTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_create_shortcut_writes_lnk_with_required_chrome_arguments(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
chrome_path = os.path.join(temp_dir, "Chrome App", "chrome.exe")
|
||||
shortcut_path = os.path.join(temp_dir, "Desktop", "主店.lnk")
|
||||
account = {
|
||||
"alias": "alias",
|
||||
"debug_port": 9222,
|
||||
"user_data_dir": os.path.join(temp_dir, "profile with space"),
|
||||
}
|
||||
cfg = {"chrome_path": chrome_path}
|
||||
|
||||
with mock.patch("app.chrome.subprocess.run") as run:
|
||||
result = chrome.create_shortcut(
|
||||
account,
|
||||
shortcut_path=shortcut_path,
|
||||
config=cfg,
|
||||
)
|
||||
|
||||
self.assertEqual(os.path.abspath(shortcut_path), result)
|
||||
run.assert_called_once()
|
||||
command = run.call_args[0][0]
|
||||
self.assertEqual("powershell", command[0])
|
||||
script = command[-1]
|
||||
self.assertIn("$shortcut.TargetPath", script)
|
||||
self.assertIn(chrome_path, script)
|
||||
self.assertIn("--remote-debugging-port=9222", script)
|
||||
self.assertIn("--remote-allow-origins=*", script)
|
||||
self.assertIn("--user-data-dir=", script)
|
||||
self.assertIn("profile with space", script)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_is_running_and_wait_debug_ready(self):
|
||||
port = self.start_json_version_server()
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
@@ -126,6 +127,28 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_accounts_tab_create_shortcut_for_selected_account(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
account = accounts.create_account("主店", "alias", debug_port=9222, config=cfg)
|
||||
statuses = []
|
||||
tab = AccountsTab(config=cfg, status_callback=statuses.append)
|
||||
self.addCleanup(tab.close)
|
||||
tab.table.selectRow(0)
|
||||
shortcut_path = os.path.join(temp_dir, "Desktop", "主店.lnk")
|
||||
|
||||
with mock.patch(
|
||||
"app.gui.accounts.create_shortcut",
|
||||
return_value=shortcut_path,
|
||||
) as create_shortcut, mock.patch("app.gui.QMessageBox.information") as info:
|
||||
tab.create_shortcut()
|
||||
|
||||
create_shortcut.assert_called_once_with(account, config=cfg)
|
||||
info.assert_called_once()
|
||||
self.assertIn(shortcut_path, statuses[-1])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user