Skip to content

Commit e04f61a

Browse files
committed
thinking
1 parent 5dea75f commit e04f61a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
4141

4242
override init() {
4343
vpn = CoderVPNService()
44-
state = AppState(onChange: vpn.configureTunnelProviderProtocol)
44+
let state = AppState(onChange: vpn.configureTunnelProviderProtocol)
45+
vpn.onStart = {
46+
// We don't need this to have finished before the VPN actually starts
47+
Task { await state.refreshDeploymentConfig() }
48+
}
4549
if state.startVPNOnLaunch {
4650
vpn.startWhenReady = true
4751
}
52+
self.state = state
4853
vpn.installSystemExtension()
4954
#if arch(arm64)
5055
let mutagenBinary = "mutagen-darwin-arm64"
@@ -65,12 +70,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6570
title: "Coder Desktop",
6671
image: "MenuBarIcon",
6772
onAppear: {
68-
// If the VPN is enabled, it's likely the token hasn't expired,
69-
// and the deployment config is up to date.
73+
// If the VPN is enabled, it's likely the token isn't expired
7074
guard case .disabled = self.vpn.state, self.state.hasSession else { return }
7175
Task { @MainActor in
7276
await self.state.handleTokenExpiry()
73-
await self.state.refreshDeploymentConfig()
7477
}
7578
}, content: {
7679
VPNMenu<CoderVPNService, MutagenDaemon>().frame(width: 256)

Coder-Desktop/Coder-Desktop/VPN/VPNService.swift

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ final class CoderVPNService: NSObject, VPNService {
7676

7777
// Whether the VPN should start as soon as possible
7878
var startWhenReady: Bool = false
79+
var onStart: (() -> Void)?
7980

8081
// systemExtnDelegate holds a reference to the SystemExtensionDelegate so that it doesn't get
8182
// garbage collected while the OSSystemExtensionRequest is in flight, since the OS framework
@@ -96,6 +97,8 @@ final class CoderVPNService: NSObject, VPNService {
9697
return
9798
}
9899

100+
onStart?()
101+
99102
menuState.clear()
100103
await startTunnel()
101104
logger.debug("network extension enabled")

0 commit comments

Comments
 (0)