fix: Clicking the taskbar icon while enable the Quick Assistant can't open the main window

This commit is contained in:
ousugo 2025-02-18 14:01:46 +08:00 committed by 亢奋猫
parent 7c4d81c108
commit fb8ed35b59
2 changed files with 27 additions and 14 deletions

View File

@ -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'
@ -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()
@ -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) => {

View File

@ -28,6 +28,7 @@ export class WindowService {
public createMainWindow(): BrowserWindow {
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.show()
return this.mainWindow
}
@ -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()
}
}
@ -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()
}