mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 13:59:28 +08:00
fix(ipc): check mainWindow in ipc handler (#9712)
fix(ipc): 添加主窗口检查并修复窗口重置逻辑 在Windows_ResetMinimumSize处理中添加主窗口存在性检查 移除不必要的可选链操作符,确保窗口操作安全
This commit is contained in:
parent
2e5ffb8324
commit
16973fc034
@ -86,6 +86,12 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
|||||||
// Initialize Python service with main window
|
// Initialize Python service with main window
|
||||||
pythonService.setMainWindow(mainWindow)
|
pythonService.setMainWindow(mainWindow)
|
||||||
|
|
||||||
|
const checkMainWindow = () => {
|
||||||
|
if (!mainWindow || mainWindow.isDestroyed()) {
|
||||||
|
throw new Error('Main window does not exist or has been destroyed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ipcMain.handle(IpcChannel.App_Info, () => ({
|
ipcMain.handle(IpcChannel.App_Info, () => ({
|
||||||
version: app.getVersion(),
|
version: app.getVersion(),
|
||||||
isPackaged: app.isPackaged,
|
isPackaged: app.isPackaged,
|
||||||
@ -562,19 +568,23 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
|||||||
|
|
||||||
// window
|
// window
|
||||||
ipcMain.handle(IpcChannel.Windows_SetMinimumSize, (_, width: number, height: number) => {
|
ipcMain.handle(IpcChannel.Windows_SetMinimumSize, (_, width: number, height: number) => {
|
||||||
mainWindow?.setMinimumSize(width, height)
|
checkMainWindow()
|
||||||
|
mainWindow.setMinimumSize(width, height)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle(IpcChannel.Windows_ResetMinimumSize, () => {
|
ipcMain.handle(IpcChannel.Windows_ResetMinimumSize, () => {
|
||||||
mainWindow?.setMinimumSize(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
|
checkMainWindow()
|
||||||
const [width, height] = mainWindow?.getSize() ?? [MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT]
|
|
||||||
|
mainWindow.setMinimumSize(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
|
||||||
|
const [width, height] = mainWindow.getSize() ?? [MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT]
|
||||||
if (width < MIN_WINDOW_WIDTH) {
|
if (width < MIN_WINDOW_WIDTH) {
|
||||||
mainWindow?.setSize(MIN_WINDOW_WIDTH, height)
|
mainWindow.setSize(MIN_WINDOW_WIDTH, height)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle(IpcChannel.Windows_GetSize, () => {
|
ipcMain.handle(IpcChannel.Windows_GetSize, () => {
|
||||||
const [width, height] = mainWindow?.getSize() ?? [MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT]
|
checkMainWindow()
|
||||||
|
const [width, height] = mainWindow.getSize() ?? [MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT]
|
||||||
return [width, height]
|
return [width, height]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user