aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/TrackerView.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-01-05 19:46:13 -0800
committerDustin Mierau <dustin@mierau.me>2024-01-05 19:46:37 -0800
commit2f8f71d0410f59d5d303a4c221a628630168bfe2 (patch)
tree6a18ae2e4dbd72a688667bd9e819ecee72d76b52 /Hotline/macOS/TrackerView.swift
parent57c33eb798f6802fe5af8fcd3d1992a4b63a448f (diff)
Add image preview to Files so you don't have to download images to view them, works with animated GIFs too. Added cmd-R shortcut for Servers window. More work on login view.
Diffstat (limited to 'Hotline/macOS/TrackerView.swift')
-rw-r--r--Hotline/macOS/TrackerView.swift34
1 files changed, 31 insertions, 3 deletions
diff --git a/Hotline/macOS/TrackerView.swift b/Hotline/macOS/TrackerView.swift
index 2c9c839..268cd3e 100644
--- a/Hotline/macOS/TrackerView.swift
+++ b/Hotline/macOS/TrackerView.swift
@@ -9,6 +9,7 @@ struct TrackerBookmark {
let type: TrackerBookmarkType
let name: String
let address: String
+ let port: Int = HotlinePorts.DefaultServerPort
}
@Observable
@@ -22,6 +23,27 @@ class TrackerItem: Identifiable, Hashable {
var expanded: Bool = false
var loading: Bool = false
+ var displayAddress: String? {
+ if let s = server {
+ if s.port == HotlinePorts.DefaultServerPort {
+ return s.address
+ }
+ else {
+ return "\(s.address):\(s.port)"
+ }
+ }
+ else if let b = bookmark {
+ if b.port == HotlinePorts.DefaultServerPort {
+ return b.address
+ }
+ else {
+ return "\(b.address):\(b.port)"
+ }
+ }
+
+ return nil
+ }
+
init(bookmark: TrackerBookmark) {
self.bookmark = bookmark
self.server = nil
@@ -46,6 +68,7 @@ class TrackerItem: Identifiable, Hashable {
hasher.combine(self.id)
}
+
@MainActor
func loadServers() async {
guard
@@ -283,10 +306,10 @@ struct TrackerView: View {
.alternatingRowBackgrounds(.enabled)
.contextMenu(forSelectionType: TrackerItem.self) { items in
if let item = items.first {
- if let server = item.server {
+ if let address = item.displayAddress {
Button {
NSPasteboard.general.clearContents()
- NSPasteboard.general.setString(server.address, forType: .string)
+ NSPasteboard.general.setString(address, forType: .string)
} label: {
Label("Copy Server Address", systemImage: "doc.on.doc")
}
@@ -371,7 +394,7 @@ struct TrackerView: View {
.help("Connect to Server...")
}
}
- .onAppear {
+ .task {
// Add initial items to tracker list.
var items: [TrackerItem] = []
for bookmark in self.bookmarks {
@@ -379,6 +402,11 @@ struct TrackerView: View {
}
self.servers = items
}
+ .onOpenURL(perform: { url in
+ if let s = Server(url: url) {
+ openWindow(id: "server", value: s)
+ }
+ })
}
}