From 53673ca3da98b3bdbf873daa9e167b4f1d7dece7 Mon Sep 17 00:00:00 2001 From: 0xzio Date: Sat, 9 Aug 2025 14:21:07 +0800 Subject: [PATCH] feat: improve app activate ux --- apps/electron/src/main/ElectronApp.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/electron/src/main/ElectronApp.ts b/apps/electron/src/main/ElectronApp.ts index d491d504..b3be1471 100644 --- a/apps/electron/src/main/ElectronApp.ts +++ b/apps/electron/src/main/ElectronApp.ts @@ -171,10 +171,14 @@ export class ElectronApp { this.panelWindow.on('blur', async () => { console.log('blur panel..........isDev:', is.dev) - const pinned = await this.conf.get('pinned') - if (!is.dev && !pinned) { - this.panelWindow.hide() - } + // Add a small delay to prevent immediate hiding when switching between windows + setTimeout(async () => { + const pinned = await this.conf.get('pinned') + // Only hide if the window is still not focused and not pinned + if (!is.dev && !pinned && !this.panelWindow.isFocused()) { + this.panelWindow.hide() + } + }, 100) // if (!pinned) { // this.panelWindow.hide() @@ -186,14 +190,14 @@ export class ElectronApp { app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. + // For PenX, we want to show the panel window when activated - if (!this.mainWindow) { - this.toggleMainWindow() + if (!this.panelWindow || this.panelWindow.isDestroyed()) { + this.windows.panelWindow = createPanelWindow() } - // if (BrowserWindow.getAllWindows().length === 0) { - // this.windows.mainWindow = createMainWindow() - // } + // Show and focus the panel window when app is activated + this.togglePanelWindow({ openOnly: true }) }) } catch (error) { console.error('Failed to initialize app:', error)