diff --git a/Coder-Desktop/Coder-Desktop/VPN/NetworkExtension.swift b/Coder-Desktop/Coder-Desktop/VPN/NetworkExtension.swift index 7c90bd5..3f325cd 100644 --- a/Coder-Desktop/Coder-Desktop/VPN/NetworkExtension.swift +++ b/Coder-Desktop/Coder-Desktop/VPN/NetworkExtension.swift @@ -16,7 +16,7 @@ enum NetworkExtensionState: Equatable { case .disabled: "NetworkExtension tunnel disabled" case let .failed(error): - "NetworkExtension config failed: \(error)" + "NetworkExtension: \(error)" } } } @@ -44,7 +44,7 @@ extension CoderVPNService { try await removeNetworkExtension() } catch { logger.error("remove tunnel failed: \(error)") - neState = .failed(error.localizedDescription) + neState = .failed("Failed to remove configuration: \(error.description)") return } logger.debug("inserting new tunnel") @@ -60,7 +60,9 @@ extension CoderVPNService { } catch { // This typically fails when the user declines the permission dialog logger.error("save tunnel failed: \(error)") - neState = .failed("Failed to save tunnel: \(error.localizedDescription). Try logging in and out again.") + neState = .failed( + "Failed to save configuration: \(error.localizedDescription). Try logging in and out again." + ) } } @@ -71,17 +73,24 @@ extension CoderVPNService { try await tunnel.removeFromPreferences() } } catch { - throw .internalError("couldn't remove tunnels: \(error)") + throw .internalError(error.localizedDescription) } } func startTunnel() async { + let tm: NETunnelProviderManager + do { + tm = try await getTunnelManager() + } catch { + logger.error("get tunnel: \(error)") + neState = .failed("Failed to get VPN configuration: \(error.description)") + return + } do { - let tm = try await getTunnelManager() try tm.connection.startVPNTunnel() } catch { logger.error("start tunnel: \(error)") - neState = .failed(error.localizedDescription) + neState = .failed("Failed to start VPN tunnel: \(error.localizedDescription)") return } logger.debug("started tunnel") @@ -94,7 +103,7 @@ extension CoderVPNService { tm.connection.stopVPNTunnel() } catch { logger.error("stop tunnel: \(error)") - neState = .failed(error.localizedDescription) + neState = .failed("Failed to stop VPN tunnel: \(error.localizedDescription)") return } logger.debug("stopped tunnel") diff --git a/Coder-Desktop/Coder-Desktop/VPN/VPNService.swift b/Coder-Desktop/Coder-Desktop/VPN/VPNService.swift index 224174a..1bf4a84 100644 --- a/Coder-Desktop/Coder-Desktop/VPN/VPNService.swift +++ b/Coder-Desktop/Coder-Desktop/VPN/VPNService.swift @@ -37,7 +37,7 @@ enum VPNServiceError: Error, Equatable { case systemExtensionError(SystemExtensionState) case networkExtensionError(NetworkExtensionState) - var description: String { + public var description: String { switch self { case let .internalError(description): "Internal Error: \(description)" @@ -48,7 +48,7 @@ enum VPNServiceError: Error, Equatable { } } - var localizedDescription: String { description } + public var localizedDescription: String { description } } @MainActor @@ -126,13 +126,13 @@ final class CoderVPNService: NSObject, VPNService { // this just configures the VPN, it doesn't enable it tunnelState = .disabled } else { - do { + do throws(VPNServiceError) { try await removeNetworkExtension() neState = .unconfigured tunnelState = .disabled } catch { - logger.error("failed to remove network extension: \(error)") - neState = .failed(error.localizedDescription) + logger.error("failed to remove configuration: \(error)") + neState = .failed("Failed to remove configuration: \(error.description)") } } } diff --git a/Coder-Desktop/project.yml b/Coder-Desktop/project.yml index 166a157..f97ebdd 100644 --- a/Coder-Desktop/project.yml +++ b/Coder-Desktop/project.yml @@ -98,7 +98,7 @@ packages: # - Set onAppear/disappear handlers. # The upstream repo has a purposefully limited API url: https://github.com/coder/fluid-menu-bar-extra - revision: 8e1d8b8 + revision: b0d5438 KeychainAccess: url: https://github.com/kishikawakatsumi/KeychainAccess branch: e0c7eebc5a4465a3c4680764f26b7a61f567cdaf