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

call windowManager.show() and windowManager.restore() together as an extension #3671

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

levkropp
Copy link
Contributor

resolve #3667

windowManager.restore() calls gtk_window_deiconify as well as gtk_window_present https://docs.gtk.org/gtk3/method.Window.deiconify.html

In my testing, this has made it so "Open in Multipass" for an instance either

  • opens the Multipass window (if keyboard focus is not stolen), or
  • shows the " is ready" dialog if typing focus is on another app

100% of the time, and fixes the issues seen from #3667 without needing to fork the flutter window_manager plugin

Copy link
Contributor

@andrei-toterman andrei-toterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that you found this method, @levkropp! But there are multiple places where we call show, and I think those might need to be replaced by restore as well :)

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.85%. Comparing base (d2d4a82) to head (418162b).
Report is 119 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3671      +/-   ##
==========================================
- Coverage   88.85%   88.85%   -0.01%     
==========================================
  Files         254      254              
  Lines       14261    14269       +8     
==========================================
+ Hits        12672    12679       +7     
- Misses       1589     1590       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@levkropp levkropp force-pushed the window-manager-fork-tray-icon-behavior branch from c4dcfd1 to f9d76ac Compare September 12, 2024 15:24
@levkropp
Copy link
Contributor Author

there are multiple places where we call show, and I think those might need to be replaced by restore as well :)

Good catch @andrei-toterman , thank you! I have replaced the other occurrence of show() in tray_menu for the "Toggle Window" button with restore() as well

The only other instance of windowManager.show() I see is in main.dart in the waitUntilReadyToShow method, but I don't believe this should be replaced since we're not in a minimized state at this point, and there is no need to have a call to deiconify

@andrei-toterman
Copy link
Contributor

@levkropp check main.dart again ;)

@levkropp levkropp force-pushed the window-manager-fork-tray-icon-behavior branch from f9d76ac to 1724626 Compare September 13, 2024 14:02
Copy link
Contributor

@andrei-toterman andrei-toterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, replacing show with restore breaks things on Windows, since the window no longer appears at all after being hidden. Looking at the window_manager source code, it seems that the Windows implementation of restore does not call some of the functions called by show. So there are several options. We could call show and restore together all the time. We could fork the plugin and make it do what we need in one function call. Or we could introduce a platform-specific method that calls the appropriate window_manager methods when needed i.e. show for Windows and restore for the rest. Opinions, @levkropp and @ricab?

@ricab
Copy link
Collaborator

ricab commented Sep 16, 2024

Do you foresee any issues with just calling show + restore? Would it perhaps make things slow? If not, I guess that would be an easy fix. Otherwise, if we find that there is something wrong with the window_manager implementation that should be fixed, I would say fork+upstream. If it is not something wrong overall but just a specific need of ours, perhaps a platform method.

@andrei-toterman
Copy link
Contributor

No, I don't think there would be any issues with calling both all the time, and that would indeed be an easy fix. Just wanted to hear other opinions :)

@levkropp levkropp force-pushed the window-manager-fork-tray-icon-behavior branch from 1724626 to 99b27ab Compare September 16, 2024 13:24
@levkropp levkropp changed the title replace windowManager.show() with windowManager.restore() call windowManager.restore() before windowManager.show() Sep 16, 2024
Copy link
Contributor

@andrei-toterman andrei-toterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levkropp I think we first need show and then restore. On Windows, restore has no effect until show is called (which might not be a problem, but better safe than sorry). Also, you could group those two method calls into a single function, so you don't have to actually call them together all the time.
You could look into creating an extension method for the WindowManager class called showAndRestore or something like that. Make sure the method is async and awaits both show and restore ;)
You can place that extension in the tray menu file, since that's the most relevant place I can think of...

@levkropp
Copy link
Contributor Author

You can place that extension in the tray menu file, since that's the most relevant place I can think of...

Thank you for the feedback @andrei-toterman ! I like the idea of making an extension for window_manager to handle this as well

If we place the extension in the tray_menu file then I believe we'll have to import tray_menu.dart to access it if we want to use it for goToPrimary in main.dart

We could make a new .dart file to hold the extension, or perhaps not import the extension at all for the main.dart case since goToPrimary is the only place where restore() is needed

@andrei-toterman
Copy link
Contributor

@levkropp we already import tray_menu.dart into main.dart since that's where we call setupTrayMenu which creates the tray menu itself, so that would not be an issue. But now that I look again, we have an extensions.dart file where there are various other extensions that couldn't find a better place. If you put it there, then we'd have to import that into main.dart, but that is also perfectly ok. Take your pick!

@levkropp levkropp force-pushed the window-manager-fork-tray-icon-behavior branch from 99b27ab to 5a93cd1 Compare September 16, 2024 15:27
@levkropp levkropp changed the title call windowManager.restore() before windowManager.show() call windowManager.show() and windowManager.restore() together as an extension Sep 16, 2024
Comment on lines 58 to 65
callback: (_, __) async => await windowManager.isVisible()
? windowManager.hide()
: windowManager.show(),
callback: (_, __) async => await windowManager.showAndRestore(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this change? 'Toggle window' is supposed to hide the window if it's visible and show it if it's not.

@levkropp levkropp force-pushed the window-manager-fork-tray-icon-behavior branch from 5a93cd1 to 418162b Compare September 17, 2024 13:09
@andrei-toterman andrei-toterman added this pull request to the merge queue Sep 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 17, 2024
@andrei-toterman andrei-toterman added this pull request to the merge queue Sep 17, 2024
Merged via the queue into main with commit 5f4dfe2 Sep 17, 2024
13 of 14 checks passed
@andrei-toterman andrei-toterman deleted the window-manager-fork-tray-icon-behavior branch September 17, 2024 17:17
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

Successfully merging this pull request may close these issues.

[GUI] Tray icon doesn't bring the window up if minimized or hidden behind another window
3 participants