included Sparkle
This commit is contained in:
@@ -12,6 +12,7 @@ struct MainView: View {
|
||||
private static let serverOrderKeyStatic = "serverOrder"
|
||||
private static let storedServersKeyStatic = "storedServers"
|
||||
|
||||
@EnvironmentObject private var updateViewModel: UpdateViewModel
|
||||
@State var showAddServerSheet: Bool = false
|
||||
@State private var serverBeingEdited: Server?
|
||||
@State private var serverToDelete: Server?
|
||||
@@ -30,9 +31,9 @@ struct MainView: View {
|
||||
@State private var selectedServerID: UUID?
|
||||
|
||||
var body: some View {
|
||||
|
||||
NavigationSplitView {
|
||||
List(selection: $selectedServerID) {
|
||||
var mainContent: some View {
|
||||
NavigationSplitView {
|
||||
List(selection: $selectedServerID) {
|
||||
ForEach(servers) { server in
|
||||
HStack {
|
||||
Image(systemName: "dot.circle.fill")
|
||||
@@ -61,6 +62,19 @@ struct MainView: View {
|
||||
}
|
||||
.help("Add Host")
|
||||
}
|
||||
ToolbarItem {
|
||||
Button {
|
||||
updateViewModel.checkForUpdates(userInitiated: true)
|
||||
} label: {
|
||||
if updateViewModel.isChecking {
|
||||
ProgressView()
|
||||
.scaleEffect(0.6)
|
||||
} else {
|
||||
Image(systemName: "square.and.arrow.down")
|
||||
}
|
||||
}
|
||||
.help("Check for Updates")
|
||||
}
|
||||
}
|
||||
.navigationTitle("Servers")
|
||||
.onChange(of: selectedServerID) {
|
||||
@@ -76,7 +90,9 @@ struct MainView: View {
|
||||
} else {
|
||||
ContentUnavailableView("No Server Selected", systemImage: "server.rack")
|
||||
}
|
||||
}
|
||||
}
|
||||
return mainContent
|
||||
.sheet(isPresented: $showAddServerSheet) {
|
||||
ServerFormView(
|
||||
mode: .add,
|
||||
@@ -128,9 +144,26 @@ struct MainView: View {
|
||||
pingTimer = Timer.scheduledTimer(withTimeInterval: 10.0, repeats: true) { _ in
|
||||
pingAllServers()
|
||||
}
|
||||
updateViewModel.startAutomaticCheckIfNeeded()
|
||||
}
|
||||
.frame(minWidth: 800, minHeight: 450)
|
||||
|
||||
.alert(item: availableReleaseBinding) { release in
|
||||
Alert(
|
||||
title: Text("Update Available"),
|
||||
message: Text("iKeyMon \(release.versionString) is available."),
|
||||
primaryButton: .default(Text("Download")) {
|
||||
updateViewModel.downloadLatest()
|
||||
},
|
||||
secondaryButton: .cancel(Text("Later"))
|
||||
)
|
||||
}
|
||||
.alert(item: statusAlertBinding) { alert in
|
||||
Alert(
|
||||
title: Text(alert.title),
|
||||
message: Text(alert.message),
|
||||
dismissButton: .default(Text("OK"))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchServerInfo(for id: UUID) {
|
||||
@@ -257,8 +290,23 @@ struct MainView: View {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
private var availableReleaseBinding: Binding<ReleaseInfo?> {
|
||||
Binding(
|
||||
get: { updateViewModel.availableRelease },
|
||||
set: { updateViewModel.availableRelease = $0 }
|
||||
)
|
||||
}
|
||||
|
||||
private var statusAlertBinding: Binding<UpdateViewModel.StatusAlert?> {
|
||||
Binding(
|
||||
get: { updateViewModel.statusAlert },
|
||||
set: { updateViewModel.statusAlert = $0 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
MainView()
|
||||
.environmentObject(UpdateViewModel())
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -59,10 +59,11 @@ struct GeneralView: View {
|
||||
var description = os.label.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if description.isEmpty {
|
||||
description = distro
|
||||
} else if !distro.isEmpty && distro.caseInsensitiveCompare(description) != .orderedSame {
|
||||
} else if !distro.isEmpty && description.range(of: distro, options: [.caseInsensitive]) == nil {
|
||||
description += " • \(distro)"
|
||||
}
|
||||
if !os.architecture.isEmpty {
|
||||
if !os.architecture.isEmpty &&
|
||||
description.range(of: os.architecture, options: [.caseInsensitive]) == nil {
|
||||
description += " (\(os.architecture))"
|
||||
}
|
||||
if !description.isEmpty {
|
||||
|
||||
Reference in New Issue
Block a user