mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-09-01 17:10:24 +08:00
The draw.io iframe registers a window.onbeforeunload handler that returns a non-empty string whenever its internal editor.modified flag is true. After the user edits text in a shape, that flag is set and never cleared. Per Electron BrowserWindow docs, returning a non-void value from any beforeunload handler in the page tree silently cancels the window close without showing a dialog. This is what caused the X button (and Cmd+Q) to do nothing for users who had typed in a shape. Calling event.preventDefault() in will-prevent-unload tells Electron to ignore the iframe's beforeunload return value and proceed with the close. The host app already persists diagrams via autosave + visibilitychange, so the prompt was unnecessary. Verified by reproducing the bug, applying the fix, and re-testing.
This commit is contained in:
@@ -60,6 +60,13 @@ export function createWindow(serverUrl: string): BrowserWindow {
|
||||
mainWindow.webContents.openDevTools()
|
||||
}
|
||||
|
||||
// Override the draw.io iframe's beforeunload handler so the window can
|
||||
// close after the user edits text in a shape (fixes #815). Diagrams are
|
||||
// already persisted via autosave, so the prompt is unnecessary.
|
||||
mainWindow.webContents.on("will-prevent-unload", (event) => {
|
||||
event.preventDefault()
|
||||
})
|
||||
|
||||
mainWindow.on("closed", () => {
|
||||
mainWindow = null
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user