fix(linux): fix main window not coming to front when clicked from tray (#12503)

When clicking the tray icon on Linux with another window on top,
the main window would not properly come to the front. This was due
to Linux window managers' focus stealing prevention.

The fix uses a hide/show sequence to simulate the "close to tray
and reopen" behavior which works correctly. This approach resets
the window state and makes the window manager treat it as a new
window activation request.

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
beyondkmp 2026-01-23 01:50:04 +08:00 committed by GitHub
parent 1f209dc280
commit 2cf38fcc41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -415,6 +415,23 @@ export class WindowService {
return
}
/**
* [Linux] Special handling for window activation
* When the window is visible but covered by other windows, simply calling show() and focus()
* is not enough to bring it to the front. We need to hide it first, then show it again.
* This mimics the "close to tray and reopen" behavior which works correctly.
*/
if (isLinux && this.mainWindow.isVisible() && !this.mainWindow.isFocused()) {
this.mainWindow.hide()
setImmediate(() => {
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.show()
this.mainWindow.focus()
}
})
return
}
/**
* About setVisibleOnAllWorkspaces
*