Skip to content

feat: add start vpn on launch setting #108

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 18, 2025
Merged
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
3 changes: 3 additions & 0 deletions Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift
Original file line number Diff line number Diff line change
@@ -58,6 +58,9 @@ 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 {
8 changes: 8 additions & 0 deletions Coder-Desktop/Coder-Desktop/State.swift
Original file line number Diff line number Diff line change
@@ -54,6 +54,13 @@ class AppState: ObservableObject {
}
}

@Published var startVPNOnLaunch: Bool = UserDefaults.standard.bool(forKey: Keys.startVPNOnLaunch) {
didSet {
guard persistent else { return }
UserDefaults.standard.set(startVPNOnLaunch, forKey: Keys.startVPNOnLaunch)
}
}

func tunnelProviderProtocol() -> NETunnelProviderProtocol? {
if !hasSession { return nil }
let proto = NETunnelProviderProtocol()
@@ -133,6 +140,7 @@ class AppState: ObservableObject {
static let useLiteralHeaders = "UseLiteralHeaders"
static let literalHeaders = "LiteralHeaders"
static let stopVPNOnQuit = "StopVPNOnQuit"
static let startVPNOnLaunch = "StartVPNOnLaunch"
}
}

9 changes: 7 additions & 2 deletions Coder-Desktop/Coder-Desktop/Views/Settings/GeneralTab.swift
Original file line number Diff line number Diff line change
@@ -6,11 +6,16 @@ struct GeneralTab: View {
var body: some View {
Form {
Section {
LaunchAtLogin.Toggle("Launch at Login")
LaunchAtLogin.Toggle("Launch at login")
}
Section {
Toggle(isOn: $state.stopVPNOnQuit) {
Text("Stop Coder Connect on Quit")
Text("Stop Coder Connect on quit")
}
}
Section {
Toggle(isOn: $state.startVPNOnLaunch) {
Text("Start Coder Connect on launch")
}
}
}.formStyle(.grouped)