diff options
| author | Dustin Mierau <dustin@mierau.me> | 2025-11-13 11:33:43 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2025-11-13 11:33:43 -0800 |
| commit | da6a1f92caa31c85f9182bff4c29ceb5c72b3742 (patch) | |
| tree | ca79509164efe287354ee221542a93a4919613b9 /Hotline | |
| parent | 467b53f143a0c3d7328fe85e9d1215eceb9b150a (diff) | |
Don't show accounts in sidebar to reduce clutter. Admins can use menu bar or toolbar. More error handling.
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/Hotline/HotlineClient.swift | 10 | ||||
| -rw-r--r-- | Hotline/State/HotlineState.swift | 33 | ||||
| -rw-r--r-- | Hotline/macOS/Files/FilesView.swift | 2 | ||||
| -rw-r--r-- | Hotline/macOS/ServerView.swift | 29 |
4 files changed, 47 insertions, 27 deletions
diff --git a/Hotline/Hotline/HotlineClient.swift b/Hotline/Hotline/HotlineClient.swift index 7305a2f..6dbb460 100644 --- a/Hotline/Hotline/HotlineClient.swift +++ b/Hotline/Hotline/HotlineClient.swift @@ -666,17 +666,11 @@ public actor HotlineClient { /// - name: New folder name /// - path: Directory path for the new folder /// - Returns: True if creation succeeded - public func newFolder(name: String, path: [String]) async throws -> Bool { + public func newFolder(name: String, path: [String]) async throws { var transaction = HotlineTransaction(id: self.generateTransactionID(), type: .newFolder) transaction.setFieldString(type: .fileName, val: name) transaction.setFieldPath(type: .filePath, val: path) - - do { - try await self.sendTransaction(transaction) - return true - } catch { - return false - } + try await self.sendTransaction(transaction) } // MARK: - News diff --git a/Hotline/State/HotlineState.swift b/Hotline/State/HotlineState.swift index 1f8e2e5..c9810ad 100644 --- a/Hotline/State/HotlineState.swift +++ b/Hotline/State/HotlineState.swift @@ -852,11 +852,22 @@ class HotlineState: Equatable { throw HotlineClientError.notConnected } - return try await client.newFolder(name: name, path: parentPath) + do { + try await client.newFolder(name: name, path: parentPath) + self.invalidateFileListCache(for: parentPath, includingAncestors: true) + return true + } + catch let error as HotlineClientError { + self.errorMessage = error.userMessage + self.errorDisplayed = true + } + + return false } + @discardableResult @MainActor - func deleteFile(_ fileName: String, path: [String]) async throws { + func deleteFile(_ fileName: String, path: [String]) async throws -> Bool { guard let client = self.client else { throw HotlineClientError.notConnected } @@ -869,12 +880,14 @@ class HotlineState: Equatable { do { try await client.deleteFile(name: fileName, path: fullPath) self.invalidateFileListCache(for: fullPath, includingAncestors: true) + return true } catch let error as HotlineClientError { self.errorMessage = error.userMessage self.errorDisplayed = true - return } + + return false } /// Download a file from the server. @@ -896,9 +909,19 @@ class HotlineState: Equatable { Task { @MainActor [weak self] in guard let self else { return } - + // Request download from server - guard let result = try? await client.downloadFile(name: fileName, path: fullPath), + let result: (referenceNumber: UInt32, transferSize: Int, fileSize: Int, waitingCount: Int)? + do { + result = try await client.downloadFile(name: fileName, path: fullPath) + } + catch let error as HotlineClientError { + self.errorMessage = error.userMessage + self.errorDisplayed = true + return + } + + guard let result, let server = self.server, let address = server.address as String?, let port = server.port as Int? diff --git a/Hotline/macOS/Files/FilesView.swift b/Hotline/macOS/Files/FilesView.swift index ab93cbc..325af8c 100644 --- a/Hotline/macOS/Files/FilesView.swift +++ b/Hotline/macOS/Files/FilesView.swift @@ -432,7 +432,7 @@ struct FilesView: View { } let path: [String] = parentFolder?.path ?? [] - if try await self.model.newFolder(name: name, parentPath: path) == true { + if try await self.model.newFolder(name: name, parentPath: path) { try await self.model.getFileList(path: path) } } diff --git a/Hotline/macOS/ServerView.swift b/Hotline/macOS/ServerView.swift index 1f85bd7..b8297fd 100644 --- a/Hotline/macOS/ServerView.swift +++ b/Hotline/macOS/ServerView.swift @@ -338,18 +338,19 @@ struct ServerView: View { self.navigationList .frame(maxWidth: .infinity) .navigationSplitViewColumnWidth(min: 200, ideal: 250, max: 500) - .toolbar { - if self.model.access?.contains(.canOpenUsers) == true { - ToolbarItem { - Button { - self.state.accountsShown = true - } label: { - Label("Manage Accounts", systemImage: "gear") - } - .help("Manage Accounts") - } - } - } + .toolbar(removing: .sidebarToggle) +// .toolbar { +// if self.model.access?.contains(.canOpenUsers) == true { +// ToolbarItem(placement: .primaryAction) { +// Button { +// self.state.accountsShown = true +// } label: { +// Label("Manage Accounts", systemImage: "gear") +// } +// .help("Manage Accounts") +// } +// } +// } } detail: { switch state.selection { case .chat: @@ -388,7 +389,9 @@ struct ServerView: View { } } } - .toolbar(removing: .sidebarToggle) + .background { + Color.red + } } // MARK: - |