Merge pull request #218 from RobotsAndPencils/SparkUpdate

Update Sparkle to 2.1
This commit is contained in:
Matt Kiazyk 2022-05-12 13:08:37 -05:00 committed by GitHub
commit 7440f5715d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 20 deletions

View file

@ -1415,8 +1415,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sparkle-project/Sparkle/";
requirement = {
kind = exactVersion;
version = "1.24.0-spm";
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

View file

@ -60,8 +60,8 @@
"repositoryURL": "https://github.com/sparkle-project/Sparkle/",
"state": {
"branch": null,
"revision": "891afd44c7075e699924ed9b81d8dc94a5111dfd",
"version": "1.24.0-spm"
"revision": "286edd1fa22505a9e54d170e9fd07d775ea233f2",
"version": "2.1.0"
}
},
{

View file

@ -5,6 +5,7 @@ struct PreferencesView: View {
case general, updates, advanced, experiment
}
@EnvironmentObject var appState: AppState
@EnvironmentObject var updater: ObservableUpdater
var body: some View {
TabView {
@ -15,6 +16,7 @@ struct PreferencesView: View {
}
.tag(Tabs.general)
UpdatesPreferencePane()
.environmentObject(updater)
.tabItem {
Label("Updates", systemImage: "arrow.triangle.2.circlepath.circle")
}

View file

@ -3,7 +3,7 @@ import Sparkle
import SwiftUI
struct UpdatesPreferencePane: View {
@StateObject var updater = ObservableUpdater()
@EnvironmentObject var updater: ObservableUpdater
@AppStorage("autoInstallation") var autoInstallationType: AutoInstallationType = .none
@ -41,7 +41,7 @@ struct UpdatesPreferencePane: View {
)
Button("CheckNow") {
SUUpdater.shared()?.checkForUpdates(nil)
updater.checkForUpdates()
}
Text(String(format: localizeString("LastChecked"), lastUpdatedString))
@ -69,9 +69,11 @@ struct UpdatesPreferencePane: View {
}
class ObservableUpdater: ObservableObject {
private let updater: SPUUpdater
@Published var automaticallyChecksForUpdates = false {
didSet {
SUUpdater.shared()?.automaticallyChecksForUpdates = automaticallyChecksForUpdates
updater.automaticallyChecksForUpdates = automaticallyChecksForUpdates
}
}
private var automaticallyChecksForUpdatesObservation: NSKeyValueObservation?
@ -82,15 +84,17 @@ class ObservableUpdater: ObservableObject {
UserDefaults.standard.setValue(includePrereleaseVersions, forKey: "includePrereleaseVersions")
if includePrereleaseVersions {
SUUpdater.shared()?.feedURL = .prereleaseAppcast
updater.setFeedURL(.prereleaseAppcast)
} else {
SUUpdater.shared()?.feedURL = .appcast
updater.setFeedURL(.appcast)
}
}
}
init() {
automaticallyChecksForUpdatesObservation = SUUpdater.shared()?.observe(
updater = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil).updater
automaticallyChecksForUpdatesObservation = updater.observe(
\.automaticallyChecksForUpdates,
options: [.initial, .new, .old],
changeHandler: { [unowned self] updater, change in
@ -98,7 +102,7 @@ class ObservableUpdater: ObservableObject {
self.automaticallyChecksForUpdates = updater.automaticallyChecksForUpdates
}
)
lastUpdateCheckDateObservation = SUUpdater.shared()?.observe(
lastUpdateCheckDateObservation = updater.observe(
\.lastUpdateCheckDate,
options: [.initial, .new, .old],
changeHandler: { [unowned self] updater, change in
@ -107,6 +111,10 @@ class ObservableUpdater: ObservableObject {
)
includePrereleaseVersions = UserDefaults.standard.bool(forKey: "includePrereleaseVersions")
}
func checkForUpdates() {
updater.checkForUpdates()
}
}
extension URL {

View file

@ -402,7 +402,7 @@ bspatch.c and bsdiff.c, from bsdiff 4.3 <http://www.daemonology.net/bsdiff/>:\
sais.c and sais.c, from sais-lite (2010/08/07) <https://sites.google.com/site/yuta256/sais>:\
Copyright (c) 2008-2010 Yuta Mori.\
\
SUDSAVerifier.m:\
SUSignatureVerifier.m:\
Copyright (c) 2011 Mark Hamlin.\
\
All rights reserved.\

View file

@ -8,11 +8,13 @@ struct XcodesApp: App {
@SwiftUI.Environment(\.scenePhase) private var scenePhase: ScenePhase
@SwiftUI.Environment(\.openURL) var openURL: OpenURLAction
@StateObject private var appState = AppState()
@StateObject private var updater = ObservableUpdater()
var body: some Scene {
WindowGroup("Xcodes") {
MainWindow()
.environmentObject(appState)
.environmentObject(updater)
// This is intentionally used on a View, and not on a WindowGroup,
// so that it's triggered when an individual window's phase changes instead of all window phases.
// When used on a View it's also invoked on launch, which doesn't occur with a WindowGroup.
@ -32,7 +34,7 @@ struct XcodesApp: App {
}
CommandGroup(after: .appInfo) {
Button("Menu.CheckForUpdates") {
appDelegate.checkForUpdates()
updater.checkForUpdates()
}
}
@ -69,6 +71,7 @@ struct XcodesApp: App {
Settings {
PreferencesView()
.environmentObject(appState)
.environmentObject(updater)
}
#endif
}
@ -112,13 +115,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
acknowledgementsWindow.makeKeyAndOrderFront(nil)
}
func checkForUpdates() {
SUUpdater.shared()?.checkForUpdates(self)
}
func applicationDidFinishLaunching(_ notification: Notification) {
// Initialize manually
SUUpdater.shared()
}
}