Skip to content

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

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
fdennis opened this issue Jan 22, 2024 · 2 comments · May be fixed by #530
Open

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

fdennis opened this issue Jan 22, 2024 · 2 comments · May be fixed by #530

Comments

@fdennis
Copy link

fdennis commented Jan 22, 2024

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
Copy link
Author

fdennis commented Aug 15, 2024

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

@HarryToo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants