Fix discard close flow

This commit is contained in:
webadderall
2026-03-13 21:14:05 +11:00
parent 579b29a5e9
commit ffc41d6d19
+21 -9
View File
@@ -50,6 +50,16 @@ let selectedSourceName = ''
let editorHasUnsavedChanges = false
let isForceClosing = false
function closeEditorWindowBypassingUnsavedPrompt(window: BrowserWindow | null) {
if (!window || window.isDestroyed()) {
return
}
isForceClosing = true
editorHasUnsavedChanges = false
window.close()
}
// Tray Icons
const defaultTrayIcon = getTrayIcon('app-icons/recordly-32.png');
const recordingTrayIcon = getTrayIcon('rec-button.png');
@@ -248,14 +258,20 @@ function updateTrayMenu(recording: boolean = false) {
function createEditorWindowWrapper() {
if (mainWindow) {
isForceClosing = true
mainWindow.close()
isForceClosing = false
closeEditorWindowBypassingUnsavedPrompt(mainWindow)
mainWindow = null
}
mainWindow = createEditorWindow()
editorHasUnsavedChanges = false
mainWindow.on('closed', () => {
if (mainWindow?.isDestroyed()) {
mainWindow = null
}
isForceClosing = false
editorHasUnsavedChanges = false
})
mainWindow.on('close', (event) => {
if (isForceClosing || !editorHasUnsavedChanges) {
return
@@ -276,14 +292,10 @@ function createEditorWindowWrapper() {
if (choice === 0) {
mainWindow!.webContents.send('request-save-before-close')
ipcMain.once('save-before-close-done', () => {
isForceClosing = true
mainWindow?.close()
isForceClosing = false
closeEditorWindowBypassingUnsavedPrompt(mainWindow)
})
} else if (choice === 1) {
isForceClosing = true
mainWindow?.close()
isForceClosing = false
closeEditorWindowBypassingUnsavedPrompt(mainWindow)
}
})
}