Skip to content

fix: Windows 启动问题#98

Merged
Detritalw merged 60 commits intoWindowsfrom
moreOS
Feb 16, 2026
Merged

fix: Windows 启动问题#98
Detritalw merged 60 commits intoWindowsfrom
moreOS

Conversation

@Detritalw
Copy link
Member

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Detritalw, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求主要旨在解决 Windows 启动问题,并显著提升 Bloret Launcher 在 Windows、macOS 和 Linux 平台上的跨平台兼容性和稳定性。通过统一数据路径管理、优化进程启动参数、改进日志处理、增强 UI 响应性以及适配不同操作系统的特性,确保了启动器在各种环境下都能提供更流畅、更可靠的用户体验。

Highlights

  • 跨平台兼容性增强: 统一使用 BLglobals.datapath 管理数据路径,并为 Windows 特有模块(如 win32comwin32gui)添加了平台判断,确保程序在 Windows、macOS 和 Linux 上行为一致。
  • Minecraft 启动优化: 优化了 Minecraft 启动参数,特别是为 macOS 增加了 -XstartOnFirstThread 参数,并改进了 subprocess.Popen 调用,以适应不同操作系统的进程管理,同时将 stderr 重定向到 stdout 以避免管道阻塞。
  • 游戏日志处理改进: 改进了游戏日志处理,通过节流机制限制 UI 更新频率,防止日志过多导致 UI 卡顿,并优化了日志写入性能。
  • 资源路径管理: 引入了 get_resource_path 函数,以确保在脚本运行和 PyInstaller 打包环境下资源路径的正确性,解决了图标和 UI 文件加载问题。
  • 单实例运行锁: 实现了跨平台单实例运行锁,防止程序重复启动,提高了用户体验。
  • 主题和 UI 适配: 更新了主题应用逻辑,支持深色/浅色模式,并为 macOS 标题栏进行了适配,同时将 Modrinth Modpack 导入的文件选择器从 tkinter 迁移到 QFileDialog
  • 错误报告和工具栏异步化: 重构了错误报告和工具栏创建机制,采用异步信号/槽模式,提升了 UI 响应性,即使在后台线程发生异常也能在主线程显示错误。
  • 依赖管理和删除机制: 为 send2trash 模块添加了导入保护和回退机制,确保在未安装该模块时也能正常删除文件,并更新了 requirements.txt 以反映平台特定依赖。
Changelog
  • Bloret-Launcher.py
    • Added get_resource_path function for PyInstaller compatibility.
    • Removed check_write_permission import.
    • Updated open_BBBS_link import to use modules.links alias.
    • Used get_resource_path for loading icons and UI files.
    • Modified game launch subprocess.Popen to redirect stderr to stdout and throttle UI updates.
    • Adjusted game exit error handling to use the last output line.
    • Refined theme application logic for dark/light mode and added macOS title bar adaptation.
    • Implemented cross-platform single instance lock using fcntl for Linux/macOS.
    • Updated default minecraft_dir and log_folder paths to use BLglobals.datapath.
    • Added new links (Bloret PassPort, BIMG WEB) to the system tray menu.
    • Adjusted application restart logic for non-Windows platforms.
  • modules/BLServer.py
    • Conditionalized win32com.client.Dispatch import with sys.platform == "win32".
    • Added platform check for create_shortcut function.
    • Updated desktop path to use os.path.expanduser('~').
    • Added checks for BLtips and BL_Activity before assigning values from API response.
  • modules/ShortCut.py
    • Conditionalized win32gui, win32con, win32api imports with sys.platform == "win32".
    • Added platform checks to update_hover_window and capture_window_at_point functions.
  • modules/config.py
    • Updated config_path to use BLglobals.datapath for cross-platform compatibility.
  • modules/global_hotkey.py
    • Conditionalized ctypes.wintypes and user32/kernel32 imports with sys.platform == "win32".
    • Added platform check to init_global_hotkeys to only enable on Windows.
  • modules/globals.py
    • Defined datapath based on sys.platform (Windows: APPDATA, macOS: ~/Library/Application Support, Linux: ~/.local/share).
    • Initialized BLtips and BL_Activity with default values.
  • modules/install.py
    • Added send2trash import guard and fallback.
    • Updated default MaxThread value from 2000 to 64.
    • Updated default minecraft_dir to use BLglobals.datapath.
    • Used QMetaObject.invokeMethod for thread-safe closing of download dialogs.
  • modules/java.py
    • Updated extract_dir for Java runtime to use BLglobals.datapath.
  • modules/launch.py
    • Added send2trash import guard.
    • Guarded win32gui, win32con, win32process imports with sys.platform == "Windows".
    • Updated default minecraft_dir to use BLglobals.datapath.
    • Added default Java paths for macOS and Linux.
    • Removed manual quoting for java_arg in subprocess.Popen calls.
    • Added -XstartOnFirstThread argument for macOS.
    • Added --add-modules=jdk.unsupported and removed --add-opens java.base/sun.misc.
    • Removed -Doolloo.jlw.tmpdir from main launch arguments.
    • Removed manual quoting from native library paths.
    • Refined JavaWrapper.jar usage to be Windows-specific and non-Fabric.
    • Used os.pathsep for classpath separator.
    • Updated fabric.addMods argument format.
    • Improved get_minecraft_window_handle to find process PID on non-Windows systems.
    • Added platform check for floating toolbar functionality.
  • modules/links.py
    • Standardized BBS link.
    • Added open_PassPort_link and open_BIMG_WEB_link functions.
  • modules/log.py
    • Updated log folder path to use BLglobals.datapath.
    • Optimized log function for high-frequency game output by directly writing to file stream.
    • Removed explicit flush calls for handlers.
  • modules/modrinth.py
    • Removed tkinter related imports.
    • Replaced filedialog.askopenfilename with QFileDialog.getOpenFileName for Modrinth modpack import.
    • Used platform-specific executable name (mrpack-install.exe or mrpack-install) for subprocess.Popen.
  • modules/mwtool.py
    • Conditionalized win32gui, win32con, win32api, win32process imports with sys.platform == "win32".
    • Added platform checks to MonitorThread.run, MinecraftWindowToolManager.show_tool, and MinecraftWindowTool.ensure_visible.
    • Refactored show_tool to use asynchronous signal/slot for creating the tool manager, removing synchronous waiting.
    • Removed _tool_manager_ready event.
    • Updated ToolManagerFactory to include a show_signal for asynchronous tool display.
  • modules/plugin.py
    • Updated plugin_dir to use BLglobals.datapath.
  • modules/safe.py
    • Added QThread, QObject, pyqtSignal imports.
    • Refactored handle_exception to use a QObject signal (ErrorSignaler) to ensure error UI is displayed on the main thread, even if the exception occurs in a background thread.
    • Introduced _show_error_ui function for the actual UI display logic.
  • modules/setup_ui.py
    • Expanded Java path scanning to include common macOS and Linux Java installation directories.
    • Updated default minecraft_dir to use BLglobals.datapath.
    • Added safety checks for BLglobals.BLtips and BLglobals.BL_Activity to prevent errors if they are empty.
  • modules/systems.py
    • Conditionalized ctypes.wintypes, ctypes, win32com.client.Dispatch imports with sys.platform == "win32".
    • Added platform checks to get_system_theme_color (defaulting to blue for non-Windows) and is_dark_theme (including macOS defaults command).
    • Removed check_write_permission function.
    • Added platform checks to restart, add_to_startup, and remove_from_startup functions.
  • modules/versions.py
    • Added global variables import.
    • Implemented send2trash fallback to shutil.rmtree or os.remove.
    • Replaced os.startfile with QDesktopServices.openUrl for opening folders.
    • Updated default MaxThread value from 2000 to 64.
  • requirements.txt
    • Added platform-specific markers for Windows-only dependencies (win11toast, pywin32, winsdk).
Ignored Files
  • Ignored by pattern: .github/workflows/** (2)
    • .github/workflows/Nuitka-Build.yml
    • .github/workflows/build.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Detritalw and others added 2 commits February 16, 2026 14:00
…ensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

你好!感谢你的贡献。这次的 Pull Request 质量非常高,进行了一系列出色的重构,极大地提升了应用的跨平台兼容性、性能和稳定性。特别是在以下几个方面做得很好:

  1. 跨平台兼容性: 通过使用 sys.platform 判断和平台特定的实现,成功地将应用适配到了 macOS 和 Linux,例如数据目录、单例锁、进程启动方式等。
  2. 性能优化: 对日志系统进行了深度优化,通过直接写入流的方式处理高频游戏日志,有效避免了 UI 卡顿。
  3. 线程安全: 在多处使用了 QMetaObject.invokeMethod 来确保在主线程中更新 UI,解决了多线程编程中常见的崩溃风险,这是一个非常关键的修复。
  4. 代码健壮性: 增加了许多防御性编程实践,如检查 dict.get() 的返回值、使用可选依赖等。

我发现了一些小问题,主要集中在一个硬编码路径和异常处理上,修复后代码会更加完美。请查看具体的审查评论。

I am having trouble creating individual review comments. Click here to see my feedback.

modules/mwtool.py (331-334)

critical

这里使用了硬编码的本地绝对路径 r"g:\Work\git\Bloret-Launcher\Bloret.png" 来加载图标。这个路径在其他用户的电脑上将不存在,会导致图标加载失败,甚至可能引发程序异常。

建议使用 get_resource_path 函数来获取资源的正确路径,就像在 Bloret-Launcher.py 中处理 bloret.ico 一样。你可能需要先从主模块导入 get_resource_path 函数,或者将其移动到一个公共的工具模块中。

modules/mwtool.py (378)

critical

这里使用了硬编码的本地绝对路径 r"g:\Work\git\Bloret-Launcher\Bloret.png" 来加载图标。这个路径在其他用户的电脑上将不存在,会导致图标加载失败。

建议使用 get_resource_path 函数来获取资源的正确路径,以确保在打包后和不同环境下都能正确找到文件。

                    icon_path = get_resource_path("Bloret.png")

modules/mwtool.py (410)

critical

这里使用了硬编码的本地绝对路径 r"g:\Work\git\Bloret-Launcher\Bloret.png" 来加载图标。这个路径在其他用户的电脑上将不存在,会导致图标加载失败。

建议使用 get_resource_path 函数来获取资源的正确路径,以确保在打包后和不同环境下都能正确找到文件。

        icon_path = get_resource_path("Bloret.png")

modules/launch.py (472-475)

medium

捕获所有异常的 except: 语句通常是不好的做法,因为它会隐藏所有错误,包括程序应该退出的 SystemExitKeyboardInterrupt。这使得调试变得困难。

建议捕获更具体的异常,例如 OSErrorPermissionError,这两种是 os.makedirs 最可能抛出的异常,并记录错误日志。

        try:
            os.makedirs(temp_dir, exist_ok=True)
        except (OSError, PermissionError) as e:
            log(f"创建临时目录失败: {e}", logging.WARNING)

modules/log.py (12)

medium

这里有一行重复的注释 # 创建日志文件夹。建议删除其中一行以保持代码整洁。

@Detritalw Detritalw merged commit a192e38 into Windows Feb 16, 2026
10 checks passed
@Detritalw Detritalw deleted the moreOS branch February 16, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant