Skip to content

App crashes when calling windowManager.hide() with hotkey_manager #543

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

Open
dancamdev opened this issue Apr 5, 2025 · 2 comments
Open

Comments

@dancamdev
Copy link

Description

The app crashes when attempting to hide the window using windowManager.hide() after registering a system-wide hotkey with hotkey_manager. The crash occurs specifically when toggling the window visibility with Cmd+T.

Code Snippet

import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
import 'package:hotkey_manager/hotkey_manager.dart';

final showAndFocusWindowHotKey = HotKey(
  key: PhysicalKeyboardKey.keyT,
  modifiers: [HotKeyModifier.meta],
  scope: HotKeyScope.system,
);

class AppShortcuts extends StatefulWidget {
  const AppShortcuts({super.key, required this.child});
  final Widget child;

  @override
  State<AppShortcuts> createState() => _AppShortcutsState();
}

class _AppShortcutsState extends State<AppShortcuts> {
  @override
  void initState() {
    super.initState();
    hotKeyManager.register(
      showAndFocusWindowHotKey,
      keyDownHandler: (hotKey) async {
        if (!await windowManager.isVisible()) {
          print('show and focus window');
          windowManager.show();
          windowManager.focus();
        } else {
          print('hide window');
          windowManager.blur();
          await windowManager.hide(); // Crash occurs here
        }
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }
}

Steps to Reproduce

  1. Run the app
  2. Press Cmd+T to show the window
  3. Press Cmd+T again to hide the window
  4. App crashes when attempting to hide

Expected Behavior

The window should toggle visibility smoothly when pressing Cmd+T, showing when hidden and hiding when visible.

Actual Behavior

The app crashes when attempting to hide the window.

Environment

  • Flutter SDK: ^3.7.2
  • window_manager: ^0.4.3
  • hotkey_manager: ^0.2.3
  • Platform: macOS

Additional Notes

The crash seems to be related to the interaction between hotkey_manager and window_manager when attempting to hide the window. The show and focus operations work correctly, but the hide operation causes the app to crash.

@lingxuan0520
Copy link

When I used the two libraries, window_manager and hotkey_manager together, I also encountered the same problem that the program would directly close when I called the hide method.

@lingxuan0520
Copy link

Refer to this, but haven't merged into the main branch yet.
af74247

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

2 participants