mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Add Sparkle update framework for macOS
This commit is contained in:
@@ -15,5 +15,11 @@
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>SUEnableInstallerLauncherService</key>
|
||||
<true/>
|
||||
<key>SUFeedURL</key>
|
||||
<string>https://repos.yattee.stream/appcast.xml</string>
|
||||
<key>SUPublicEDKey</key>
|
||||
<string>73U5at3utQRS7F/z/7nztpjp3l1gw1Ih+ztOelRLSx4=</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
10
macOS/Updates/CheckForUpdatesView.swift
Normal file
10
macOS/Updates/CheckForUpdatesView.swift
Normal file
@@ -0,0 +1,10 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CheckForUpdatesView: View {
|
||||
@EnvironmentObject<UpdaterModel> private var updater
|
||||
|
||||
var body: some View {
|
||||
Button("Check For Updates…", action: updater.checkForUpdates)
|
||||
.disabled(!updater.canCheckForUpdates)
|
||||
}
|
||||
}
|
41
macOS/Updates/UpdaterModel.swift
Normal file
41
macOS/Updates/UpdaterModel.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
import Defaults
|
||||
import Sparkle
|
||||
import SwiftUI
|
||||
|
||||
final class UpdaterModel: ObservableObject {
|
||||
@Published var canCheckForUpdates = false
|
||||
|
||||
private let updaterController: SPUStandardUpdaterController
|
||||
private let updaterDelegate = UpdaterDelegate()
|
||||
|
||||
init() {
|
||||
updaterController = SPUStandardUpdaterController(
|
||||
startingUpdater: true,
|
||||
updaterDelegate: updaterDelegate,
|
||||
userDriverDelegate: nil
|
||||
)
|
||||
|
||||
updaterController.updater.publisher(for: \.canCheckForUpdates)
|
||||
.assign(to: &$canCheckForUpdates)
|
||||
}
|
||||
|
||||
func checkForUpdates() {
|
||||
updaterController.checkForUpdates(nil)
|
||||
}
|
||||
|
||||
var automaticallyChecksForUpdates: Bool {
|
||||
updaterController.updater.automaticallyChecksForUpdates
|
||||
}
|
||||
|
||||
func setAutomaticallyChecksForUpdates(_ value: Bool) {
|
||||
updaterController.updater.automaticallyChecksForUpdates = value
|
||||
}
|
||||
}
|
||||
|
||||
final class UpdaterDelegate: NSObject, SPUUpdaterDelegate {
|
||||
@Default(.enableBetaChannel) private var enableBetaChannel
|
||||
|
||||
func allowedChannels(for _: SPUUpdater) -> Set<String> {
|
||||
Set(enableBetaChannel ? ["beta"] : [])
|
||||
}
|
||||
}
|
32
macOS/Updates/UpdatesSettings.swift
Normal file
32
macOS/Updates/UpdatesSettings.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct UpdatesSettings: View {
|
||||
@EnvironmentObject<UpdaterModel> private var updater
|
||||
|
||||
@State private var automaticallyChecksForUpdates = false
|
||||
@Default(.enableBetaChannel) private var enableBetaChannel
|
||||
|
||||
var body: some View {
|
||||
Section(header: SettingsHeader(text: "Updates")) {
|
||||
Toggle("Check automatically", isOn: $automaticallyChecksForUpdates)
|
||||
Toggle("Enable beta channel", isOn: $enableBetaChannel)
|
||||
}
|
||||
.onAppear {
|
||||
automaticallyChecksForUpdates = updater.automaticallyChecksForUpdates
|
||||
}
|
||||
.onChange(of: automaticallyChecksForUpdates) { _ in
|
||||
updater.setAutomaticallyChecksForUpdates(automaticallyChecksForUpdates)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
struct UpdatesSettings_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
UpdatesSettings()
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user