From 09a0757d96e3c9034ccc5230898b589e03a1f041 Mon Sep 17 00:00:00 2001 From: Francesco Compagnoni Date: Thu, 20 Feb 2020 01:44:53 +0000 Subject: [PATCH] Fix crash upon first launch --- kingsapp/Info.plist | 2 +- kingsapp/StatusMenuController.swift | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/kingsapp/Info.plist b/kingsapp/Info.plist index 05e21fa..a33c0a7 100644 --- a/kingsapp/Info.plist +++ b/kingsapp/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString 1.1.3 CFBundleVersion - 38 + 43 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) LSUIElement diff --git a/kingsapp/StatusMenuController.swift b/kingsapp/StatusMenuController.swift index db60154..4d860be 100644 --- a/kingsapp/StatusMenuController.swift +++ b/kingsapp/StatusMenuController.swift @@ -194,12 +194,10 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate { } func needsToCheckForUpdate() -> Bool { - // Don't load it from disk if it's cached - if self.lastUpdateCheck == nil { - self.lastUpdateCheck = dateFormatter.date(from: userDefaults.object(forKey: "lastUpdateCheck") as! String) - if lastUpdateCheck == nil { - return true - } + // Check when it was last updated + let lastUpdateString = userDefaults.object(forKey: "lastUpdateCheck") + if (lastUpdateString == nil) { + return true; } // Create threshold date @@ -208,7 +206,7 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate { var components = DateComponents() components.hour = -1 * hoursThreshold let thresholdDate = NSCalendar.current.date(byAdding: components, to: currentDate) - return !(self.lastUpdateCheck! > thresholdDate!) + return dateFormatter.date(from: lastUpdateString as! String)! < thresholdDate! } func loadCredentials() {