Skip to content

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

Open
@fdennis

Description

@fdennis

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions