aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/macOS')
-rw-r--r--Hotline/macOS/ServerView.swift151
-rw-r--r--Hotline/macOS/Trackers/TrackerView.swift50
2 files changed, 117 insertions, 84 deletions
diff --git a/Hotline/macOS/ServerView.swift b/Hotline/macOS/ServerView.swift
index a66a071..d2c503f 100644
--- a/Hotline/macOS/ServerView.swift
+++ b/Hotline/macOS/ServerView.swift
@@ -116,8 +116,13 @@ struct ServerView: View {
var body: some View {
Group {
if model.status == .disconnected {
- connectForm
- .navigationTitle("Connect to Server")
+ VStack(alignment: .center) {
+ Spacer()
+ self.connectForm
+ Spacer()
+ }
+// .frame(maxWidth: .infinity, maxHeight: .infinity)
+ .navigationTitle("Connect to Server")
}
else if case .failed(let error) = model.status {
VStack {
@@ -245,79 +250,80 @@ struct ServerView: View {
}
var connectForm: some View {
- VStack(alignment: .center) {
- GroupBox {
- Form {
- Group {
- TextField(text: $connectAddress) {
- Text("Address:")
- }
- .focused($focusedField, equals: .address)
-
- Text("Type the address of the Hotline server you would like to connect to. If you have an account on that server, type your login and password too.")
- .font(.caption)
- .foregroundStyle(.secondary)
- .padding(.bottom, 4)
-
- TextField(text: $connectLogin, prompt: Text("Optional")) {
- Text("Login:")
- }
- .focused($focusedField, equals: .login)
- SecureField(text: $connectPassword, prompt: Text("Optional")) {
- Text("Password:")
- }
- .focused($focusedField, equals: .password)
- }
- .textFieldStyle(.roundedBorder)
- .controlSize(.large)
-
- HStack {
- Button("Save...") {
- if !connectAddress.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
- connectNameSheetPresented = true
- }
- }
- .disabled(connectAddress.isEmpty)
- .controlSize(.regular)
- .buttonStyle(.automatic)
- .help("Bookmark server")
-
- Spacer()
-
- Button("Cancel") {
- dismiss()
- }
- .controlSize(.regular)
- .buttonStyle(.automatic)
- .keyboardShortcut(.cancelAction)
-
- Button("Connect") {
- connectToServer()
- }
-
- .controlSize(.regular)
- .buttonStyle(.automatic)
- .keyboardShortcut(.defaultAction)
- }
- .padding(.top, 8)
-
+ Form {
+ HStack(alignment: .top, spacing: 10) {
+ Image("Server Large")
+ .resizable()
+ .scaledToFit()
+ .frame(width: 28, height: 28)
+
+ VStack(alignment: .leading) {
+ Text("Connect to Server")
+ Text("Enter the address of a Hotline server to connect to.")
+ .foregroundStyle(.secondary)
+ .font(.subheadline)
}
- .padding()
- .onChange(of: connectAddress) {
- let (a, p) = Server.parseServerAddressAndPort(connectAddress)
- server.address = a
- server.port = p
+ }
+
+ TextField(text: $connectAddress) {
+ Text("Address:")
+ }
+ .focused($focusedField, equals: .address)
+
+ TextField(text: $connectLogin, prompt: Text("Optional")) {
+ Text("Login:")
+ }
+ .focused($focusedField, equals: .login)
+ SecureField(text: $connectPassword, prompt: Text("Optional")) {
+ Text("Password:")
+ }
+ .focused($focusedField, equals: .password)
+
+ HStack {
+ Button("Save...") {
+ if !connectAddress.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
+ connectNameSheetPresented = true
+ }
}
- .onChange(of: connectLogin) {
- server.login = connectLogin.trimmingCharacters(in: .whitespacesAndNewlines)
+ .disabled(connectAddress.isEmpty)
+ .controlSize(.regular)
+ .buttonStyle(.automatic)
+ .help("Bookmark server")
+
+ Spacer()
+
+ Button("Cancel") {
+ dismiss()
}
- .onChange(of: connectPassword) {
- server.password = connectPassword
+ .controlSize(.regular)
+ .buttonStyle(.automatic)
+ .keyboardShortcut(.cancelAction)
+
+ Button("Connect") {
+ connectToServer()
}
+
+ .controlSize(.regular)
+ .buttonStyle(.automatic)
+ .keyboardShortcut(.defaultAction)
}
- .onAppear {
- focusedField = .address
- }
+ .padding(.top, 8)
+ }
+ .formStyle(.grouped)
+ .fixedSize(horizontal: false, vertical: true)
+ .onChange(of: connectAddress) {
+ let (a, p) = Server.parseServerAddressAndPort(connectAddress)
+ server.address = a
+ server.port = p
+ }
+ .onChange(of: connectLogin) {
+ server.login = connectLogin.trimmingCharacters(in: .whitespacesAndNewlines)
+ }
+ .onChange(of: connectPassword) {
+ server.password = connectPassword
+ }
+ .onAppear {
+ focusedField = .address
}
.frame(maxWidth: 380)
.padding()
@@ -346,8 +352,7 @@ struct ServerView: View {
if !name.isEmpty {
connectNameSheetPresented = false
connectName = ""
-// Task.detached {
-
+
let (host, port) = Server.parseServerAddressAndPort(connectAddress)
let login: String? = connectLogin.isEmpty ? nil : connectLogin
let password: String? = connectPassword.isEmpty ? nil : connectPassword
@@ -356,8 +361,6 @@ struct ServerView: View {
let newBookmark = Bookmark(type: .server, name: name, address: host, port: port, login: login, password: password)
Bookmark.add(newBookmark, context: modelContext)
}
-
-// }
}
}
}
diff --git a/Hotline/macOS/Trackers/TrackerView.swift b/Hotline/macOS/Trackers/TrackerView.swift
index 0eb4a12..dbbacaa 100644
--- a/Hotline/macOS/Trackers/TrackerView.swift
+++ b/Hotline/macOS/Trackers/TrackerView.swift
@@ -405,14 +405,13 @@ struct TrackerView: View {
@ViewBuilder
func bookmarkServerContextMenu(_ server: BookmarkServer) -> some View {
Button {
- let newBookmark = Bookmark(type: .server, name: server.name ?? server.address, address: server.address, port: server.port, login: nil, password: nil)
- Bookmark.add(newBookmark, context: modelContext)
+ NSPasteboard.general.clearContents()
+ let displayAddress = (server.port == HotlinePorts.DefaultServerPort) ? server.address : "\(server.address):\(server.port)"
+ NSPasteboard.general.setString("hotline://\(displayAddress)", forType: .string)
} label: {
- Label("Bookmark", systemImage: "bookmark")
+ Label("Copy Link", systemImage: "link")
}
- Divider()
-
Button {
NSPasteboard.general.clearContents()
let displayAddress = (server.port == HotlinePorts.DefaultServerPort) ? server.address : "\(server.address):\(server.port)"
@@ -420,11 +419,31 @@ struct TrackerView: View {
} label: {
Label("Copy Address", systemImage: "doc.on.doc")
}
+
+ Divider()
+
+ Button {
+ let newBookmark = Bookmark(type: .server, name: server.name ?? server.address, address: server.address, port: server.port, login: nil, password: nil)
+ Bookmark.add(newBookmark, context: modelContext)
+ } label: {
+ Label("Bookmark", systemImage: "bookmark")
+ }
}
@ViewBuilder
func bookmarkContextMenu(_ bookmark: Bookmark) -> some View {
Button {
+ let linkString: String = switch bookmark.type {
+ case .tracker: "hotlinetracker://\(bookmark.displayAddress)"
+ case .server: "hotline://\(bookmark.displayAddress)"
+ }
+ NSPasteboard.general.clearContents()
+ NSPasteboard.general.setString(linkString, forType: .string)
+ } label: {
+ Label("Copy Link", systemImage: "link")
+ }
+
+ Button {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(bookmark.displayAddress, forType: .string)
} label: {
@@ -471,14 +490,13 @@ struct TrackerView: View {
guard let server = bonjourServer.server else {
return
}
- let newBookmark = Bookmark(type: .server, name: server.name ?? server.address, address: server.address, port: server.port, login: nil, password: nil)
- Bookmark.add(newBookmark, context: modelContext)
+ NSPasteboard.general.clearContents()
+ let displayAddress = (server.port == HotlinePorts.DefaultServerPort) ? server.address : "\(server.address):\(server.port)"
+ NSPasteboard.general.setString("hotline://\(displayAddress)", forType: .string)
} label: {
- Label("Bookmark", systemImage: "bookmark")
+ Label("Copy Link", systemImage: "link")
}
- Divider()
-
Button {
guard let server = bonjourServer.server else {
return
@@ -488,6 +506,18 @@ struct TrackerView: View {
} label: {
Label("Copy Address", systemImage: "doc.on.doc")
}
+
+ Divider()
+
+ Button {
+ guard let server = bonjourServer.server else {
+ return
+ }
+ let newBookmark = Bookmark(type: .server, name: server.name ?? server.address, address: server.address, port: server.port, login: nil, password: nil)
+ Bookmark.add(newBookmark, context: modelContext)
+ } label: {
+ Label("Bookmark", systemImage: "bookmark")
+ }
}
func refresh() {