Skip to content

[Windows] 1.9.3 启动即闪退:通知插件在禁用 Windows 推送通知服务的系统上未捕获异常导致 fail-fast 崩溃(相关 #1324) #1441

Description

@muchstarlight

以下是我使用AI的诊断结果,经AI修复,目前我本地的版本已可以正常使用

问题描述

Windows 上 Gopeed 1.9.3(最新版,含安装版与 portable 版)打开后约 0.5 秒即闪退,无任何窗口、无日志输出。与 #1324 症状一致。

环境

复现步骤

  1. 使用工具将 Windows 推送通知服务禁用(很多精简版/优化版系统默认如此):
    • WpnService(Windows Push Notifications System Service)
    • WpnUserService_*(Windows Push Notifications User Service,如 WpnUserService_964d1
  2. 启动 gopeed.exe → 立即闪退

根因分析

进程实际退出码为 -10737407910xC0000409 = STATUS_STACK_BUFFER_OVERRUN),即 MSVC 运行时的 fail-fast 崩溃(未处理 C++ 异常 → terminate → RaiseFailFastException)。

用 Process Monitor 抓取启动轨迹,崩溃前最后的操作序列是:

  1. 通知插件初始化:写入 HKCU\Software\Classes\AppUserModelId\com.gopeed.gopeed(DisplayName/IconUri/CustomActivator)、临时图标文件 notification_icon.ico
  2. 激活 WinRT Windows.UI.Notifications.ToastNotificationManager
  3. 读取 WPN 端点注册表 HKLM\SYSTEM\CurrentControlSet\Control\Notifications\...
  4. 随后进程 fail-fast 崩溃

对照插件源码(gopeed 使用 flutter_local_notifications 20.1.0,FFI 实现),崩溃点在这里:

flutter_local_notifications_windows/src/ffi_api.cpp:33-34

plugin->notifier = plugin->hasIdentity
  ? ToastNotificationManager::CreateToastNotifier()
  : ToastNotificationManager::CreateToastNotifier(plugin->aumid);

CreateToastNotifier() 没有 try/catch:当 WPN 服务(特别是用户级 WpnUserService)不可用时,WinRT 调用抛出的异常直接跨 FFI 边界,进程 fail-fast 崩溃,Dart 层无法捕获。

验证

  • 将 flutter_local_notifications_windows.dll 从安装目录改名/移除后,Gopeed 可正常启动运行(仅无通知功能,Dart 层会打印一条动态库加载失败的错误但不再崩溃)
  • 启用 WpnService + WpnUserService_* 并重新登录后,Gopeed 恢复正常

建议修复

ffi_api.cpp 中 init() 用 try/catch 包裹 CreateToastNotifier()(以及 ToastNotificationManager::History()),失败时返回 false,由 Dart 层降级处理而不是让整个进程崩溃:

  try {
    plugin->notifier = plugin->hasIdentity
      ? ToastNotificationManager::CreateToastNotifier()
      : ToastNotificationManager::CreateToastNotifier(plugin->aumid);
  } catch (winrt::hresult_error const& e) {
    // WPN 服务不可用时降级处理,不要崩溃
    return false;
  }

另外建议 gopeed 侧在 notification_service.dart 的 _initNotifications() 对 initialize() 加 try/catch,双保险。

相关

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions