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

Add desktop systray quit menu item only if it's not already present #3875

Closed

Conversation

bzdtchk
Copy link
Contributor

@bzdtchk bzdtchk commented May 7, 2023

Description:

Add desktop systray quit menu item only if it's not already present

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

@bzdtchk bzdtchk force-pushed the feature/systray-quit-menu-item branch from c8d1d53 to bbb5ff0 Compare May 7, 2023 14:56
Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

Thanks this seems like a good idea, however let's not duplicate the method to use it in system tray. The quit item is, after all, appended to a Menu in both cases.

@@ -183,3 +178,25 @@ func catchTerm(d *gLDriver) {
break
}
}

func addMissingQuitForMenu(menu *fyne.Menu, d *gLDriver) {
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a duplicate of addMissingQuitForMainMenu but with the first parameter different.

Would it not make sense to call one from the other? The Menu is found in menus.Items[0] so it should be a simple call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well their item.Action anonymous function is different and addMissingQuitForMainMenu returns the MainMenu object. addMissingQuitForMenu is void.

I'm not really sure it's just a simple call, seems like a big difference to me and I'm not really sure it's possible to make these two methods work together. I might extract the first two if statements to separate private methods but that's about it I guess.

Or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know how, but I haven't managed to explain. The following diff seemed to work for me:

index f46945175..9d7624973 100644
--- a/internal/driver/glfw/menu.go
+++ b/internal/driver/glfw/menu.go
@@ -15,30 +15,6 @@ func buildMenuOverlay(menus *fyne.MainMenu, w *window) fyne.CanvasObject {
 }
 
 func addMissingQuitForMainMenu(menus *fyne.MainMenu, w *window) *fyne.MainMenu {
-       var lastItem *fyne.MenuItem
-       if len(menus.Items[0].Items) > 0 {
-               lastItem = menus.Items[0].Items[len(menus.Items[0].Items)-1]
-               if lastItem.Label == "Quit" {
-                       lastItem.IsQuit = true
-               }
-       }
-       if lastItem == nil || !lastItem.IsQuit { // make sure the first menu always has a quit option
-               quitItem := fyne.NewMenuItem("Quit", nil)
-               quitItem.IsQuit = true
-               menus.Items[0].Items = append(menus.Items[0].Items, fyne.NewMenuItemSeparator(), quitItem)
-       }
-       for _, item := range menus.Items[0].Items {
-               if item.IsQuit && item.Action == nil {
-                       item.Action = func() {
-                               for _, win := range w.driver.AllWindows() {
-                                       if glWin, ok := win.(*window); ok {
-                                               glWin.closed(glWin.view())
-                                       } else {
-                                               win.Close() // for test windows
-                                       }
-                               }
-                       }
-               }
-       }
+       addMissingQuitForMenu(menus.Items[0], w.driver)
        return menus
 }

Copy link
Member

Choose a reason for hiding this comment

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

However make sure that the full quit action is taken - the version you added is not as thorough as the one in the original main menu quit code...

@coveralls
Copy link

Coverage Status

Coverage: 62.019% (-0.03%) from 62.044% when pulling bbb5ff0 on bzdtchk:feature/systray-quit-menu-item into ec0d80e on fyne-io:develop.

@bzdtchk bzdtchk requested a review from andydotxyz May 9, 2023 20:11
Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

I'm not sure why another review was requested - the duplicate code I tried to help with is still present.

@Jacalz
Copy link
Member

Jacalz commented Jan 7, 2024

Thanks for the contribution. I'm sorry that this got left for such a long time but I will have to close this per the rule that stale PRs can be closed after 6 months. If you want to continue working on this, you are more than welcome to rebase on latest develop and reopen (or open a new one if that's easier).

@Jacalz Jacalz closed this Jan 7, 2024
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.

4 participants