Skip to content

Commit

Permalink
fix: Clicking the taskbar icon while enable the Quick Assistant can't…
Browse files Browse the repository at this point in the history
… open the main window
  • Loading branch information
ousugo authored and kangfenmao committed Feb 18, 2025
1 parent 7c4d81c commit fb8ed35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
14 changes: 4 additions & 10 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { electronApp, optimizer } from '@electron-toolkit/utils'
import { app, BrowserWindow } from 'electron'
import { app } from 'electron'
import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer'

import { registerIpc } from './ipc'
Expand Down Expand Up @@ -46,9 +46,8 @@ if (!app.requestSingleInstanceLock()) {
new TrayService()

app.on('activate', function () {
// 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.
if (BrowserWindow.getAllWindows().length === 0) {
const mainWindow = windowService.getMainWindow()
if (!mainWindow || mainWindow.isDestroyed()) {
windowService.createMainWindow()
} else {
windowService.showMainWindow()
Expand All @@ -68,12 +67,7 @@ if (!app.requestSingleInstanceLock()) {

// Listen for second instance
app.on('second-instance', () => {
const mainWindow = BrowserWindow.getAllWindows()[0]
if (mainWindow) {
mainWindow.isMinimized() && mainWindow.restore()
mainWindow.show()
mainWindow.focus()
}
windowService.showMainWindow()
})

app.on('browser-window-created', (_, window) => {
Expand Down
27 changes: 23 additions & 4 deletions src/main/services/WindowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class WindowService {

public createMainWindow(): BrowserWindow {
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.show()
return this.mainWindow
}

Expand Down Expand Up @@ -248,17 +249,32 @@ export class WindowService {
event.preventDefault()
mainWindow.hide()
})

mainWindow.on('closed', () => {
this.mainWindow = null
})

mainWindow.on('show', () => {
if (this.miniWindow && !this.miniWindow.isDestroyed()) {
this.miniWindow.hide()
}
})
}

public showMainWindow() {
if (this.mainWindow) {
if (this.miniWindow && !this.miniWindow.isDestroyed()) {
this.miniWindow.hide()
}

if (this.mainWindow && !this.mainWindow.isDestroyed()) {
if (this.mainWindow.isMinimized()) {
return this.mainWindow.restore()
this.mainWindow.restore()
}
this.mainWindow.show()
this.mainWindow.focus()
} else {
this.createMainWindow()
this.mainWindow = this.createMainWindow()
this.mainWindow.focus()
}
}

Expand All @@ -269,7 +285,10 @@ export class WindowService {
return
}

if (this.selectionMenuWindow) {
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.hide()
}
if (this.selectionMenuWindow && !this.selectionMenuWindow.isDestroyed()) {
this.selectionMenuWindow.hide()
}

Expand Down

0 comments on commit fb8ed35

Please sign in to comment.