Skip to content

Commit 5ece015

Browse files
committed
workaround xcode linking bug
1 parent f6a851a commit 5ece015

File tree

4 files changed

+68
-63
lines changed

4 files changed

+68
-63
lines changed
+3-61
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Foundation
2-
import URLRouting
2+
import VPNLib
33

44
@MainActor
55
class URLHandler {
@@ -13,7 +13,7 @@ class URLHandler {
1313
router = CoderRouter()
1414
}
1515

16-
func handle(_ url: URL) throws(URLError) {
16+
func handle(_ url: URL) throws(RouterError) {
1717
guard state.hasSession, let deployment = state.baseAccessURL else {
1818
throw .noSession
1919
}
@@ -29,69 +29,11 @@ class URLHandler {
2929
}
3030
}
3131
} catch {
32-
throw .routerError(url: url)
32+
throw .matchError(url: url)
3333
}
3434

3535
func handleRDP(workspace _: String, agent _: String, creds _: RDPCredentials) {
3636
// TODO: Handle RDP
3737
}
3838
}
3939
}
40-
41-
struct CoderRouter: ParserPrinter {
42-
public var body: some ParserPrinter<URLRequestData, CoderRoute> {
43-
Route(.case(CoderRoute.open(workspace:agent:route:))) {
44-
// v0/open/ws/<workspace>/agent/<agent>/<openType>
45-
Path { "v0"; "open"; "ws"; Parse(.string); "agent"; Parse(.string) }
46-
openRouter
47-
}
48-
}
49-
50-
var openRouter: some ParserPrinter<URLRequestData, OpenRoute> {
51-
OneOf {
52-
Route(.memberwise(OpenRoute.rdp)) {
53-
Path { "rdp" }
54-
Query {
55-
Parse(.memberwise(RDPCredentials.init)) {
56-
Optionally { Field("username") }
57-
Optionally { Field("password") }
58-
}
59-
}
60-
}
61-
}
62-
}
63-
}
64-
65-
enum URLError: Error {
66-
case invalidAuthority(String)
67-
case routerError(url: URL)
68-
case noSession
69-
70-
var description: String {
71-
switch self {
72-
case let .invalidAuthority(authority):
73-
"Authority '\(authority)' does not match the host of the current Coder deployment."
74-
case let .routerError(url):
75-
"Failed to handle \(url.absoluteString) because the format is unsupported."
76-
case .noSession:
77-
"Not logged in."
78-
}
79-
}
80-
81-
var localizedDescription: String { description }
82-
}
83-
84-
public enum CoderRoute: Equatable, Sendable {
85-
case open(workspace: String, agent: String, route: OpenRoute)
86-
}
87-
88-
public enum OpenRoute: Equatable, Sendable {
89-
case rdp(RDPCredentials)
90-
}
91-
92-
// Due to a Swift Result builder limitation, we can't flatten this out to `case rdp(String?, String?)`
93-
// https://github.com/pointfreeco/swift-url-routing/issues/50
94-
public struct RDPCredentials: Equatable, Sendable {
95-
let username: String?
96-
let password: String?
97-
}
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import Foundation
2+
import URLRouting
3+
4+
// This is in VPNLib to avoid depending on `swift-collections` in both the app & extension.
5+
public struct CoderRouter: ParserPrinter {
6+
public init() {}
7+
8+
public var body: some ParserPrinter<URLRequestData, CoderRoute> {
9+
Route(.case(CoderRoute.open(workspace:agent:route:))) {
10+
// v0/open/ws/<workspace>/agent/<agent>/<openType>
11+
Path { "v0"; "open"; "ws"; Parse(.string); "agent"; Parse(.string) }
12+
openRouter
13+
}
14+
}
15+
16+
var openRouter: some ParserPrinter<URLRequestData, OpenRoute> {
17+
OneOf {
18+
Route(.memberwise(OpenRoute.rdp)) {
19+
Path { "rdp" }
20+
Query {
21+
Parse(.memberwise(RDPCredentials.init)) {
22+
Optionally { Field("username") }
23+
Optionally { Field("password") }
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
30+
31+
public enum RouterError: Error {
32+
case invalidAuthority(String)
33+
case matchError(url: URL)
34+
case noSession
35+
36+
public var description: String {
37+
switch self {
38+
case let .invalidAuthority(authority):
39+
"Authority '\(authority)' does not match the host of the current Coder deployment."
40+
case let .matchError(url):
41+
"Failed to handle \(url.absoluteString) because the format is unsupported."
42+
case .noSession:
43+
"Not logged in."
44+
}
45+
}
46+
47+
public var localizedDescription: String { description }
48+
}
49+
50+
public enum CoderRoute: Equatable, Sendable {
51+
case open(workspace: String, agent: String, route: OpenRoute)
52+
}
53+
54+
public enum OpenRoute: Equatable, Sendable {
55+
case rdp(RDPCredentials)
56+
}
57+
58+
// Due to a Swift Result builder limitation, we can't flatten this out to `case rdp(String?, String?)`
59+
// https://github.com/pointfreeco/swift-url-routing/issues/50
60+
public struct RDPCredentials: Equatable, Sendable {
61+
public let username: String?
62+
public let password: String?
63+
}

Coder-Desktop/Coder-DesktopTests/CoderRouterTests.swift renamed to Coder-Desktop/VPNLibTests/CoderRouterTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
@testable import Coder_Desktop
21
import Foundation
32
import Testing
43
import URLRouting
4+
@testable import VPNLib
55

66
@MainActor
77
@Suite(.timeLimit(.minutes(1)))

Coder-Desktop/project.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ targets:
189189
- package: LaunchAtLogin
190190
- package: SDWebImageSwiftUI
191191
- package: SDWebImageSVGCoder
192-
- package: URLRouting
193192
scheme:
194193
testPlans:
195194
- path: Coder-Desktop.xctestplan
@@ -295,6 +294,7 @@ targets:
295294
- package: GRPC
296295
- package: Subprocess
297296
- package: Semaphore
297+
- package: URLRouting
298298
- target: CoderSDK
299299
embed: false
300300

0 commit comments

Comments
 (0)