From fdefaef66ebbe61efa833841ecef983e00e7366a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 27 Jan 2019 20:25:09 -0800 Subject: [PATCH] =?UTF-8?q?Check=20to=20see=20if=20the=20main=20window=20i?= =?UTF-8?q?s=20loaded,=20in=20applicationShouldHandleReopen,=20which=20may?= =?UTF-8?q?=20be=20a=20work-around=20for=20a=20mysterious=20and=20(so=20fa?= =?UTF-8?q?r)=20unreproducible=20crash=20=E2=80=94=C2=A0#522.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NetNewsWire/AppDelegate.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/NetNewsWire/AppDelegate.swift b/NetNewsWire/AppDelegate.swift index a4425b9ce..6c0cc7300 100644 --- a/NetNewsWire/AppDelegate.swift +++ b/NetNewsWire/AppDelegate.swift @@ -195,7 +195,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, } func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { - createAndShowMainWindow() + // https://github.com/brentsimmons/NetNewsWire/issues/522 + // I couldn’t reproduce the crashing bug, but it appears to happen on creating a main window + // and its views and view controllers. The check below is so that the app does nothing + // if the window doesn’t already exist — because it absolutely *should* exist already. + // And if the window exists, then maybe the views and view controllers are also already loaded? + // We’ll try this, and then see if we get more crash logs like this or not. + guard let mainWindowController = mainWindowController, mainWindowController.isWindowLoaded else { + return false + } + mainWindowController.showWindow(self) return false } @@ -334,7 +343,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, if let currentNextFireDate = refreshTimer?.fireDate, currentNextFireDate == nextRefreshTime { return } - + invalidateRefreshTimer() let timer = Timer(fireAt: nextRefreshTime, interval: 0, target: self, selector: #selector(timedRefresh(_:)), userInfo: nil, repeats: false) RunLoop.main.add(timer, forMode: .common)