electron icon indicating copy to clipboard operation
electron copied to clipboard

[Bug]: `tray.getBounds()` initially returns the incorrect `x` and `y` values on macOS

Open davej opened this issue 3 years ago • 5 comments

Preflight Checklist

Electron Version

21.1.0

What operating system are you using?

macOS

Operating System Version

12.6 (Monterey)

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

tray.getBounds() should return current bounds when called shortly after the initialisation of the Tray. If this is not possible then the tray instance should emit a ready event so that we know when getBounds() will return the correct bounds.

Actual Behavior

tray.getBounds() returns an incorrect value until some arbitrary time has passed. In my testcase it takes approx 500ms for the correct value to be returned.

Testcase Gist URL

https://gist.github.com/davej/be1503e76acb237fc2ef513445d80b70

Additional Information

Output of my test case above. Only setTimeout:500 is correct.

Electron v21.1.0 started.
sync { x: 0, y: 956, width: 16, height: 36 }
setImmediate { x: 0, y: 956, width: 16, height: 36 }
setTimeout:50 { x: 0, y: 956, width: 16, height: 36 }
setTimeout:500 { x: 931, y: 0, width: 16, height: 36 }

This is probably the same bug as reported in #33515.

davej avatar Oct 11 '22 17:10 davej

Just to note: there's some additional details/investigation into the cause of this in #36031, which I closed as a duplicate of this issue.

clavin avatar Oct 14 '22 22:10 clavin

Looking forward to the fix

piotrpawlik avatar Dec 06 '22 13:12 piotrpawlik

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Mar 07 '23 02:03 github-actions[bot]

Still an issue.

davej avatar Mar 07 '23 10:03 davej

Facing same shit when trying to create window based on tray bounds instantly after creating tray

image

excal1bu7 avatar May 03 '23 10:05 excal1bu7

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

github-actions[bot] avatar Aug 02 '23 01:08 github-actions[bot]

bump

ScottSavarie avatar Sep 14 '23 00:09 ScottSavarie

@clavin Is there any update on this issue? I'm facing it too. Here's some information to help out with debugging:

Expected Behaviour: trayIcon.getBounds() should return the correct values for x, and y which are needed for me to set my window position correctly w.r.t. the tray icon.

Extended Context: I checked getting these bound values using setTimeout too. Even after 10 * 1000 (10 seconds) of delay, the values are incorrect.

System:

Electron Version: 26.2.1
OS: Mac OS
OS Version: Sonoma (14.0)
Arch: arm64 (Apple Silicon)

Values:

trayIcon.getBounds() = { x: 0, y: 900, width: 32, height: 24 }
mainWindow.getBounds() = { x: 520, y: 287, width: 400, height: 327 }
app.isPackaged = false

harshit-budhraja avatar Feb 20 '24 14:02 harshit-budhraja