Check to see if the main window is loaded, in applicationShouldHandleReopen, which may be a work-around for a mysterious and (so far) unreproducible crash — #522.

This commit is contained in:
Brent Simmons 2019-01-27 20:25:09 -08:00
parent 7df22a2b6f
commit fdefaef66e
1 changed files with 11 additions and 2 deletions

View File

@ -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 couldnt 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 doesnt already exist because it absolutely *should* exist already.
// And if the window exists, then maybe the views and view controllers are also already loaded?
// Well 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)