]> git.r.bdr.sh - rbdr/map/blame - Map/Presentation/Commands/UpdateCommands.swift
3.0.0
[rbdr/map] / Map / Presentation / Commands / UpdateCommands.swift
CommitLineData
4e7e11cf
RBR
1import SwiftUI
2import Sparkle
3
4struct UpdateCommands: Commands {
5 let updaterController: SPUStandardUpdaterController
6
7 var body: some Commands {
8 CommandGroup(after: .appInfo) {
9 CheckForUpdatesView(updater: updaterController.updater)
10 }
11 }
12}
13
14
15struct CheckForUpdatesView: View {
16 @ObservedObject private var checkForUpdatesViewModel: CheckForUpdatesViewModel
17 private let updater: SPUUpdater
18
19 init(updater: SPUUpdater) {
20 self.updater = updater
21
22 // Create our view model for our CheckForUpdatesView
23 self.checkForUpdatesViewModel = CheckForUpdatesViewModel(updater: updater)
24 }
25
26 var body: some View {
27 Button("Check for Updates…", action: updater.checkForUpdates)
28 .disabled(!checkForUpdatesViewModel.canCheckForUpdates)
29 }
30}
31
32final class CheckForUpdatesViewModel: ObservableObject {
33 @Published var canCheckForUpdates = false
34
35 init(updater: SPUUpdater) {
36 updater.publisher(for: \.canCheckForUpdates)
37 .assign(to: &$canCheckForUpdates)
38 }
39}