Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onTrayMenuItemClick 事件失效 #53

Open
Muska-Ami opened this issue Sep 14, 2024 · 2 comments
Open

onTrayMenuItemClick 事件失效 #53

Muska-Ami opened this issue Sep 14, 2024 · 2 comments

Comments

@Muska-Ami
Copy link

Muska-Ami commented Sep 14, 2024

环境信息

  • OS: Windows 11 23H2 22631.4112
  • Flutter:
    [√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [版本 10.0.22631.4112], locale zh-CN)
    [√] Windows Version (Installed version of Windows is version 10 or higher)
    [√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    [X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
        ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
    [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.6)
    [√] Android Studio (version 2024.1)
    [√] IntelliJ IDEA Community Edition (version 2024.2)
    [√] Connected device (2 available)
    [√] Network resources
    

代码

初始化

class _AppState extends State<App> with WindowListener, TrayListener {
  /// 根组件
  @override
  Widget build(BuildContext context) {
    ThemeData themeData = ThemeControl().getTheme();

    final app = GetMaterialApp(
      // ...
    );
    _appInit = true;
    return app;
  }

  /// 组件初始化时操作
  @override
  void initState() {
    trayManager.addListener(this);
    windowManager.addListener(this);
    super.initState();
    _init();
  }

  /// 异步初始化内容
  Future<void> _init() async {
    await windowManager.setPreventClose(true);
    setState(() {});
  }

  /// 组件销毁时操作
  @override
  void dispose() {
    windowManager.removeListener(this);
    trayManager.removeListener(this);
    super.dispose();
  }

  // ...

  @override
  onTrayMenuItemClick(MenuItem menuItem) => MainTray.onTrayMenuItemClick(menuItem);
}

MainTray.onTrayMenuItemClick(MenuItem menuItem)

/// 托盘菜单点击事件
static void onTrayMenuItemClick(MenuItem menuItem) {
  // 这里的 Logger 没有任何输出,说明根本没有被触发
  Logger.info(menuItem.key);
  switch (menuItem.key) {
    case 'show_window':
      appWindow.show();
      break;
    case 'hide_window':
      appWindow.hide();
      break;
    case 'restore_window':
      appWindow.restore();
      break;
    case 'app_force_update':
      Get.forceAppUpdate();
      // appWindow.show();
      break;
    case 'exit_app':
      appWindow.show();
      MainWindow.onWindowClose();
      break;
  }
}
@CodeStar999
Copy link

同问,有什么解决办法?

@johannesvuorinen
Copy link

Indeed not working.

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

No branches or pull requests

3 participants