Skip to content

Instantly share code, notes, and snippets.

@davej
Created October 11, 2022 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davej/be1503e76acb237fc2ef513445d80b70 to your computer and use it in GitHub Desktop.
Save davej/be1503e76acb237fc2ef513445d80b70 to your computer and use it in GitHub Desktop.
Electron tray bounds bug on Mac
const { app, BrowserWindow, nativeImage, Tray } = require('electron')
let tray
function createTray() {
tray = new Tray(nativeImage.createEmpty())
// ❌ Doesn't work
console.log('sync', tray.getBounds())
setImmediate(() => {
// wait until the end of current queue to check bounds
// ❌ Doesn't work
console.log('setImmediate', tray.getBounds())
})
setTimeout(() => {
// wait 50ms to see if it's initialized later
// ❌ Doesn't work
console.log('setTimeout:50', tray.getBounds())
}, 50)
setTimeout(() => {
// wait 500ms to see if it's initialized later
// ✅ Works
console.log('setTimeout:500', tray.getBounds())
}, 500)
}
app.whenReady().then(() => {
createTray()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment