window_manager icon indicating copy to clipboard operation
window_manager copied to clipboard

[macOS] macOS does not properly understand windowManager.hide()

Open fdennis opened this issue 1 year ago • 4 comments

Issue If I try running the example code but remove the following lines:

diff --git a/example/lib/pages/home.dart b/example/lib/pages/home.dart
index 75c3c1e..e566590 100644
--- a/example/lib/pages/home.dart
+++ b/example/lib/pages/home.dart
@@ -185,8 +185,8 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
               onTap: () async {
                 await windowManager.hide();
                 await Future.delayed(const Duration(seconds: 2));
-                await windowManager.show();
-                await windowManager.focus();
               },
             ),
             PreferenceListItem(

the window stays hidden when pressing show/hide. I then do the following:

  1. press the show/hide button. The app is now hidden.
  2. right-click on the icon down in the dock on macOS. A menu will appear with several items.
  3. In the menu one of the options is to hide the app. However, the app is already hidden, because I pressed show/hide. I would expect to get the option to show the app. This means that macOS does not entirely understand what happens when we call hide().

Solution If I change to the following in WindowManager.swift

public func hide() {
        DispatchQueue.main.async {
            NSApp.hide(nil)
        }
    }

It seems to fix the problem. Now, when I press show/hide and the app is hidden, I get the option to show the app when right-clicking on the icon in the dock on macOS.

fdennis avatar Jan 22 '24 13:01 fdennis

Is there an update to this issue? Would be great to have this looked into.

fdennis avatar Aug 15 '24 08:08 fdennis

I also encountered the same issue, hoping for a targeted update.

HarryToo avatar Dec 24 '24 09:12 HarryToo

Just following up as I'm also facing this issue

rafaeljustinox avatar May 16 '25 13:05 rafaeljustinox

same issue, waiting merge.

daoye avatar Aug 06 '25 12:08 daoye