Skip to content

Commit 27d9c56

Browse files
committed
feat(dashboard): 添加自动打开浏览器功能
- 在配置文件中新增 auto_open_browser 选项,默认为 true。 - 在主应用程序中实现自动打开浏览器的功能,当 Dashboard 启动时,自动打开相应的 URL。 此功能提升了用户体验,方便用户快速访问 Dashboard。
1 parent b73c2c5 commit 27d9c56

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

config-template.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ port = 60214
369369
cors_origins = ["http://localhost:5173", "http://127.0.0.1:5173"]
370370
max_history_messages = 1000
371371
websocket_heartbeat = 30
372+
auto_open_browser = true
372373

373374
# ==================================================
374375
# 事件总线配置

main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""Amaidesu 应用程序主入口。"""
22

3+
import webbrowser
34
import argparse
45
import asyncio
56
import contextlib
67
import os
78
import signal
89
import sys
9-
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple
10+
from typing import Any, Dict, Optional, Tuple
1011

1112
from loguru import logger as loguru_logger
13+
from src.modules.dashboard.server import DashboardServer
1214
from src.modules.events import EventBus
1315
from src.modules.logging import get_logger
1416
from src.modules.registry import ProviderRegistry
@@ -444,6 +446,12 @@ async def create_app_components(
444446
)
445447
await dashboard_server.start()
446448
logger.info(f"Dashboard 已启动: http://{typed_dashboard_config.host}:{typed_dashboard_config.port}")
449+
450+
# 自动打开浏览器
451+
if typed_dashboard_config.auto_open_browser:
452+
dashboard_url = f"http://{typed_dashboard_config.host}:{typed_dashboard_config.port}"
453+
webbrowser.open(dashboard_url)
454+
logger.info(f"已自动打开浏览器: {dashboard_url}")
447455
except ImportError as e:
448456
logger.warning(f"Dashboard 模块导入失败(可能缺少依赖): {e}")
449457
logger.warning("Dashboard 功能将被禁用。请运行: uv add fastapi 'uvicorn[standard]'")

src/modules/dashboard/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ class DashboardConfig(BaseModel):
2121
)
2222
max_history_messages: int = Field(default=1000, description="内存中保留的最大历史消息数")
2323
websocket_heartbeat: int = Field(default=30, description="WebSocket 心跳间隔(秒)")
24+
auto_open_browser: bool = Field(default=True, description="启动时自动打开浏览器")

0 commit comments

Comments
 (0)