+import SwiftUI
+import Sparkle
+
+struct UpdateCommands: Commands {
+ let updaterController: SPUStandardUpdaterController
+
+ var body: some Commands {
+ CommandGroup(after: .appInfo) {
+ CheckForUpdatesView(updater: updaterController.updater)
+ }
+ }
+}
+
+
+struct CheckForUpdatesView: View {
+ @ObservedObject private var checkForUpdatesViewModel: CheckForUpdatesViewModel
+ private let updater: SPUUpdater
+
+ init(updater: SPUUpdater) {
+ self.updater = updater
+
+ // Create our view model for our CheckForUpdatesView
+ self.checkForUpdatesViewModel = CheckForUpdatesViewModel(updater: updater)
+ }
+
+ var body: some View {
+ Button("Check for Updates…", action: updater.checkForUpdates)
+ .disabled(!checkForUpdatesViewModel.canCheckForUpdates)
+ }
+}
+
+final class CheckForUpdatesViewModel: ObservableObject {
+ @Published var canCheckForUpdates = false
+
+ init(updater: SPUUpdater) {
+ updater.publisher(for: \.canCheckForUpdates)
+ .assign(to: &$canCheckForUpdates)
+ }
+}