T-585 Chrome 路径自动检测
This commit is contained in:
+10
-2
@@ -6,7 +6,7 @@ import os
|
||||
import sys
|
||||
import webbrowser
|
||||
|
||||
from .. import appconfig, diagnostics, update_check
|
||||
from .. import appconfig, chrome, diagnostics, update_check
|
||||
from ..version import APP_NAME, display_name
|
||||
from . import widgets as _widgets
|
||||
from .widgets import *
|
||||
@@ -136,6 +136,14 @@ def main() -> int:
|
||||
return 1
|
||||
if not _run_startup_update_gate():
|
||||
return 1
|
||||
window = MainWindow()
|
||||
try:
|
||||
startup = chrome.ensure_configured_chrome_path()
|
||||
except (OSError, appconfig.ConfigError) as exc:
|
||||
QMessageBox.critical(None, "启动配置错误", str(exc))
|
||||
return 1
|
||||
window = MainWindow(
|
||||
config=startup["config"],
|
||||
startup_status=startup["message"],
|
||||
)
|
||||
window.show()
|
||||
return app.exec()
|
||||
|
||||
+10
-1
@@ -74,7 +74,14 @@ def _fit_and_center_window(
|
||||
class MainWindow(QMainWindow):
|
||||
"""Main application window with the fixed five-tab workflow."""
|
||||
|
||||
def __init__(self, db_path=None, config=None, config_path=None, ai_models_path=None):
|
||||
def __init__(
|
||||
self,
|
||||
db_path=None,
|
||||
config=None,
|
||||
config_path=None,
|
||||
ai_models_path=None,
|
||||
startup_status="",
|
||||
):
|
||||
super().__init__()
|
||||
self._initial_window_fit_applied_after_show = False
|
||||
self.config = appconfig.load_config(config_path or appconfig.CONFIG_PATH) if config is None else config
|
||||
@@ -104,6 +111,8 @@ class MainWindow(QMainWindow):
|
||||
self.tabs.setTabIcon(TAB_TITLES.index("③ 更新蝦皮"), _warning_dot_icon())
|
||||
self.setCentralWidget(self.tabs)
|
||||
self.show_status("就绪", level="muted")
|
||||
if startup_status:
|
||||
self.show_status(startup_status, level="success")
|
||||
|
||||
def showEvent(self, event):
|
||||
super().showEvent(event)
|
||||
|
||||
@@ -6,6 +6,7 @@ from contextlib import contextmanager
|
||||
import os
|
||||
|
||||
from ... import ai as ai_module
|
||||
from ... import chrome
|
||||
from ..widgets import *
|
||||
from ..workers import AIModelTestWorker as _RealAIModelTestWorker
|
||||
from ..workers import CMHubSettingsWorker as _RealCMHubSettingsWorker
|
||||
@@ -165,6 +166,8 @@ class SettingsTab(QWidget):
|
||||
self.chrome_path_edit.setObjectName("chromePathEdit")
|
||||
self.chrome_path_browse_button = QPushButton("选择...")
|
||||
self.chrome_path_browse_button.setObjectName("chromePathBrowseButton")
|
||||
self.chrome_path_detect_button = QPushButton("自动检测")
|
||||
self.chrome_path_detect_button.setObjectName("chromePathAutoDetectButton")
|
||||
self.chrome_path_widget = QWidget()
|
||||
self.chrome_path_widget.setObjectName("chromePathWidget")
|
||||
chrome_path_layout = QHBoxLayout(self.chrome_path_widget)
|
||||
@@ -172,6 +175,7 @@ class SettingsTab(QWidget):
|
||||
chrome_path_layout.setSpacing(8)
|
||||
chrome_path_layout.addWidget(self.chrome_path_edit, 1)
|
||||
chrome_path_layout.addWidget(self.chrome_path_browse_button)
|
||||
chrome_path_layout.addWidget(self.chrome_path_detect_button)
|
||||
self.user_data_root_edit = QLineEdit()
|
||||
self.user_data_root_edit.setObjectName("userDataRootEdit")
|
||||
self.user_data_root_edit.setEnabled(False)
|
||||
@@ -393,6 +397,7 @@ class SettingsTab(QWidget):
|
||||
self._update_response_timeout_label
|
||||
)
|
||||
self.chrome_path_browse_button.clicked.connect(self.browse_chrome_path)
|
||||
self.chrome_path_detect_button.clicked.connect(self.detect_chrome_path)
|
||||
self.save_config_button.clicked.connect(self.save_app_settings)
|
||||
self._connect_dirty_signals()
|
||||
|
||||
@@ -535,6 +540,17 @@ class SettingsTab(QWidget):
|
||||
return
|
||||
self.chrome_path_edit.setText(path)
|
||||
|
||||
def detect_chrome_path(self, checked=False):
|
||||
path = chrome.detect_chrome_path()
|
||||
if not path:
|
||||
self._set_status(
|
||||
"未找到 Chrome,请点『选择...』手动指定,或先安装 Chrome",
|
||||
level="warning",
|
||||
)
|
||||
return
|
||||
self.chrome_path_edit.setText(path)
|
||||
self._set_status(f"已自动定位 Chrome:{path}", level="success")
|
||||
|
||||
def discard_unsaved_changes(self):
|
||||
try:
|
||||
saved = appconfig.load_config(self.config_path)
|
||||
|
||||
Reference in New Issue
Block a user