]>
Commit | Line | Data |
---|---|---|
4e7e11cf RBR |
1 | import SwiftUI |
2 | import Sparkle | |
3 | ||
4 | struct 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 | ||
15 | struct 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 | ||
32 | final class CheckForUpdatesViewModel: ObservableObject { | |
33 | @Published var canCheckForUpdates = false | |
34 | ||
35 | init(updater: SPUUpdater) { | |
36 | updater.publisher(for: \.canCheckForUpdates) | |
37 | .assign(to: &$canCheckForUpdates) | |
38 | } | |
39 | } |