included Sparkle

This commit is contained in:
Micha
2025-11-22 18:56:55 +01:00
parent db1f15f981
commit dc710d53aa
15 changed files with 579 additions and 28 deletions

View File

@@ -2,13 +2,14 @@ import SwiftUI
struct PreferencesView: View {
private enum Tab: CaseIterable {
case monitor, notifications, alerts
case monitor, notifications, alerts, updates
var title: String {
switch self {
case .monitor: return "Monitor"
case .notifications: return "Notifications"
case .alerts: return "Alerts"
case .updates: return "Updates"
}
}
@@ -17,13 +18,17 @@ struct PreferencesView: View {
case .monitor: return "waveform.path.ecg"
case .notifications: return "bell.badge"
case .alerts: return "exclamationmark.triangle"
case .updates: return "square.and.arrow.down"
}
}
}
@EnvironmentObject private var updateViewModel: UpdateViewModel
@AppStorage("pingInterval") private var storedPingInterval: Int = 10
@AppStorage("refreshInterval") private var storedRefreshInterval: Int = 60
@AppStorage("showIntervalIndicator") private var showIntervalIndicator: Bool = true
@AppStorage("autoCheckUpdates") private var autoCheckUpdates: Bool = true
@AppStorage("includePrereleaseUpdates") private var includePrereleaseUpdates: Bool = true
@State private var pingIntervalSlider: Double = 10
@State private var refreshIntervalSlider: Double = 60
@@ -77,14 +82,14 @@ struct PreferencesView: View {
.padding(.vertical, 8)
.padding(.horizontal, 10)
.frame(maxWidth: .infinity, alignment: .leading)
.background(
Capsule(style: .continuous)
.fill(backgroundColor(for: tab))
)
}
.buttonStyle(.plain)
.focusable(false)
.contentShape(Capsule())
.background(
Capsule(style: .continuous)
.fill(backgroundColor(for: tab))
)
.foregroundColor(selection == tab ? .white : .primary)
.onHover { isHovering in
hoveredTab = isHovering ? tab : (hoveredTab == tab ? nil : hoveredTab)
@@ -120,6 +125,12 @@ struct PreferencesView: View {
NotificationsPreferencesView()
case .alerts:
AlertsPreferencesView()
case .updates:
UpdatesPreferencesView(
autoCheckUpdates: $autoCheckUpdates,
includePrereleaseUpdates: $includePrereleaseUpdates
)
.environmentObject(updateViewModel)
}
}
}
@@ -220,6 +231,51 @@ private struct MonitorPreferencesView: View {
}
}
private struct UpdatesPreferencesView: View {
@Binding var autoCheckUpdates: Bool
@Binding var includePrereleaseUpdates: Bool
@EnvironmentObject var updateViewModel: UpdateViewModel
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Toggle("Automatically check for updates", isOn: $autoCheckUpdates)
.toggleStyle(.switch)
Toggle("Include pre-release builds", isOn: $includePrereleaseUpdates)
.toggleStyle(.switch)
HStack {
if updateViewModel.isChecking {
ProgressView()
.progressViewStyle(.circular)
Text("Checking for updates…")
.foregroundColor(.secondary)
} else {
Button("Check Now") {
updateViewModel.checkForUpdates(userInitiated: true)
}
}
}
if let release = updateViewModel.latestFetchedRelease {
VStack(alignment: .leading, spacing: 4) {
Text("Latest available: \(release.versionString)")
.font(.subheadline)
if release.prerelease {
Text("Pre-release build")
.font(.caption)
.foregroundColor(.secondary)
}
}
.padding(.top, 4)
}
Spacer()
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
private struct NotificationsPreferencesView: View {
var body: some View {
VStack(alignment: .leading, spacing: 12) {