fix: recognize modern Chrome Sessions so open restores login
All checks were successful
技能自动化发布 / release (push) Successful in 10s
All checks were successful
技能自动化发布 / release (push) Successful in 10s
This commit is contained in:
@@ -14,7 +14,10 @@ import sys
|
||||
|
||||
from db.connection import get_conn, init_db
|
||||
from db.accounts_repo import get_account_by_id, get_platform_from_db
|
||||
from service.chrome_profile_prefs import ensure_session_restore
|
||||
from service.chrome_profile_prefs import (
|
||||
ensure_session_restore,
|
||||
profile_has_restorable_session,
|
||||
)
|
||||
from util.logging_config import get_skill_logger
|
||||
from util.platforms import PLATFORMS
|
||||
|
||||
@@ -314,12 +317,9 @@ def cmd_open(account_id):
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
# 有可恢复会话时不带 URL;首次/空 Profile 仍打开平台首页便于登录
|
||||
session_dir = os.path.join(profile_abs, "Default")
|
||||
has_session = any(
|
||||
os.path.isfile(os.path.join(session_dir, name))
|
||||
for name in ("Current Session", "Last Session", "Current Tabs", "Last Tabs")
|
||||
)
|
||||
# 有可恢复会话时不带 URL;首次/空 Profile 仍打开平台首页便于登录。
|
||||
# 须识别现代 Chrome 的 Default/Sessions/Session_*(仅认旧文件名会导致每次都开首页冲掉 Session Cookie)。
|
||||
has_session = profile_has_restorable_session(profile_abs)
|
||||
launch_url = None if has_session else url
|
||||
cmd = [browser_exe, *human_chrome_launch_args(profile_abs, launch_url)]
|
||||
|
||||
|
||||
@@ -10,6 +10,41 @@ from util.logging_config import get_skill_logger
|
||||
|
||||
RESTORE_CONTINUE_WHERE_LEFT_OFF = 1
|
||||
|
||||
# Chromium ≤ roughly mid-era: session files lived under Default/
|
||||
_LEGACY_SESSION_FILES = (
|
||||
"Current Session",
|
||||
"Last Session",
|
||||
"Current Tabs",
|
||||
"Last Tabs",
|
||||
)
|
||||
|
||||
|
||||
def profile_has_restorable_session(profile_dir: str) -> bool:
|
||||
"""True when the profile has on-disk session data Chrome can restore.
|
||||
|
||||
Modern Chrome/Edge write ``Default/Sessions/Session_*`` (and ``Tabs_*``).
|
||||
Older builds used ``Default/Current Session`` etc. Either form counts.
|
||||
"""
|
||||
default_dir = os.path.join(os.path.abspath(profile_dir), "Default")
|
||||
if any(
|
||||
os.path.isfile(os.path.join(default_dir, name))
|
||||
for name in _LEGACY_SESSION_FILES
|
||||
):
|
||||
return True
|
||||
|
||||
sessions_dir = os.path.join(default_dir, "Sessions")
|
||||
if not os.path.isdir(sessions_dir):
|
||||
return False
|
||||
try:
|
||||
names = os.listdir(sessions_dir)
|
||||
except OSError:
|
||||
return False
|
||||
return any(
|
||||
name.startswith("Session_") or name.startswith("Tabs_")
|
||||
for name in names
|
||||
if os.path.isfile(os.path.join(sessions_dir, name))
|
||||
)
|
||||
|
||||
|
||||
def preferences_path(profile_dir: str) -> str:
|
||||
return os.path.join(os.path.abspath(profile_dir), "Default", "Preferences")
|
||||
|
||||
Reference in New Issue
Block a user