Created
October 11, 2022 17:21
-
-
Save davej/be1503e76acb237fc2ef513445d80b70 to your computer and use it in GitHub Desktop.
Electron tray bounds bug on Mac
This file contains 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
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