Skip to content

Commit

Permalink
Merge pull request #52 from arjunkomath/main
Browse files Browse the repository at this point in the history
mac UI fixes
  • Loading branch information
arjunkomath authored Dec 29, 2023
2 parents 097d3af + 8236aef commit 767b005
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
8 changes: 4 additions & 4 deletions netdata/Modules/ServerList/Components/ServerListRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
26 changes: 2 additions & 24 deletions netdata/Modules/ServerList/ServerListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -77,7 +56,6 @@ struct ServerListView: View {
}
.padding(.horizontal, 16)
}
#endif
}
.task {
await serverService.refresh()
Expand Down
23 changes: 16 additions & 7 deletions netdata/Modules/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "")
Expand Down Expand Up @@ -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)"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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."),
Expand Down
8 changes: 7 additions & 1 deletion netdata/Modules/Shared/Charts/Meter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

import SwiftUI

extension Comparable {
func clamped(to limits: ClosedRange<Self>) -> 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("%")
Expand Down
2 changes: 1 addition & 1 deletion netdata/Modules/Shared/UI/BorderedBarButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 767b005

Please sign in to comment.