Skip to content

Commit c1e187d

Browse files
committed
Coder Desktop swift 6 conformance
1 parent 6cf9394 commit c1e187d

File tree

10 files changed

+19
-42
lines changed

10 files changed

+19
-42
lines changed

Coder Desktop/Coder Desktop/About.swift

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum About {
3030
return coder
3131
}
3232

33+
@MainActor
3334
static func open() {
3435
#if compiler(>=5.9) && canImport(AppKit)
3536
if #available(macOS 14, *) {

Coder Desktop/Coder Desktop/Coder_DesktopApp.swift

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct DesktopApp: App {
1717
}
1818
}
1919

20+
@MainActor
2021
class AppDelegate: NSObject, NSApplicationDelegate {
2122
private var menuBarExtra: FluidMenuBarExtra?
2223
let vpn: PreviewVPN
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SwiftUI
22

3-
class PreviewVPN: Coder_Desktop.VPNService {
3+
@MainActor
4+
final class PreviewVPN: Coder_Desktop.VPNService {
45
@Published var state: Coder_Desktop.VPNServiceState = .disabled
56
@Published var agents: [Coder_Desktop.Agent] = [
67
Agent(id: UUID(), name: "dogfood2", status: .error, copyableDNS: "asdf.coder", workspaceName: "dogfood2"),
@@ -22,36 +23,26 @@ class PreviewVPN: Coder_Desktop.VPNService {
2223
self.shouldFail = shouldFail
2324
}
2425

25-
private func setState(_ newState: Coder_Desktop.VPNServiceState) async {
26-
await MainActor.run {
27-
self.state = newState
28-
}
29-
}
30-
3126
func start() async {
32-
await setState(.connecting)
27+
state = .connecting
3328
do {
34-
try await Task.sleep(for: .seconds(1))
29+
try await Task.sleep(for: .seconds(10))
3530
} catch {
36-
await setState(.failed(.exampleError))
31+
state = .failed(.exampleError)
3732
return
3833
}
39-
if shouldFail {
40-
await setState(.failed(.exampleError))
41-
} else {
42-
await setState(.connected)
43-
}
34+
state = shouldFail ? .failed(.exampleError) : .connected
4435
}
4536

4637
func stop() async {
4738
guard state == .connected else { return }
48-
await setState(.disconnecting)
39+
state = .disconnecting
4940
do {
50-
try await Task.sleep(for: .seconds(1))
41+
try await Task.sleep(for: .seconds(10))
5142
} catch {
52-
await setState(.failed(.exampleError))
43+
state = .failed(.exampleError)
5344
return
5445
}
55-
await setState(.disabled)
46+
state = .disabled
5647
}
5748
}

Coder Desktop/Coder Desktop/SDK/Client.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct CoderClient: Client {
2222
return enc
2323
}()
2424

25-
func request<T: Encodable>(
25+
func request<T: Encodable & Sendable>(
2626
_ path: String,
2727
method: HTTPMethod,
2828
body: T? = nil

Coder Desktop/Coder Desktop/VPNService.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SwiftUI
22

3+
@MainActor
34
protocol VPNService: ObservableObject {
45
var state: VPNServiceState { get }
56
var agents: [Agent] { get }

Coder Desktop/Coder DesktopTests/AgentsTests.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
import Testing
44
import ViewInspector
55

6+
@MainActor
67
@Suite(.timeLimit(.minutes(1)))
78
struct AgentsTests {
89
let vpn: MockVPNService
@@ -30,7 +31,6 @@ struct AgentsTests {
3031
}
3132

3233
@Test
33-
@MainActor
3434
func agentsWhenVPNOff() throws {
3535
vpn.state = .disabled
3636

@@ -40,7 +40,6 @@ struct AgentsTests {
4040
}
4141

4242
@Test
43-
@MainActor
4443
func agentsWhenVPNOn() throws {
4544
vpn.state = .connected
4645
vpn.agents = createMockAgents(count: Theme.defaultVisibleAgents + 2)
@@ -51,7 +50,6 @@ struct AgentsTests {
5150
}
5251

5352
@Test
54-
@MainActor
5553
func showAllToggle() async throws {
5654
vpn.state = .connected
5755
vpn.agents = createMockAgents(count: 7)
@@ -78,7 +76,6 @@ struct AgentsTests {
7876
}
7977

8078
@Test
81-
@MainActor
8279
func noToggleFewAgents() throws {
8380
vpn.state = .connected
8481
vpn.agents = createMockAgents(count: 3)

Coder Desktop/Coder DesktopTests/LoginFormTests.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
import Testing
44
import ViewInspector
55

6+
@MainActor
67
@Suite(.timeLimit(.minutes(1)))
78
struct LoginTests {
89
let session: MockSession
@@ -16,7 +17,6 @@ struct LoginTests {
1617
}
1718

1819
@Test
19-
@MainActor
2020
func testInitialView() async throws {
2121
try await ViewHosting.host(view) {
2222
try await sut.inspection.inspect { view in
@@ -28,7 +28,6 @@ struct LoginTests {
2828
}
2929

3030
@Test
31-
@MainActor
3231
func testInvalidServerURL() async throws {
3332
try await ViewHosting.host(view) {
3433
try await sut.inspection.inspect { view in
@@ -40,7 +39,6 @@ struct LoginTests {
4039
}
4140

4241
@Test
43-
@MainActor
4442
func testValidServerURL() async throws {
4543
try await ViewHosting.host(view) {
4644
try await sut.inspection.inspect { view in
@@ -55,7 +53,6 @@ struct LoginTests {
5553
}
5654

5755
@Test
58-
@MainActor
5956
func testBackButton() async throws {
6057
try await ViewHosting.host(view) {
6158
try await sut.inspection.inspect { view in
@@ -70,7 +67,6 @@ struct LoginTests {
7067
}
7168

7269
@Test
73-
@MainActor
7470
func testFailedAuthentication() async throws {
7571
let login = LoginForm<MockErrorClient, MockSession>()
7672

@@ -87,7 +83,6 @@ struct LoginTests {
8783
}
8884

8985
@Test
90-
@MainActor
9186
func testSuccessfulLogin() async throws {
9287
try await ViewHosting.host(view) {
9388
try await sut.inspection.inspect { view in

Coder Desktop/Coder DesktopTests/Util.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ import Combine
33
import SwiftUI
44
import ViewInspector
55

6+
@MainActor
67
class MockVPNService: VPNService, ObservableObject {
78
@Published var state: Coder_Desktop.VPNServiceState = .disabled
89
@Published var baseAccessURL: URL = .init(string: "https://dev.coder.com")!
910
@Published var agents: [Coder_Desktop.Agent] = []
1011
var onStart: (() async -> Void)?
1112
var onStop: (() async -> Void)?
1213

13-
@MainActor
1414
func start() async {
1515
state = .connecting
1616
await onStart?()
1717
}
1818

19-
@MainActor
2019
func stop() async {
2120
state = .disconnecting
2221
await onStop?()

Coder Desktop/Coder DesktopTests/VPNMenuTests.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
import Testing
44
import ViewInspector
55

6+
@MainActor
67
@Suite(.timeLimit(.minutes(1)))
78
struct VPNMenuTests {
89
let vpn: MockVPNService
@@ -18,7 +19,6 @@ struct VPNMenuTests {
1819
}
1920

2021
@Test
21-
@MainActor
2222
func testVPNLoggedOut() async throws {
2323
session.hasSession = false
2424

@@ -33,7 +33,6 @@ struct VPNMenuTests {
3333
}
3434

3535
@Test
36-
@MainActor
3736
func testStartStopCalled() async throws {
3837
try await ViewHosting.host(view) {
3938
try await sut.inspection.inspect { view in
@@ -58,7 +57,6 @@ struct VPNMenuTests {
5857
}
5958

6059
@Test
61-
@MainActor
6260
func testVPNDisabledWhileConnecting() async throws {
6361
vpn.state = .disabled
6462

@@ -79,7 +77,6 @@ struct VPNMenuTests {
7977
}
8078

8179
@Test
82-
@MainActor
8380
func testVPNDisabledWhileDisconnecting() async throws {
8481
vpn.state = .disabled
8582

@@ -106,7 +103,6 @@ struct VPNMenuTests {
106103
}
107104

108105
@Test
109-
@MainActor
110106
func testOffWhenFailed() async throws {
111107
try await ViewHosting.host(view) {
112108
try await sut.inspection.inspect { view in

Coder Desktop/Coder DesktopTests/VPNStateTests.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
import Testing
44
import ViewInspector
55

6+
@MainActor
67
@Suite(.timeLimit(.minutes(1)))
78
struct VPNStateTests {
89
let vpn: MockVPNService
@@ -16,7 +17,6 @@ struct VPNStateTests {
1617
}
1718

1819
@Test
19-
@MainActor
2020
func testDisabledState() async throws {
2121
vpn.state = .disabled
2222

@@ -30,7 +30,6 @@ struct VPNStateTests {
3030
}
3131

3232
@Test
33-
@MainActor
3433
func testConnectingState() async throws {
3534
vpn.state = .connecting
3635

@@ -43,7 +42,6 @@ struct VPNStateTests {
4342
}
4443

4544
@Test
46-
@MainActor
4745
func testDisconnectingState() async throws {
4846
vpn.state = .disconnecting
4947

@@ -56,7 +54,6 @@ struct VPNStateTests {
5654
}
5755

5856
@Test
59-
@MainActor
6057
func testFailedState() async throws {
6158
vpn.state = .failed(.exampleError)
6259

@@ -69,7 +66,6 @@ struct VPNStateTests {
6966
}
7067

7168
@Test
72-
@MainActor
7369
func testDefaultState() async throws {
7470
vpn.state = .connected
7571

0 commit comments

Comments
 (0)