Skip to content

Commit dd9870f

Browse files
committed
add stop vpn on quit setting
1 parent cf9c422 commit dd9870f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Coder Desktop/Coder Desktop/Coder_DesktopApp.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
4747
}
4848
}
4949

50-
// MUST eventually call `NSApp.reply(toApplicationShouldTerminate: true)`
50+
// MUST eventually call `NSApp.reply(toApplicationShouldTerminate: true)`
51+
// or return `.terminateNow`
5152
func applicationShouldTerminate(_: NSApplication) -> NSApplication.TerminateReply {
53+
if !settings.stopVPNOnQuit { return .terminateNow }
5254
Task {
5355
await vpn.stop()
5456
NSApp.reply(toApplicationShouldTerminate: true)

Coder Desktop/Coder Desktop/State.swift

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class Settings: ObservableObject {
104104
}
105105
}
106106

107+
@AppStorage(Keys.stopVPNOnQuit) var stopVPNOnQuit = true
108+
107109
init(store: UserDefaults = .standard) {
108110
self.store = store
109111
_literalHeaders = Published(
@@ -116,6 +118,7 @@ class Settings: ObservableObject {
116118
enum Keys {
117119
static let useLiteralHeaders = "UseLiteralHeaders"
118120
static let literalHeaders = "LiteralHeaders"
121+
static let stopVPNOnQuit = "StopVPNOnQuit"
119122
}
120123
}
121124

Coder Desktop/Coder Desktop/Views/Settings/GeneralTab.swift

+6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import LaunchAtLogin
22
import SwiftUI
33

44
struct GeneralTab: View {
5+
@EnvironmentObject var settings: Settings
56
var body: some View {
67
Form {
78
Section {
89
LaunchAtLogin.Toggle("Launch at Login")
910
}
11+
Section {
12+
Toggle(isOn: $settings.stopVPNOnQuit) {
13+
Text("Stop VPN on Quit")
14+
}
15+
}
1016
}.formStyle(.grouped)
1117
}
1218
}

0 commit comments

Comments
 (0)