fix(accounts): keep first login launch in one window
This commit is contained in:
+30
-4
@@ -10,6 +10,7 @@ import subprocess
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from . import appconfig
|
||||
from . import config as account_config
|
||||
@@ -209,7 +210,27 @@ def _user_data_dir(account, config=None) -> str:
|
||||
return account_config.ensure_user_data_dir(slug, config=config)
|
||||
|
||||
|
||||
def build_launch_args(account, config=None) -> list:
|
||||
def _validated_initial_url(value):
|
||||
text = str(value or "").strip()
|
||||
if not text:
|
||||
return None
|
||||
try:
|
||||
parsed = urlsplit(text)
|
||||
except ValueError as exc:
|
||||
raise ChromeLaunchError("Chrome 初始页面必须是有效的蝦皮 http/https 地址") from exc
|
||||
hostname = str(parsed.hostname or "").lower()
|
||||
is_shopee_host = hostname.startswith("shopee.") or ".shopee." in hostname
|
||||
if (
|
||||
parsed.scheme.lower() not in {"http", "https"}
|
||||
or not is_shopee_host
|
||||
or parsed.username
|
||||
or parsed.password
|
||||
):
|
||||
raise ChromeLaunchError("Chrome 初始页面必须是有效的蝦皮 http/https 地址")
|
||||
return text
|
||||
|
||||
|
||||
def build_launch_args(account, config=None, initial_url=None) -> list:
|
||||
"""Build Chrome command arguments for one account."""
|
||||
|
||||
chrome_path = appconfig.chrome_path(config)
|
||||
@@ -217,12 +238,17 @@ def build_launch_args(account, config=None) -> list:
|
||||
raise ChromeLaunchError("chrome_path 不能为空")
|
||||
port = _debug_port(account)
|
||||
user_data_dir = _user_data_dir(account, config=config)
|
||||
return [
|
||||
args = [
|
||||
chrome_path,
|
||||
f"--remote-debugging-port={port}",
|
||||
"--remote-allow-origins=*",
|
||||
f"--user-data-dir={user_data_dir}",
|
||||
]
|
||||
startup_url = _validated_initial_url(initial_url)
|
||||
if startup_url:
|
||||
args.extend(("--no-first-run", "--no-default-browser-check"))
|
||||
args.append(startup_url)
|
||||
return args
|
||||
|
||||
|
||||
def _safe_shortcut_name(value) -> str:
|
||||
@@ -300,10 +326,10 @@ def create_shortcut(account, shortcut_path=None, desktop_dir=None, name=None, co
|
||||
return shortcut_path
|
||||
|
||||
|
||||
def launch_chrome(account, config=None) -> subprocess.Popen:
|
||||
def launch_chrome(account, config=None, initial_url=None) -> subprocess.Popen:
|
||||
"""Launch Chrome for one account and return the process handle."""
|
||||
|
||||
args = build_launch_args(account, config=config)
|
||||
args = build_launch_args(account, config=config, initial_url=initial_url)
|
||||
try:
|
||||
return subprocess.Popen(args)
|
||||
except OSError as exc:
|
||||
|
||||
Reference in New Issue
Block a user