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.

This commit is contained in:
Daniel Jalkut 2019-10-22 19:33:00 -04:00
parent e80a5f92bb
commit 471c8ce667
3 changed files with 29 additions and 23 deletions

View File

@ -13,14 +13,14 @@ import RSTree
import RSWeb import RSWeb
import Account import Account
import RSCore import RSCore
#if TEST #if !MAC_APP_STORE && !TEST
import Sparkle import Sparkle
#endif #endif
var appDelegate: AppDelegate! var appDelegate: AppDelegate!
@NSApplicationMain @NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider { class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate {
var userNotificationManager: UserNotificationManager! var userNotificationManager: UserNotificationManager!
var faviconDownloader: FaviconDownloader! var faviconDownloader: FaviconDownloader!
@ -70,6 +70,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
private let log = Log() private let log = Log()
private let appNewsURLString = "https://nnw.ranchero.com/feed.json" private let appNewsURLString = "https://nnw.ranchero.com/feed.json"
private let appMovementMonitor = RSAppMovementMonitor() private let appMovementMonitor = RSAppMovementMonitor()
#if !MAC_APP_STORE && !TEST
private var softwareUpdater: SPUUpdater!
#endif
override init() { override init() {
NSWindow.allowsAutomaticWindowTabbing = false NSWindow.allowsAutomaticWindowTabbing = false
@ -117,16 +120,24 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
func applicationWillFinishLaunching(_ notification: Notification) { func applicationWillFinishLaunching(_ notification: Notification) {
installAppleEventHandlers() installAppleEventHandlers()
#if TEST
// Don't prompt for updates while running automated tests
SUUpdater.shared()?.automaticallyChecksForUpdates = false
#endif
} }
func applicationDidFinishLaunching(_ note: Notification) { func applicationDidFinishLaunching(_ note: Notification) {
#if MAC_APP_STORE #if MAC_APP_STORE || TEST
checkForUpdatesMenuItem.isHidden = true 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 #endif
appName = (Bundle.main.infoDictionary!["CFBundleExecutable"]! as! String) appName = (Bundle.main.infoDictionary!["CFBundleExecutable"]! as! String)
@ -571,7 +582,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
@IBAction func groupByFeedToggled(_ sender: NSMenuItem) { @IBAction func groupByFeedToggled(_ sender: NSMenuItem) {
AppDefaults.timelineGroupByFeed.toggle() AppDefaults.timelineGroupByFeed.toggle()
} }
@IBAction func checkForUpdates(_ sender: Any?) {
#if !MAC_APP_STORE && !TEST
self.softwareUpdater.checkForUpdates()
#endif
}
} }
// MARK: - Debug Menu // MARK: - Debug Menu

View File

@ -30,7 +30,7 @@
<menuItem title="Check for Updates…" id="1nF-7O-aKU"> <menuItem title="Check for Updates…" id="1nF-7O-aKU">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="checkForUpdates:" target="5Wg-Cw-OOw" id="vV0-oc-v5a"/> <action selector="checkForUpdates:" target="Ady-hI-5gd" id="htt-e3-mEy"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/> <menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
@ -623,7 +623,6 @@
</menuItem> </menuItem>
</items> </items>
</menu> </menu>
<customObject id="5Wg-Cw-OOw" customClass="SUUpdater"/>
</objects> </objects>
<point key="canvasLocation" x="-54" y="-144"/> <point key="canvasLocation" x="-54" y="-144"/>
</scene> </scene>

View File

@ -234,17 +234,7 @@
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
<connections> <connections>
<binding destination="1hh-8U-B8b" name="value" keyPath="automaticallyChecksForUpdates" id="cge-fo-09y"> <binding destination="mV3-0T-XFc" name="value" keyPath="values.SUEnableAutomaticChecks" id="PwC-5l-EQR"/>
<dictionary key="options">
<bool key="NSAllowsEditingMultipleValuesSelection" value="NO"/>
<bool key="NSConditionallySetsEnabled" value="NO"/>
<integer key="NSMultipleValuesPlaceholder" value="0"/>
<integer key="NSNoSelectionPlaceholder" value="0"/>
<integer key="NSNotApplicablePlaceholder" value="0"/>
<integer key="NSNullPlaceholder" value="0"/>
<bool key="NSRaisesForNotApplicableKeys" value="NO"/>
</dictionary>
</binding>
</connections> </connections>
</button> </button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Q6M-Iz-Ypx"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Q6M-Iz-Ypx">
@ -293,7 +283,7 @@
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>
<connections> <connections>
<action selector="checkForUpdates:" target="1hh-8U-B8b" id="RX4-6c-Osn"/> <action selector="checkForUpdates:" target="VX1-M3-K0J" id="WVQ-XY-Czt"/>
</connections> </connections>
</button> </button>
<textField horizontalHuggingPriority="1000" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="SUN-k3-ZEb"> <textField horizontalHuggingPriority="1000" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="SUN-k3-ZEb">
@ -382,8 +372,8 @@
</connections> </connections>
</viewController> </viewController>
<customObject id="VX1-M3-K0J" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> <customObject id="VX1-M3-K0J" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<customObject id="1hh-8U-B8b" customClass="SUUpdater"/>
<userDefaultsController id="Y8q-yi-F5Z"/> <userDefaultsController id="Y8q-yi-F5Z"/>
<userDefaultsController id="mV3-0T-XFc"/>
</objects> </objects>
<point key="canvasLocation" x="-29" y="455.5"/> <point key="canvasLocation" x="-29" y="455.5"/>
</scene> </scene>