rastrillo / native Public

Clone
git clone https://amadan.net/rastrillo/native

Plain git — no account needed to clone.

Download

Download this file

1#if os(macOS)
2import SwiftUI
3
4/// Sparkle owns installation and its UI; apps retain their normal quit/save handling.
5public struct NativeUpdateCommands: Commands {
6 @Bindable private var updater: NativeUpdater
7
8 public init(updater: NativeUpdater) { self.updater = updater }
9
10 static let resources = Bundle.main.url(forResource: "RastrilloNative_RastrilloMacUpdates", withExtension: "bundle").flatMap(Bundle.init(url:)) ?? Bundle.module
11
12 static var appName: String {
13 let info = Bundle.main.localizedInfoDictionary ?? Bundle.main.infoDictionary ?? [:]
14 return (info["CFBundleDisplayName"] as? String) ?? (info["CFBundleName"] as? String) ?? ProcessInfo.processInfo.processName
15 }
16
17 public var body: some Commands {
18 CommandGroup(after: .appInfo) {
19 // A quiet updater's staged update, where a person looks for it. Disabled
20 // while busy: the restart would end whatever the app is busy with.
21 if case .ready = updater.pendingUpdate {
22 Button(action: updater.installPendingUpdate) {
23 Text("Update Ready — Restart \(Self.appName)", bundle: Self.resources)
24 }
25 .disabled(!updater.canInstallPendingUpdate)
26 }
27 Button(action: updater.checkForUpdates) { Text("Check for Updates…", bundle: Self.resources) }
28 .disabled(!updater.canCheckForUpdates)
29 Toggle(isOn: $updater.automaticallyChecksForUpdates) { Text("Automatically Check for Updates", bundle: Self.resources) }
30 .disabled(!updater.isConfigured)
31 }
32 }
33}
34#endif
35