Skip to content

fix: start coder connect on launch after SE is installed #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
vpn = CoderVPNService()
state = AppState(onChange: vpn.configureTunnelProviderProtocol)
fileSyncDaemon = MutagenDaemon()
if state.startVPNOnLaunch {
vpn.startWhenReady = true
}
vpn.installSystemExtension()
}

func applicationDidFinishLaunching(_: Notification) {
Expand Down Expand Up @@ -68,16 +72,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if await !vpn.loadNetworkExtensionConfig() {
state.reconfigure()
}
if state.startVPNOnLaunch {
await vpn.start()
}
}
// TODO: Start the daemon only once a file sync is configured
Task {
await fileSyncDaemon.start()
}
}

deinit {
NotificationCenter.default.removeObserver(self)
}

Comment on lines +82 to +85
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by fix: this was on the wrong class, though that wasn't causing any issues.

// This function MUST eventually call `NSApp.reply(toApplicationShouldTerminate: true)`
// or return `.terminateNow`
func applicationShouldTerminate(_: NSApplication) -> NSApplication.TerminateReply {
Expand Down
22 changes: 17 additions & 5 deletions Coder-Desktop/Coder-Desktop/VPN/VPNService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ enum VPNServiceState: Equatable {
case disconnecting
case connected
case failed(VPNServiceError)

var canBeStarted: Bool {
switch self {
// A tunnel failure should not prevent a reconnect attempt
case .disabled, .failed:
true
default:
false
}
}
}

enum VPNServiceError: Error, Equatable {
Expand Down Expand Up @@ -54,11 +64,18 @@ final class CoderVPNService: NSObject, VPNService {
guard neState == .enabled || neState == .disabled else {
return .failed(.networkExtensionError(neState))
}
if startWhenReady, tunnelState.canBeStarted {
startWhenReady = false
Task { await start() }
}
return tunnelState
}

@Published var menuState: VPNMenuState = .init()

// Whether the VPN should start as soon as possible
var startWhenReady: Bool = false

// systemExtnDelegate holds a reference to the SystemExtensionDelegate so that it doesn't get
// garbage collected while the OSSystemExtensionRequest is in flight, since the OS framework
// only stores a weak reference to the delegate.
Expand All @@ -68,11 +85,6 @@ final class CoderVPNService: NSObject, VPNService {

override init() {
super.init()
installSystemExtension()
}

deinit {
NotificationCenter.default.removeObserver(self)
}

func start() async {
Expand Down
6 changes: 6 additions & 0 deletions Coder-Desktop/Coder-DesktopTests/LoginFormTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ struct LoginTests {
data: [.get: Client.encoder.encode(buildInfo)]
).register()

try Mock(
url: url.appendingPathComponent("/api/v2/users/me"),
statusCode: 200,
data: [.get: Client.encoder.encode(User(id: UUID(), username: "username"))]
).register()

Comment on lines +110 to +115
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by fix: We need to mock this route as the token is validated before the server version.

try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
try view.find(ViewType.TextField.self).setInput(url.absoluteString)
Expand Down
Loading