From d8e32d39ff021749b0f837f7843a9322fc00a319 Mon Sep 17 00:00:00 2001
From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
Date: Thu, 30 Jun 2022 14:33:58 -0700
Subject: [PATCH] Don't save window stats after shutdown request

---
 app/main.ts         |  5 ++++-
 app/window_state.ts | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/app/main.ts b/app/main.ts
index ce1faa20d83..738de01c7dd 100644
--- a/app/main.ts
+++ b/app/main.ts
@@ -774,7 +774,9 @@ async function createWindow() {
     // so if we need to recreate the window, we have the most recent settings
     windowConfig = newWindowConfig;
 
-    debouncedSaveStats();
+    if (!windowState.requestedShutdown()) {
+      debouncedSaveStats();
+    }
   }
 
   mainWindow.on('resize', captureWindowStats);
@@ -856,6 +858,7 @@ async function createWindow() {
       return;
     }
 
+    windowState.markRequestedShutdown();
     await requestShutdown();
     windowState.markReadyForShutdown();
 
diff --git a/app/window_state.ts b/app/window_state.ts
index 1b88db5e120..e21417c15a0 100644
--- a/app/window_state.ts
+++ b/app/window_state.ts
@@ -20,3 +20,13 @@ export function markReadyForShutdown(): void {
 export function readyForShutdown(): boolean {
   return isReadyForShutdown;
 }
+
+let hasRequestedShutdown = false;
+
+export function markRequestedShutdown(): void {
+  hasRequestedShutdown = true;
+}
+
+export function requestedShutdown(): boolean {
+  return hasRequestedShutdown;
+}