aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-01-03 15:40:24 -0800
committerDustin Mierau <dustin@mierau.me>2024-01-03 15:40:24 -0800
commit64368ad8690f0a071f2490e8429c0437694133ee (patch)
tree2e0eac2130ff39498ccab2fa8f6abf905f7c5a4d
parent4d31accad9d6bf901928f4293f29cb62f6f77260 (diff)
Fix issue with username saving to server with each change in username textfield.
-rw-r--r--Hotline/Application.swift2
-rw-r--r--Hotline/Hotline.entitlements2
-rw-r--r--Hotline/Utility/TextDocument.swift8
-rw-r--r--Hotline/macOS/ChatView.swift20
-rw-r--r--Hotline/macOS/ServerView.swift48
-rw-r--r--Hotline/macOS/SettingsView.swift33
-rw-r--r--Hotline/macOS/TrackerView.swift11
7 files changed, 61 insertions, 63 deletions
diff --git a/Hotline/Application.swift b/Hotline/Application.swift
index baea4da..0804615 100644
--- a/Hotline/Application.swift
+++ b/Hotline/Application.swift
@@ -33,7 +33,7 @@ struct Application: App {
.defaultSize(width: 700, height: 600)
.defaultPosition(.center)
- WindowGroup(for: Server.self) { $server in
+ WindowGroup(id: "server", for: Server.self) { $server in
if let s = server {
ServerView(server: s)
.frame(minWidth: 400, minHeight: 300)
diff --git a/Hotline/Hotline.entitlements b/Hotline/Hotline.entitlements
index 1ec315d..3c00456 100644
--- a/Hotline/Hotline.entitlements
+++ b/Hotline/Hotline.entitlements
@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
+ <key>com.apple.security.files.user-selected.read-write</key>
+ <true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
diff --git a/Hotline/Utility/TextDocument.swift b/Hotline/Utility/TextDocument.swift
index 3904a21..82727de 100644
--- a/Hotline/Utility/TextDocument.swift
+++ b/Hotline/Utility/TextDocument.swift
@@ -16,14 +16,16 @@ struct TextFile: FileDocument {
// this initializer loads data that has been saved previously
init(configuration: ReadConfiguration) throws {
+
if let data = configuration.file.regularFileContents {
- text = String(decoding: data, as: UTF8.self)
+ if let str = String(data: data, encoding: .utf8) {
+ self.text = str
+ }
}
}
// this will be called when the system wants to write our data to disk
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
- let data = Data(text.utf8)
- return FileWrapper(regularFileWithContents: data)
+ return FileWrapper(regularFileWithContents: self.text.data(using: .utf8)!)
}
}
diff --git a/Hotline/macOS/ChatView.swift b/Hotline/macOS/ChatView.swift
index d94634a..d9e1f54 100644
--- a/Hotline/macOS/ChatView.swift
+++ b/Hotline/macOS/ChatView.swift
@@ -171,7 +171,6 @@ struct ChatView: View {
}
}
.navigationTitle(self.model.serverTitle)
- .navigationSubtitle(self.model.users.count > 0 ? "^[\(self.model.users.count) user](inflect: true) online" : "")
.background(Color(nsColor: .textBackgroundColor))
.toolbar {
ToolbarItem(placement: .primaryAction) {
@@ -181,17 +180,17 @@ struct ChatView: View {
}
} label: {
Image(systemName: "square.and.arrow.up")
- }.help("Save Chat")
+ }.help("Save Chat...")
}
}
- .fileExporter(isPresented: $showingExporter, document: chatDocument, contentType: .utf8PlainText, defaultFilename: "\(model.serverTitle) Chat") { result in
-// switch result {
-// case .success(let url):
-// print("Saved to \(url)")
-//
-// case .failure(let error):
-// print(error.localizedDescription)
-// }
+ .fileExporter(isPresented: $showingExporter, document: self.chatDocument, contentType: .utf8PlainText, defaultFilename: "\(self.model.serverTitle) Chat.txt") { result in
+ switch result {
+ case .success(let url):
+ print("Saved to \(url)")
+
+ case .failure(let error):
+ print(error.localizedDescription)
+ }
self.chatDocument.text = ""
}
}
@@ -200,7 +199,6 @@ struct ChatView: View {
var text: String = String()
self.chatDocument.text = ""
-
for msg in model.chat {
if msg.type == .agreement {
text.append(msg.text)
diff --git a/Hotline/macOS/ServerView.swift b/Hotline/macOS/ServerView.swift
index ae8a104..5570c47 100644
--- a/Hotline/macOS/ServerView.swift
+++ b/Hotline/macOS/ServerView.swift
@@ -181,7 +181,7 @@ struct ServerView: View {
@State private var agreementShown: Bool = false
@State private var selection: MenuItem? = ServerView.menuItems.first
- let server: Server
+ let server: Server?
static var menuItems = [
MenuItem(name: "Chat", image: "bubble", type: .chat),
@@ -259,7 +259,7 @@ struct ServerView: View {
}
var usersSection: some View {
- Section("Users") {
+ Section("\(model.users.count) Online") {
ForEach(model.users) { user in
HStack {
if let iconImage = Hotline.getClassicIcon(Int(user.iconID)) {
@@ -302,28 +302,9 @@ struct ServerView: View {
var body: some View {
NavigationSplitView {
-
self.navigationList
.frame(maxWidth: .infinity)
.navigationSplitViewColumnWidth(min: 150, ideal: 200, max: 500)
-
-// VSplitView {
-//
-// self.navigationList
-//
-// ScrollView {
-// VStack(alignment: .leading) {
-// // ForEach(model.downloads) {
-// // }
-// }
-// .frame(maxWidth: .infinity)
-// }
-//
-// }
-// .frame(maxWidth: .infinity)
-// .navigationSplitViewColumnWidth(min: 150, ideal: 200, max: 500)
-
-
} detail: {
if let selection = self.selection {
switch selection.type {
@@ -334,22 +315,18 @@ struct ServerView: View {
case .chat:
ChatView()
.navigationTitle(self.model.serverTitle)
- .navigationSubtitle(self.model.users.count > 0 ? "^[\(self.model.users.count) user](inflect: true) online" : "")
.navigationSplitViewColumnWidth(min: 250, ideal: 500)
case .news:
NewsView()
.navigationTitle(self.model.serverTitle)
- .navigationSubtitle(self.model.users.count > 0 ? "^[\(self.model.users.count) user](inflect: true) online" : "")
.navigationSplitViewColumnWidth(min: 250, ideal: 500)
case .messageBoard:
MessageBoardView()
.navigationTitle(self.model.serverTitle)
- .navigationSubtitle(self.model.users.count > 0 ? "^[\(self.model.users.count) user](inflect: true) online" : "")
.navigationSplitViewColumnWidth(min: 250, ideal: 500)
case .files:
FilesView()
.navigationTitle(self.model.serverTitle)
- .navigationSubtitle(self.model.users.count > 0 ? "^[\(self.model.users.count) user](inflect: true) online" : "")
.navigationSplitViewColumnWidth(min: 250, ideal: 500)
case .tasks:
EmptyView()
@@ -357,7 +334,6 @@ struct ServerView: View {
if let selectionUserID = selection.userID {
MessageView(userID: selectionUserID)
.navigationTitle(self.model.serverTitle)
- .navigationSubtitle(self.model.users.count > 0 ? "^[\(self.model.users.count) user](inflect: true) online" : "")
.navigationSplitViewColumnWidth(min: 250, ideal: 500)
}
}
@@ -365,15 +341,17 @@ struct ServerView: View {
}
.navigationTitle("")
.onAppear {
- self.model.login(server: self.server, login: "", password: "", username: preferences.username, iconID: preferences.userIconID) { success in
- if !success {
- print("FAILED LOGIN??")
- }
- else {
- print("GETTING USER LIST????!")
- self.sendPreferences()
- self.model.getUserList()
- self.model.downloadBanner()
+ if let s = self.server {
+ self.model.login(server: s, login: "", password: "", username: preferences.username, iconID: preferences.userIconID) { success in
+ if !success {
+ print("FAILED LOGIN??")
+ }
+ else {
+ print("GETTING USER LIST????!")
+ self.sendPreferences()
+ self.model.getUserList()
+ self.model.downloadBanner()
+ }
}
}
}
diff --git a/Hotline/macOS/SettingsView.swift b/Hotline/macOS/SettingsView.swift
index 54710d1..350c70f 100644
--- a/Hotline/macOS/SettingsView.swift
+++ b/Hotline/macOS/SettingsView.swift
@@ -2,12 +2,17 @@ import SwiftUI
struct GeneralSettingsView: View {
@Environment(Prefs.self) private var preferences: Prefs
+
+ @State private var username: String = ""
+ @State private var usernameChanged: Bool = false
+
+ let saveTimer = Timer.publish(every: 5, on: .main, in: .common).autoconnect()
var body: some View {
@Bindable var preferences = preferences
Form {
- TextField("Your Name", text: $preferences.username, prompt: Text("guest"))
+ TextField("Your Name", text: $username, prompt: Text("guest"))
Toggle("Refuse private messages", isOn: $preferences.refusePrivateMessages)
Toggle("Refuse private chat", isOn: $preferences.refusePrivateChat)
Toggle("Automatic Response", isOn: $preferences.enableAutomaticMessage)
@@ -15,13 +20,31 @@ struct GeneralSettingsView: View {
TextField("", text: $preferences.automaticMessage, prompt: Text("Write a response message"))
.lineLimit(2)
.multilineTextAlignment(.leading)
-// .fixedSize(horizontal: true, vertical: false)
.frame(maxWidth: .infinity)
-// .lineLimit(2, reservesSpace: true)
+ .onSubmit(of: .text) {
+ preferences.username = self.username
+ }
}
}
.padding(20)
.frame(width: 350)
+ .onAppear {
+ self.username = preferences.username
+ self.usernameChanged = false
+ }
+ .onDisappear {
+ preferences.username = self.username
+ self.usernameChanged = false
+ }
+ .onChange(of: username) { oldValue, newValue in
+ self.usernameChanged = true
+ }
+ .onReceive(saveTimer) { _ in
+ if self.usernameChanged {
+ self.usernameChanged = false
+ preferences.username = self.username
+ }
+ }
}
}
@@ -30,8 +53,6 @@ struct IconSettingsView: View {
@State private var hoveredUserIconID: Int = -1
-// @AppStorage(Prefs.userIconID) private var userIconID: Int = Prefs.defaultIconID
-
var body: some View {
@Bindable var preferences = preferences
@@ -94,7 +115,7 @@ struct SettingsView: View {
TabView {
GeneralSettingsView()
.tabItem {
- Label("General", systemImage: "gear")
+ Label("General", systemImage: "person.text.rectangle")
}
.tag(Tabs.general)
IconSettingsView()
diff --git a/Hotline/macOS/TrackerView.swift b/Hotline/macOS/TrackerView.swift
index 0f6b6b2..0278904 100644
--- a/Hotline/macOS/TrackerView.swift
+++ b/Hotline/macOS/TrackerView.swift
@@ -208,14 +208,12 @@ struct TrackerItemView: View {
}
struct TrackerView: View {
- @Environment(\.colorScheme) var colorScheme
+ @Environment(\.colorScheme) private var colorScheme
@Environment(\.openWindow) private var openWindow
-// @AppStorage("servers", store: .standard)
var bookmarks: [TrackerBookmark] = [
TrackerBookmark(type: .server, name: "RetroMac", address: "82.32.130.173"),
TrackerBookmark(type: .server, name: "System 7 Today", address: "158.174.146.146"),
-// TrackerBookmark(type: .server, name: "Bob Kiwi's House", address: "73.132.92.104"),
TrackerBookmark(type: .tracker, name: "Featured Servers", address: "hltracker.com"),
TrackerBookmark(type: .tracker, name: "Agent79", address: "tracked.agent79.org"),
TrackerBookmark(type: .tracker, name: "Preterhuman", address: "tracker.preterhuman.net"),
@@ -264,8 +262,6 @@ struct TrackerView: View {
}
@State private var servers: [TrackerItem] = []
-// @State private var selectedServer: Server?
-
@State private var selection: TrackerItem? = nil
@State private var scrollOffset: CGFloat = CGFloat.zero
@@ -360,10 +356,11 @@ struct TrackerView: View {
ToolbarItem(placement: .primaryAction) {
Button {
+ openWindow(id: "server")
} label: {
- Label("Add Server Bookmark...", systemImage: "plus")
+ Label("Add Server Bookmark...", systemImage: "globe.americas.fill")
}
- .help("Add Server Bookmark")
+ .help("Connect to Server...")
}
}
.onAppear {