Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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