-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(linux): do not treat opening the tray menu as a click #6018
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
fan711
wants to merge
7
commits into
wailsapp:master
Choose a base branch
from
fan711:fix/linux-tray-menu-click
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−3
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0694625
fix(linux): do not treat opening the tray menu as a click
1184106
docs: changelog entry
c0ee57b
docs: reference the PR in the changelog entry
943bf07
Merge branch 'master' into fix/linux-tray-menu-click
leaanthony 54652d6
test(linux): cover tray menu-open vs click dispatch
abc8836
test(linux): assert tray events run only their own callback
05ee0da
Merge remote-tracking branch 'upstream/master' into fix/linux-tray-me…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| //go:build linux && !android && !server | ||
|
|
||
| package application | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/godbus/dbus/v5" | ||
| ) | ||
|
|
||
| // trayHandlerCounts records which of the SystemTray callbacks a dbusmenu | ||
| // event reached, so each assertion can pin the whole set rather than the one | ||
| // callback it is about — an event running a callback it should not is the | ||
| // failure mode here. | ||
| type trayHandlerCounts struct { | ||
| clicks, opens, closes int | ||
| } | ||
|
|
||
| // newCountingTray builds a tray with all three callbacks attached and an App | ||
| // with no logger installed: the dbusmenu callbacks log through | ||
| // globalApplication, which is nil in a test binary. | ||
| func newCountingTray(t *testing.T, counts *trayHandlerCounts) *linuxSystemTray { | ||
| t.Helper() | ||
|
|
||
| prev := globalApplication | ||
| globalApplication = &App{} | ||
| t.Cleanup(func() { globalApplication = prev }) | ||
|
|
||
| return &linuxSystemTray{parent: &SystemTray{ | ||
| clickHandler: func() { counts.clicks++ }, | ||
| onMenuOpen: func() { counts.opens++ }, | ||
| onMenuClose: func() { counts.closes++ }, | ||
| }} | ||
| } | ||
|
|
||
| func (c trayHandlerCounts) check(t *testing.T, after string, clicks, opens, closes int) { | ||
| t.Helper() | ||
| if c.clicks != clicks || c.opens != opens || c.closes != closes { | ||
| t.Errorf("after %s: click=%d onMenuOpen=%d onMenuClose=%d, want %d/%d/%d", | ||
| after, c.clicks, c.opens, c.closes, clicks, opens, closes) | ||
| } | ||
| } | ||
|
|
||
| // The dbusmenu "opened" event is the host announcing that it is about to show | ||
| // the context menu, which is the secondary button. Running the click handler | ||
| // here as well made every right-click do whatever a left-click does — on an | ||
| // app whose click handler toggles a window, right-clicking toggled it. | ||
| func TestLinuxSystemTrayMenuEventsDoNotClick(t *testing.T) { | ||
| var counts trayHandlerCounts | ||
| tray := newCountingTray(t, &counts) | ||
|
|
||
| if err := tray.Event(0, "opened", dbus.Variant{}, 0); err != nil { | ||
| t.Fatalf(`Event("opened") returned %v`, err) | ||
| } | ||
| counts.check(t, `Event("opened")`, 0, 1, 0) | ||
|
|
||
| if err := tray.Event(0, "closed", dbus.Variant{}, 0); err != nil { | ||
| t.Fatalf(`Event("closed") returned %v`, err) | ||
| } | ||
| counts.check(t, `Event("closed")`, 0, 1, 1) | ||
| } | ||
|
|
||
| // The counterpart: ItemIsMenu is published as false, so the primary button | ||
| // arrives as Activate, which is now the only path to the click handler. | ||
| func TestLinuxSystemTrayActivateClicks(t *testing.T) { | ||
| var counts trayHandlerCounts | ||
| tray := newCountingTray(t, &counts) | ||
|
|
||
| if err := tray.Activate(12, 34); err != nil { | ||
| t.Fatalf("Activate returned %v", err) | ||
| } | ||
| counts.check(t, "Activate", 1, 0, 0) | ||
|
|
||
| if tray.lastClickX != 12 || tray.lastClickY != 34 { | ||
| t.Errorf("Activate recorded (%d,%d), want (12,34)", tray.lastClickX, tray.lastClickY) | ||
| } | ||
| } | ||
|
|
||
| // A tray with no handlers attached must not panic on the same events. | ||
| func TestLinuxSystemTrayEventsWithoutHandlers(t *testing.T) { | ||
| prev := globalApplication | ||
| globalApplication = &App{} | ||
| t.Cleanup(func() { globalApplication = prev }) | ||
|
|
||
| tray := &linuxSystemTray{parent: &SystemTray{}} | ||
| for _, eventID := range []string{"opened", "closed"} { | ||
| if err := tray.Event(0, eventID, dbus.Variant{}, 0); err != nil { | ||
| t.Fatalf("Event(%q) returned %v", eventID, err) | ||
| } | ||
| } | ||
| if err := tray.Activate(0, 0); err != nil { | ||
| t.Fatalf("Activate returned %v", err) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 54652d6 —
v3/pkg/application/systemtray_linux_event_test.go, linux-tagged and sitting next to the existingsystemtray_linux_race_test.go.TestLinuxSystemTrayMenuEventsDoNotClickassertsEvent("opened")runsonMenuOpenand notclickHandler, andEvent("closed")runsonMenuCloseand notclickHandler.TestLinuxSystemTrayActivateClickscovers the other direction —Activateis the path a primary click actually arrives on, sinceItemIsMenuis published as false, so it must still runclickHandler(and record the click position).TestLinuxSystemTrayEventsWithoutHandlerschecks neither path panics with no handlers attached. Verified both ways: restoring theclickHandler()call in the"opened"case makes the first test fail, and the set passes with the fix in place.