From 471c8ce6672ba108c117774f08ba67e41b1126b7 Mon Sep 17 00:00:00 2001 From: Daniel Jalkut Date: Tue, 22 Oct 2019 19:33:00 -0400 Subject: [PATCH 1/2] Switch to SPUUpdater and establish our own single instance of this updater in the app delegate. If we're building for App Store or a TEST build, don't even initialize Sparkle. --- Mac/AppDelegate.swift | 33 ++++++++++++++++++++------- Mac/Base.lproj/Main.storyboard | 3 +-- Mac/Base.lproj/Preferences.storyboard | 16 +++---------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 117285763..9e4c8207e 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -13,14 +13,14 @@ import RSTree import RSWeb import Account import RSCore -#if TEST +#if !MAC_APP_STORE && !TEST import Sparkle #endif var appDelegate: AppDelegate! @NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider { +class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate { var userNotificationManager: UserNotificationManager! var faviconDownloader: FaviconDownloader! @@ -70,6 +70,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, private let log = Log() private let appNewsURLString = "https://nnw.ranchero.com/feed.json" private let appMovementMonitor = RSAppMovementMonitor() + #if !MAC_APP_STORE && !TEST + private var softwareUpdater: SPUUpdater! + #endif override init() { NSWindow.allowsAutomaticWindowTabbing = false @@ -117,16 +120,24 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, func applicationWillFinishLaunching(_ notification: Notification) { installAppleEventHandlers() - #if TEST - // Don't prompt for updates while running automated tests - SUUpdater.shared()?.automaticallyChecksForUpdates = false - #endif } func applicationDidFinishLaunching(_ note: Notification) { - #if MAC_APP_STORE + #if MAC_APP_STORE || TEST checkForUpdatesMenuItem.isHidden = true + #else + // Initialize Sparkle... + let hostBundle = Bundle.main + let updateDriver = SPUStandardUserDriver(hostBundle: hostBundle, delegate: self) + self.softwareUpdater = SPUUpdater(hostBundle: hostBundle, applicationBundle: hostBundle, userDriver: updateDriver, delegate: self) + + do { + try self.softwareUpdater.start() + } + catch { + NSLog("Failed to start software updater with error: \(error)") + } #endif appName = (Bundle.main.infoDictionary!["CFBundleExecutable"]! as! String) @@ -571,7 +582,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, @IBAction func groupByFeedToggled(_ sender: NSMenuItem) { AppDefaults.timelineGroupByFeed.toggle() } - + + @IBAction func checkForUpdates(_ sender: Any?) { + #if !MAC_APP_STORE && !TEST + self.softwareUpdater.checkForUpdates() + #endif + } + } // MARK: - Debug Menu diff --git a/Mac/Base.lproj/Main.storyboard b/Mac/Base.lproj/Main.storyboard index 498fdd35f..ba4a9a4de 100644 --- a/Mac/Base.lproj/Main.storyboard +++ b/Mac/Base.lproj/Main.storyboard @@ -30,7 +30,7 @@ - + @@ -623,7 +623,6 @@ - diff --git a/Mac/Base.lproj/Preferences.storyboard b/Mac/Base.lproj/Preferences.storyboard index 46d049133..6b2ac07d5 100644 --- a/Mac/Base.lproj/Preferences.storyboard +++ b/Mac/Base.lproj/Preferences.storyboard @@ -234,17 +234,7 @@ - - - - - - - - - - - + @@ -293,7 +283,7 @@ - + @@ -382,8 +372,8 @@ - + From 8e37881ed875f4461d88f44bd2f6912b62ab5862 Mon Sep 17 00:00:00 2001 From: Daniel Jalkut Date: Tue, 22 Oct 2019 19:44:06 -0400 Subject: [PATCH 2/2] Protect against unrecognized protocol errors when building for MAC_APP_STORE or TEST. --- Mac/AppDelegate.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 9e4c8207e..52eedd75e 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -13,14 +13,21 @@ import RSTree import RSWeb import Account import RSCore -#if !MAC_APP_STORE && !TEST + +// If we're not going to import Sparkle, provide dummy protocols to make it easy +// for AppDelegate to comply +#if MAC_APP_STORE || TEST +protocol SPUStandardUserDriverDelegate {} +protocol SPUUpdaterDelegate {} +#else import Sparkle #endif var appDelegate: AppDelegate! @NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate { +class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate +{ var userNotificationManager: UserNotificationManager! var faviconDownloader: FaviconDownloader!