Browse Source

fix: emit window-all-closed after closing the window (#28912)

Co-authored-by: Jeremy Rose <[email protected]>
trop[bot] 4 years ago
parent
commit
698fc73c23
2 changed files with 15 additions and 2 deletions
  1. 2 2
      shell/browser/native_window.cc
  2. 13 0
      spec-main/api-app-spec.ts

+ 2 - 2
shell/browser/native_window.cc

@@ -419,11 +419,11 @@ void NativeWindow::NotifyWindowClosed() {
   if (is_closed_)
     return;
 
-  WindowList::RemoveWindow(this);
-
   is_closed_ = true;
   for (NativeWindowObserver& observer : observers_)
     observer.OnWindowClosed();
+
+  WindowList::RemoveWindow(this);
 }
 
 void NativeWindow::NotifyWindowEndSession() {

+ 13 - 0
spec-main/api-app-spec.ts

@@ -1716,6 +1716,8 @@ describe('default behavior', () => {
   });
 
   describe('window-all-closed', () => {
+    afterEach(closeAllWindows);
+
     it('quits when the app does not handle the event', async () => {
       const result = await runTestApp('window-all-closed');
       expect(result).to.equal(false);
@@ -1725,6 +1727,17 @@ describe('default behavior', () => {
       const result = await runTestApp('window-all-closed', '--handle-event');
       expect(result).to.equal(true);
     });
+
+    it('should omit closed windows from getAllWindows', async () => {
+      const w = new BrowserWindow({ show: false });
+      const len = new Promise(resolve => {
+        app.on('window-all-closed', () => {
+          resolve(BrowserWindow.getAllWindows().length);
+        });
+      });
+      w.close();
+      expect(await len).to.equal(0);
+    });
   });
 
   describe('user agent fallback', () => {