mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-08 04:38:45 +02:00
fix: tray icon click opens main window reliably after quick prompt use
showAndFocusWindow() used BrowserWindow.getAllWindows()[0] to find the main window, which breaks once the quick prompt window is created — the array order is not guaranteed and windows[0] may resolve to the quick prompt instead, causing the show/focus calls to target a hidden, frameless window. Accept the main window reference as an explicit parameter and guard against destroyed windows with isDestroyed(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+4
-4
@@ -63,9 +63,9 @@ async function bootstrap(): Promise<void> {
|
|||||||
applyTitleBarTheme(mainWindow, workspace.settings.theme);
|
applyTitleBarTheme(mainWindow, workspace.settings.theme);
|
||||||
|
|
||||||
systemTray = new SystemTray({
|
systemTray = new SystemTray({
|
||||||
onShowWindow: showAndFocusWindow,
|
onShowWindow: () => showAndFocusWindow(mainWindow!),
|
||||||
onCreateScratchpad: () => {
|
onCreateScratchpad: () => {
|
||||||
showAndFocusWindow();
|
showAndFocusWindow(mainWindow!);
|
||||||
mainWindow?.webContents.send('tray:create-scratchpad');
|
mainWindow?.webContents.send('tray:create-scratchpad');
|
||||||
},
|
},
|
||||||
onQuit: () => app.quit(),
|
onQuit: () => app.quit(),
|
||||||
@@ -127,8 +127,8 @@ app.on('window-all-closed', () => {
|
|||||||
app.on('activate', async () => {
|
app.on('activate', async () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
await bootstrap();
|
await bootstrap();
|
||||||
} else {
|
} else if (mainWindow && !mainWindow.isDestroyed()) {
|
||||||
showAndFocusWindow();
|
showAndFocusWindow(mainWindow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { join } from 'node:path';
|
|||||||
|
|
||||||
import type { WorkspaceState } from '@shared/domain/workspace';
|
import type { WorkspaceState } from '@shared/domain/workspace';
|
||||||
|
|
||||||
const { app, Menu, Tray, nativeImage, BrowserWindow } = electron;
|
const { app, Menu, Tray, nativeImage } = electron;
|
||||||
type TrayType = InstanceType<typeof Tray>;
|
type TrayType = InstanceType<typeof Tray>;
|
||||||
type NativeImageType = ReturnType<typeof nativeImage.createFromPath>;
|
type NativeImageType = ReturnType<typeof nativeImage.createFromPath>;
|
||||||
|
|
||||||
@@ -123,10 +123,8 @@ export function setupCloseToTray(
|
|||||||
/**
|
/**
|
||||||
* Show and focus the main window, restoring from tray if hidden.
|
* Show and focus the main window, restoring from tray if hidden.
|
||||||
*/
|
*/
|
||||||
export function showAndFocusWindow(): void {
|
export function showAndFocusWindow(mainWindow: Electron.BrowserWindow): void {
|
||||||
const windows = BrowserWindow.getAllWindows();
|
if (mainWindow.isDestroyed()) return;
|
||||||
const mainWindow = windows[0];
|
|
||||||
if (!mainWindow) return;
|
|
||||||
|
|
||||||
// On macOS, show the dock icon again
|
// On macOS, show the dock icon again
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
|||||||
Reference in New Issue
Block a user