aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/Trackers
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-11-07 16:16:00 -0800
committerDustin Mierau <dustin@mierau.me>2025-11-07 16:16:00 -0800
commite1566598c96601ebcf3229aab22fc7a593ee1904 (patch)
tree4486a58aad0df5df17ebcca0209d48dcfa3d6a5e /Hotline/macOS/Trackers
parenta55318fa8d643160900bec3e6b14e7404c63497a (diff)
Further UI tweraks. Transfers button in toolbar. Better empty states in places. Fix race condition with transactions ids (yikes)!
Diffstat (limited to 'Hotline/macOS/Trackers')
-rw-r--r--Hotline/macOS/Trackers/TrackerBookmarkServerView.swift38
-rw-r--r--Hotline/macOS/Trackers/TrackerBookmarkSheet.swift119
-rw-r--r--Hotline/macOS/Trackers/TrackerItemView.swift73
3 files changed, 230 insertions, 0 deletions
diff --git a/Hotline/macOS/Trackers/TrackerBookmarkServerView.swift b/Hotline/macOS/Trackers/TrackerBookmarkServerView.swift
new file mode 100644
index 0000000..dc42ea9
--- /dev/null
+++ b/Hotline/macOS/Trackers/TrackerBookmarkServerView.swift
@@ -0,0 +1,38 @@
+struct TrackerBookmarkServerView: View {
+ let server: BookmarkServer
+
+ var body: some View {
+ HStack(alignment: .center, spacing: 6) {
+ Image("Server")
+ .resizable()
+ .scaledToFit()
+ .frame(width: 16, height: 16, alignment: .center)
+ Text(self.server.name ?? "Server").lineLimit(1).truncationMode(.tail)
+ if let serverDescription = self.server.description {
+ Text(serverDescription)
+ .foregroundStyle(.secondary)
+ .lineLimit(1)
+ .truncationMode(.tail)
+ }
+ Spacer(minLength: 0)
+ if self.server.users > 0 {
+ Text(String(self.server.users))
+ .foregroundStyle(.secondary)
+ .lineLimit(1)
+
+ Circle()
+ .fill(.fileComplete)
+ .frame(width: 7, height: 7)
+ .keyframeAnimator(initialValue: 1.0, repeating: true) { content, opacity in
+ content.opacity(opacity)
+ } keyframes: { _ in
+ CubicKeyframe(1.0, duration: 2.0) // Stay visible for 1 second
+ CubicKeyframe(0.6, duration: 0.5) // Fade out quickly
+ CubicKeyframe(1.0, duration: 0.5) // Fade in quickly
+ }
+ .padding(.trailing, 6)
+ }
+ }
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+} \ No newline at end of file
diff --git a/Hotline/macOS/Trackers/TrackerBookmarkSheet.swift b/Hotline/macOS/Trackers/TrackerBookmarkSheet.swift
new file mode 100644
index 0000000..4943016
--- /dev/null
+++ b/Hotline/macOS/Trackers/TrackerBookmarkSheet.swift
@@ -0,0 +1,119 @@
+struct TrackerBookmarkSheet: View {
+ @Environment(\.dismiss) private var dismiss
+ @Environment(\.modelContext) private var modelContext
+
+ @State private var bookmark: Bookmark? = nil
+ @State private var trackerAddress: String = ""
+ @State private var trackerName: String = ""
+
+ init() {
+
+ }
+
+ init(_ editingBookmark: Bookmark) {
+ _bookmark = .init(initialValue: editingBookmark)
+ _trackerAddress = .init(initialValue: editingBookmark.displayAddress)
+ _trackerName = .init(initialValue: editingBookmark.name)
+ }
+
+ var body: some View {
+ VStack(alignment: .leading) {
+ Form {
+ if self.bookmark == nil {
+ HStack(alignment: .top, spacing: 10) {
+ GroupedIconView(color: .blue, systemName: "point.3.filled.connected.trianglepath.dotted", padding: 5.0)
+ .frame(width: 28, height: 28)
+
+ VStack(alignment: .leading) {
+ Text("Add a Hotline Tracker")
+
+ Text("Enter the address and name of a Hotline Tracker you want to add.")
+ .foregroundStyle(.secondary)
+ .font(.subheadline)
+ }
+ }
+ }
+ else {
+ HStack(alignment: .top, spacing: 10) {
+ GroupedIconView(color: .blue, systemName: "point.3.filled.connected.trianglepath.dotted", padding: 5.0)
+ .frame(width: 28, height: 28)
+
+ VStack(alignment: .leading) {
+ Text("Edit Hotline Tracker")
+
+ Text("Change the address and name of your Hotline Tracker.")
+ .foregroundStyle(.secondary)
+ .font(.subheadline)
+ }
+ }
+ }
+
+ Group {
+ TextField(text: $trackerAddress) {
+ Text("Address")
+ }
+ TextField(text: $trackerName, prompt: Text("Optional")) {
+ Text("Name")
+ }
+ }
+// .textFieldStyle(.roundedBorder)
+ .controlSize(.large)
+ }
+ .formStyle(.grouped)
+ }
+ .frame(width: 350)
+ .fixedSize(horizontal: true, vertical: true)
+ .toolbar {
+ ToolbarItem(placement: .confirmationAction) {
+ Button {
+ self.saveTracker()
+ } label: {
+ if self.bookmark != nil {
+ Text("Save")
+ }
+ else {
+ Text("Add")
+ }
+ }
+ }
+ ToolbarItem(placement: .cancellationAction) {
+ Button("Cancel") {
+ self.trackerName = ""
+ self.trackerAddress = ""
+
+ self.dismiss()
+ }
+ }
+ }
+ }
+
+ private func saveTracker() {
+ var displayName = trackerName.trimmingCharacters(in: .whitespacesAndNewlines)
+ let (host, port) = Tracker.parseTrackerAddressAndPort(trackerAddress)
+
+ if displayName.isEmpty {
+ displayName = host
+ }
+
+ if !displayName.isEmpty && !host.isEmpty {
+ if !host.isEmpty {
+ if self.bookmark != nil {
+ // We're editing an existing bookmark.
+ self.bookmark?.name = displayName
+ self.bookmark?.address = host
+ self.bookmark?.port = port
+ }
+ else {
+ // We're creating a new bookmark.
+ let newBookmark = Bookmark(type: .tracker, name: displayName, address: host, port: port)
+ Bookmark.add(newBookmark, context: modelContext)
+ }
+
+ self.trackerName = ""
+ self.trackerAddress = ""
+
+ self.dismiss()
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Hotline/macOS/Trackers/TrackerItemView.swift b/Hotline/macOS/Trackers/TrackerItemView.swift
new file mode 100644
index 0000000..59caad5
--- /dev/null
+++ b/Hotline/macOS/Trackers/TrackerItemView.swift
@@ -0,0 +1,73 @@
+struct TrackerItemView: View {
+ let bookmark: Bookmark
+ let isExpanded: Bool
+ let isLoading: Bool
+ let count: Int
+ let onToggleExpanded: () -> Void
+ @Environment(\.appearsActive) private var appearsActive
+
+ var body: some View {
+ HStack(alignment: .center, spacing: 6) {
+ if bookmark.type == .tracker {
+ Button {
+ self.onToggleExpanded()
+ } label: {
+ Text(Image(systemName: self.isExpanded ? "chevron.down" : "chevron.right"))
+ .bold()
+ .font(.system(size: 10))
+ .opacity(0.5)
+ .frame(alignment: .center)
+ }
+ .buttonStyle(.plain)
+ .frame(width: 10)
+ .padding(.leading, 4)
+ .padding(.trailing, 2)
+ }
+
+ switch bookmark.type {
+ case .tracker:
+ Image("Tracker")
+ .resizable()
+ .scaledToFit()
+ .frame(width: 16, height: 16, alignment: .center)
+ Text(bookmark.name).bold().lineLimit(1).truncationMode(.tail)
+ if isLoading {
+ ProgressView()
+ .padding([.leading, .trailing], 2)
+ .controlSize(.small)
+ }
+ Spacer(minLength: 0)
+ if isExpanded && count > 0 {
+ HStack(spacing: 4) {
+ Text(String(count))
+
+ SpinningGlobeView()
+ .fontWeight(.semibold)
+ .frame(width: 12, height: 12)
+ }
+ .padding(.horizontal, 6)
+ .padding(.vertical, 2)
+ .foregroundStyle(.secondary)
+// .background(.quinary)
+ .clipShape(.capsule)
+ }
+ case .server:
+ Image(systemName: "bookmark.fill")
+ .resizable()
+ .scaledToFit()
+ .foregroundStyle(Color.secondary)
+ .frame(width: 11, height: 11, alignment: .center)
+ .opacity(0.75)
+ .padding(.leading, 3)
+ .padding(.trailing, 2)
+ Image("Server")
+ .resizable()
+ .scaledToFit()
+ .frame(width: 16, height: 16, alignment: .center)
+ Text(bookmark.name).lineLimit(1).truncationMode(.tail)
+ Spacer(minLength: 0)
+ }
+ }
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+} \ No newline at end of file