fix: close and recreate macOS windows safely

This commit is contained in:
鲨鱼辣椒 committed 2026-09-29 19:50:25 +08:00
1 parent f443f3bc66
commit b5e6c663ef
19 files changed
+1079 -172

No files matched your search

@@ -7,6 +7,7 @@ import {
shell,
type MenuItemConstructorOptions,
} from 'electron';
import { resolveMainWindow, type MainWindowProvider } from '../window-provider';
const MAX_LINK_LENGTH = 4_096;
const LOCAL_WEB_FILE_PATTERN = /\.(?:html?|xhtml)$/i;
@@ -117,7 +118,7 @@ export function createConversationLinkMenuTemplate(
throw new Error('Unsupported link context menu request');
}
export function registerConversationLinkContextMenuHandler(mainWindow: BrowserWindow): void {
export function registerConversationLinkContextMenuHandler(mainWindow: MainWindowProvider): void {
ipcMain.handle('shell:showLinkContextMenu', (event, request: ConversationLinkContextMenuRequest) => {
const template = createConversationLinkMenuTemplate(request, {
platform: process.platform,
@@ -128,7 +129,7 @@ export function registerConversationLinkContextMenuHandler(mainWindow: BrowserWi
writeText: (value) => clipboard.writeText(value),
});
const menu = Menu.buildFromTemplate(template);
const ownerWindow = BrowserWindow.fromWebContents(event.sender) ?? mainWindow;
menu.popup({ window: ownerWindow });
const ownerWindow = BrowserWindow.fromWebContents(event.sender) ?? resolveMainWindow(mainWindow);
menu.popup(ownerWindow ? { window: ownerWindow } : {});
});
}