|
1 | 1 | import Foundation |
| 2 | +import SwiftUI |
2 | 3 | import VPNLib |
3 | 4 |
|
4 | 5 | @MainActor |
@@ -29,32 +30,36 @@ class URLHandler { |
29 | 30 |
|
30 | 31 | switch route { |
31 | 32 | case let .open(workspace, agent, type): |
32 | | - switch type { |
33 | | - case let .rdp(creds): |
34 | | - try handleRDP(workspace: workspace, agent: agent, creds: creds) |
| 33 | + do { |
| 34 | + switch type { |
| 35 | + case let .rdp(creds): |
| 36 | + try handleRDP(workspace: workspace, agent: agent, creds: creds) |
| 37 | + } |
| 38 | + } catch { |
| 39 | + throw .openError(error) |
35 | 40 | } |
36 | 41 | } |
37 | 42 | } |
38 | 43 |
|
39 | | - private func handleRDP(workspace: String, agent: String, creds: RDPCredentials) throws(URLError) { |
| 44 | + private func handleRDP(workspace: String, agent: String, creds: RDPCredentials) throws(OpenError) { |
40 | 45 | guard vpn.state == .connected else { |
41 | | - throw .openError(.coderConnectOffline) |
| 46 | + throw .coderConnectOffline |
42 | 47 | } |
43 | 48 |
|
44 | 49 | guard let workspace = vpn.menuState.findWorkspace(name: workspace) else { |
45 | | - throw .openError(.invalidWorkspace(workspace: workspace)) |
| 50 | + throw .invalidWorkspace(workspace: workspace) |
46 | 51 | } |
47 | 52 |
|
48 | 53 | guard let agent = vpn.menuState.findAgent(workspaceID: workspace.id, name: agent) else { |
49 | | - throw .openError(.invalidAgent(workspace: workspace.name, agent: agent)) |
| 54 | + throw .invalidAgent(workspace: workspace.name, agent: agent) |
50 | 55 | } |
51 | 56 |
|
52 | 57 | var rdpString = "rdp:full address=s:\(agent.primaryHost):3389" |
53 | 58 | if let username = creds.username { |
54 | 59 | rdpString += "&username=s:\(username)" |
55 | 60 | } |
56 | 61 | guard let url = URL(string: rdpString) else { |
57 | | - throw .openError(.couldNotCreateRDPURL(rdpString)) |
| 62 | + throw .couldNotCreateRDPURL(rdpString) |
58 | 63 | } |
59 | 64 |
|
60 | 65 | let alert = NSAlert() |
|
0 commit comments