Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

Fix discard close flow

webadderall70c122cf423a
diff --git a/electron/main.ts b/electron/main.ts
index c8f5225c..64facd18 100644
--- a/electron/main.ts
+++ b/electron/main.ts
@@ -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)
}
})
}