]> git.r.bdr.sh - rbdr/map/blame - Map/Presentation/Commands/UpdateCommands.swift
Add license notices
[rbdr/map] / Map / Presentation / Commands / UpdateCommands.swift
CommitLineData
98f09799
RBR
1/*
2 Copyright (C) 2024 Rubén Beltrán del Río
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://map.tranquil.systems.
16 */
4e7e11cf
RBR
17import SwiftUI
18import Sparkle
19
20struct UpdateCommands: Commands {
21 let updaterController: SPUStandardUpdaterController
22
23 var body: some Commands {
24 CommandGroup(after: .appInfo) {
25 CheckForUpdatesView(updater: updaterController.updater)
26 }
27 }
28}
29
30
31struct CheckForUpdatesView: View {
32 @ObservedObject private var checkForUpdatesViewModel: CheckForUpdatesViewModel
33 private let updater: SPUUpdater
34
35 init(updater: SPUUpdater) {
36 self.updater = updater
37
38 // Create our view model for our CheckForUpdatesView
39 self.checkForUpdatesViewModel = CheckForUpdatesViewModel(updater: updater)
40 }
41
42 var body: some View {
43 Button("Check for Updates…", action: updater.checkForUpdates)
44 .disabled(!checkForUpdatesViewModel.canCheckForUpdates)
45 }
46}
47
48final class CheckForUpdatesViewModel: ObservableObject {
49 @Published var canCheckForUpdates = false
50
51 init(updater: SPUUpdater) {
52 updater.publisher(for: \.canCheckForUpdates)
53 .assign(to: &$canCheckForUpdates)
54 }
55}