Description
When close-to-tray is enabled, the main window's close event handler calls mainWindow.hide(). If the BrowserWindow has already been destroyed (e.g. triggered via windowControlsBridge.close()), this throws TypeError: Object has been destroyed.
Context
Sentry ELECTRON-ET — 7 occurrences on v1.8.32, fatal level error. The race condition occurs when the close event fires on a window that has been destroyed between the close() call and the event handler execution.
Fix
Add mainWindow.isDestroyed() guard at the top of the close handler to bail out early.