mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
无界面Linux自动启用无头;MAC和Linux添加默认浏览器路径
This commit is contained in:
parent
02c63385f2
commit
95717981c8
@ -8,6 +8,7 @@ from pathlib import Path
|
||||
from subprocess import Popen, DEVNULL
|
||||
from tempfile import gettempdir
|
||||
from time import perf_counter, sleep
|
||||
from platform import system
|
||||
|
||||
from requests import get as requests_get
|
||||
|
||||
@ -62,6 +63,7 @@ def get_launch_args(opt):
|
||||
result = set()
|
||||
has_user_path = False
|
||||
remote_allow = False
|
||||
headless = False
|
||||
for i in opt.arguments:
|
||||
if i.startswith(('--load-extension=', '--remote-debugging-port=')):
|
||||
continue
|
||||
@ -71,6 +73,8 @@ def get_launch_args(opt):
|
||||
continue
|
||||
elif i.startswith('--remote-allow-origins='):
|
||||
remote_allow = True
|
||||
elif i.startswith('--headless'):
|
||||
headless = True
|
||||
|
||||
result.add(i)
|
||||
|
||||
@ -83,6 +87,12 @@ def get_launch_args(opt):
|
||||
if not remote_allow:
|
||||
result.add('--remote-allow-origins=*')
|
||||
|
||||
if not headless and system().lower() == 'linux':
|
||||
from os import popen
|
||||
r = popen('systemctl list-units | grep graphical.target')
|
||||
if 'graphical.target' not in r.read():
|
||||
result.add('--headless=new')
|
||||
|
||||
result = list(result)
|
||||
|
||||
# ----------处理插件extensions-------------
|
||||
@ -164,7 +174,7 @@ def test_connect(ip, port):
|
||||
def _run_browser(port, path: str, args) -> Popen:
|
||||
"""创建chrome进程
|
||||
:param port: 端口号
|
||||
:param path: 浏览器地址
|
||||
:param path: 浏览器路径
|
||||
:param args: 启动参数
|
||||
:return: 进程对象
|
||||
"""
|
||||
|
@ -197,7 +197,19 @@ def get_chrome_path(ini_path=None,
|
||||
return str(path)
|
||||
|
||||
from platform import system
|
||||
if system().lower() != 'windows':
|
||||
sys = system().lower()
|
||||
if sys == 'macos':
|
||||
return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
||||
|
||||
elif sys == 'linux':
|
||||
paths = ('/usr/bin/google-chrome', '/opt/google/chrome/google-chrome',
|
||||
'/user/lib/chromium-browser/chromium-browser')
|
||||
for p in paths:
|
||||
if Path(p).exists():
|
||||
return p
|
||||
return None
|
||||
|
||||
elif sys != 'windows':
|
||||
return None
|
||||
|
||||
# -----------从注册表中获取--------------
|
||||
@ -207,8 +219,6 @@ def get_chrome_path(ini_path=None,
|
||||
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
|
||||
r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe',
|
||||
reserved=0, access=winreg.KEY_READ)
|
||||
# key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Google\Chrome\BLBeacon\version',
|
||||
# reserved=0, access=winreg.KEY_READ)
|
||||
k = winreg.EnumValue(key, 0)
|
||||
winreg.CloseKey(key)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user