diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-09-16 12:10:02 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-09-16 12:10:02 +0200 |
| commit | 4e7e11cfd56adfa14a557c76e192ff3148cd2842 (patch) | |
| tree | f7e61dd1ec2ba76535b4650e6e5b960f337a88f0 /Map/Presentation/Commands/UpdateCommands.swift | |
| parent | 9acbbf34f8183ead1f2a12e60ecb919d5b3fec07 (diff) | |
3.0.03.0.0
Diffstat (limited to 'Map/Presentation/Commands/UpdateCommands.swift')
| -rw-r--r-- | Map/Presentation/Commands/UpdateCommands.swift | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Map/Presentation/Commands/UpdateCommands.swift b/Map/Presentation/Commands/UpdateCommands.swift new file mode 100644 index 0000000..44a4610 --- /dev/null +++ b/Map/Presentation/Commands/UpdateCommands.swift @@ -0,0 +1,39 @@ +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) + } +} |