Merge pull request #1161 from danielpunkass/modernize-sparkle

Switch to SPUUpdater and establish our own single instance of this up…
This commit is contained in:
Maurice Parker 2019-10-22 19:35:00 -05:00 committed by GitHub
commit f0ecfa6150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 23 deletions

View File

@ -13,14 +13,21 @@ import RSTree
import RSWeb
import Account
import RSCore
#if 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 {
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, UNUserNotificationCenterDelegate, UnreadCountProvider, SPUStandardUserDriverDelegate, SPUUpdaterDelegate
{
var userNotificationManager: UserNotificationManager!
var faviconDownloader: FaviconDownloader!
@ -70,6 +77,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 +127,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)
@ -572,6 +590,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
AppDefaults.timelineGroupByFeed.toggle()
}
@IBAction func checkForUpdates(_ sender: Any?) {
#if !MAC_APP_STORE && !TEST
self.softwareUpdater.checkForUpdates()
#endif
}
}
// MARK: - Debug Menu

View File

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

View File

@ -234,17 +234,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="1hh-8U-B8b" name="value" keyPath="automaticallyChecksForUpdates" id="cge-fo-09y">
<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>
<binding destination="mV3-0T-XFc" name="value" keyPath="values.SUEnableAutomaticChecks" id="PwC-5l-EQR"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Q6M-Iz-Ypx">
@ -293,7 +283,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="checkForUpdates:" target="1hh-8U-B8b" id="RX4-6c-Osn"/>
<action selector="checkForUpdates:" target="VX1-M3-K0J" id="WVQ-XY-Czt"/>
</connections>
</button>
<textField horizontalHuggingPriority="1000" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="SUN-k3-ZEb">
@ -382,8 +372,8 @@
</connections>
</viewController>
<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="mV3-0T-XFc"/>
</objects>
<point key="canvasLocation" x="-29" y="455.5"/>
</scene>