Skip to content

Commit 51f4773

Browse files
authored
feat(bot): 支持macOS系统浏览器检测 (#2107)
- 使用platform模块替代os模块进行系统检测 - 添加macOS系统下的Chrome和Edge浏览器路径检测 - 改进日志信息为中文提示 - 优化跨平台浏览器通道选择逻辑
1 parent d9f8305 commit 51f4773

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

bot.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import contextlib
2-
import os
2+
import platform
33

44
import nonebot
55

66
htmlrender_browser_channel = None
7+
system = platform.system()
78

8-
if os.name == "nt":
9+
if system == "Windows":
910
import winreg
1011

1112
paths = {
@@ -18,10 +19,22 @@
1819
htmlrender_browser_channel = name
1920
break
2021

21-
if htmlrender_browser_channel:
22-
nonebot.logger.info(
23-
f"Using {htmlrender_browser_channel} as htmlrender browser channel."
24-
)
22+
elif system == "Darwin": # macOS
23+
from pathlib import Path
24+
25+
mac_paths = {
26+
"chrome": "/Applications/Google Chrome.app",
27+
"msedge": "/Applications/Microsoft Edge.app",
28+
}
29+
for name, path in mac_paths.items():
30+
if Path(path).exists():
31+
htmlrender_browser_channel = name
32+
break
33+
34+
if htmlrender_browser_channel:
35+
nonebot.logger.info(
36+
f"使用 {htmlrender_browser_channel} 作为 htmlrender 驱动启动..."
37+
)
2538

2639

2740
# from nonebot.adapters.discord import Adapter as DiscordAdapter

0 commit comments

Comments
 (0)