From 51f4773e14e032f56ffe91bd4d21ba0322543e69 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Wed, 25 Feb 2026 10:48:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(bot):=20=E6=94=AF=E6=8C=81macOS=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=B5=8F=E8=A7=88=E5=99=A8=E6=A3=80=E6=B5=8B=20(#2107?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用platform模块替代os模块进行系统检测 - 添加macOS系统下的Chrome和Edge浏览器路径检测 - 改进日志信息为中文提示 - 优化跨平台浏览器通道选择逻辑 --- bot.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index 0075e569..abdff4de 100644 --- a/bot.py +++ b/bot.py @@ -1,11 +1,12 @@ import contextlib -import os +import platform import nonebot htmlrender_browser_channel = None +system = platform.system() -if os.name == "nt": +if system == "Windows": import winreg paths = { @@ -18,10 +19,22 @@ if os.name == "nt": htmlrender_browser_channel = name break - if htmlrender_browser_channel: - nonebot.logger.info( - f"Using {htmlrender_browser_channel} as htmlrender browser channel." - ) +elif system == "Darwin": # macOS + from pathlib import Path + + mac_paths = { + "chrome": "/Applications/Google Chrome.app", + "msedge": "/Applications/Microsoft Edge.app", + } + for name, path in mac_paths.items(): + if Path(path).exists(): + htmlrender_browser_channel = name + break + +if htmlrender_browser_channel: + nonebot.logger.info( + f"使用 {htmlrender_browser_channel} 作为 htmlrender 驱动启动..." + ) # from nonebot.adapters.discord import Adapter as DiscordAdapter