From 8236aef8ce2e01cc75073d271739ce5e1802485e Mon Sep 17 00:00:00 2001 From: Arjun Komath Date: Fri, 29 Dec 2023 19:26:31 +1100 Subject: [PATCH] mac UI fixes --- .../ServerList/Components/ServerListRow.swift | 8 +++--- .../Modules/ServerList/ServerListView.swift | 26 ++----------------- netdata/Modules/Settings/SettingsView.swift | 23 +++++++++++----- netdata/Modules/Shared/Charts/Meter.swift | 8 +++++- .../Shared/UI/BorderedBarButtonStyle.swift | 2 +- 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/netdata/Modules/ServerList/Components/ServerListRow.swift b/netdata/Modules/ServerList/Components/ServerListRow.swift index 60ab831..1ee868c 100644 --- a/netdata/Modules/ServerList/Components/ServerListRow.swift +++ b/netdata/Modules/ServerList/Components/ServerListRow.swift @@ -30,7 +30,7 @@ struct ServerListRow: View { Text(server.name) .lineLimit(1) - .font(.system(size: 20, weight: .semibold, design: .rounded)) + .font(.system(size: 20, weight: .medium, design: .rounded)) .foregroundColor(self.isOffline() ? .red : .primary) Spacer() @@ -46,10 +46,7 @@ struct ServerListRow: View { .frame(width: 12, height: 12, alignment: .leading) } -#if targetEnvironment(macCatalyst) -#else Image(systemName: "chevron.right") -#endif } Text(server.description) @@ -61,6 +58,9 @@ struct ServerListRow: View { .background(Color(UIColor.secondarySystemBackground)) .cornerRadius(10) } +#if targetEnvironment(macCatalyst) + .buttonStyle(.borderless) +#endif .task { if let alarms = await viewModel.fetchAlarms(server: server) { withAnimation { diff --git a/netdata/Modules/ServerList/ServerListView.swift b/netdata/Modules/ServerList/ServerListView.swift index 4841389..1fdf4be 100644 --- a/netdata/Modules/ServerList/ServerListView.swift +++ b/netdata/Modules/ServerList/ServerListView.swift @@ -18,29 +18,6 @@ struct ServerListView: View { var body: some View { GeometryReader { geometry in - #if targetEnvironment(macCatalyst) - List { - if !self.serverService.isCloudEnabled && !serverService.isSynching { - ErrorMessage(message: "iCloud not enabled, you need an iCloud account to view / add servers") - } - - if let error = self.serverService.mostRecentError { - ErrorMessage(message: error.localizedDescription) - } - - Section(header: Text("Favourites")) { - ForEach(serverService.favouriteServers, id: \.id) { server in - ServerListRow(server: server) - } - } - - Section(header: Text("All Servers")) { - ForEach(serverService.defaultServers, id: \.id) { server in - ServerListRow(server: server) - } - } - } - #else ScrollView { VStack(alignment: .leading) { RedactedView(loading: serverService.isSynching) { @@ -55,6 +32,7 @@ struct ServerListView: View { if serverService.favouriteServers.isEmpty == false { Label("Favourites", systemImage: "star.fill") .font(.headline) + .padding(.top, 16) LazyVGrid(columns: gridLayout(for: geometry.size.width), alignment: .leading, spacing: 8) { ForEach(serverService.favouriteServers, id: \.id) { server in ServerListRow(server: server) @@ -66,6 +44,7 @@ struct ServerListView: View { if serverService.defaultServers.isEmpty == false { Label("All Servers", systemImage: "folder.fill") .font(.headline) + .padding(.top, 8) LazyVGrid(columns: gridLayout(for: geometry.size.width), alignment: .leading, spacing: 8) { ForEach(serverService.defaultServers, id: \.id) { server in ServerListRow(server: server) @@ -77,7 +56,6 @@ struct ServerListView: View { } .padding(.horizontal, 16) } - #endif } .task { await serverService.refresh() diff --git a/netdata/Modules/Settings/SettingsView.swift b/netdata/Modules/Settings/SettingsView.swift index 1d79b58..2d39e7a 100644 --- a/netdata/Modules/Settings/SettingsView.swift +++ b/netdata/Modules/Settings/SettingsView.swift @@ -8,20 +8,22 @@ import SwiftUI import StoreKit import FirebaseAuth +import AlertToast struct SettingsView: View { @Environment(\.dismiss) var dismiss @Environment(\.requestReview) var requestReview - @Environment(\.scenePhase) private var scenePhase + @Environment(\.scenePhase) var scenePhase - @EnvironmentObject private var serverService: ServerService - @EnvironmentObject private var userService: UserService + @EnvironmentObject var serverService: ServerService + @EnvironmentObject var userService: UserService @ObservedObject var userSettings = UserSettings() @State private var showPushPermissionAlert = false @State private var hasPushPermission = false @State private var alertNotifications = false + @State private var showApiKeyCopiedToast = false private var versionNumber: String { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? NSLocalizedString("Error", comment: "") @@ -66,19 +68,18 @@ struct SettingsView: View { var body: some View { NavigationView { List { -#if targetEnvironment(macCatalyst) -#else Section(header: Text("Experience")) { ColorPicker(selection: $userSettings.appTintColor, supportsOpacity: false) { Label("App Tint", systemImage: "paintbrush") } - +#if targetEnvironment(macCatalyst) +#else Toggle(isOn: $userSettings.hapticFeedback) { Label("Haptic Feedback", systemImage: "waveform.path") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - } #endif + } if userService.userData != nil { Section(header: Text("Alert Notifications (beta)"), @@ -128,6 +129,7 @@ struct SettingsView: View { if alertNotifications { Button(action: { UIPasteboard.general.string = userService.userData?.api_key + showApiKeyCopiedToast = true }) { Label("Copy API key", systemImage: "doc.on.doc") .foregroundColor(.accentColor) @@ -197,6 +199,13 @@ struct SettingsView: View { dismissButton } } + .toast(isPresenting: $showApiKeyCopiedToast) { + AlertToast( + displayMode: .banner(.pop), + type: .complete(.green), + title: "API key copied to clipboard" + ) + } .alert(isPresented: $showPushPermissionAlert) { Alert(title: Text("Enable push notifications"), message: Text("You will receive instant push notifications for alerts from your Netdata instance."), diff --git a/netdata/Modules/Shared/Charts/Meter.swift b/netdata/Modules/Shared/Charts/Meter.swift index 0bb7f83..35a3e97 100644 --- a/netdata/Modules/Shared/Charts/Meter.swift +++ b/netdata/Modules/Shared/Charts/Meter.swift @@ -7,12 +7,18 @@ import SwiftUI +extension Comparable { + func clamped(to limits: ClosedRange) -> Self { + return min(max(self, limits.lowerBound), limits.upperBound) + } +} + struct Meter : View { var progress: CGFloat var body: some View { Gauge( - value: max(progress, 1), + value: progress.clamped(to: 0...1), in: 0...1 ) { Text("%") diff --git a/netdata/Modules/Shared/UI/BorderedBarButtonStyle.swift b/netdata/Modules/Shared/UI/BorderedBarButtonStyle.swift index 6e45ac3..79b67ee 100644 --- a/netdata/Modules/Shared/UI/BorderedBarButtonStyle.swift +++ b/netdata/Modules/Shared/UI/BorderedBarButtonStyle.swift @@ -22,7 +22,7 @@ public struct BorderedBarButtonStyle: ButtonStyle { #else configuration .label - .padding(10) + .padding(6) .foregroundColor(.accentColor) .background(RoundedRectangle(cornerRadius: 14, style: .continuous).foregroundColor(Color.accentColor.opacity(0.2))) #endif