Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37d7e35

Browse files
chore: set 'stop VPN on quit' setting to true by default (#155)
It's fair to assume if you're closing Coder Desktop, you want Coder Connect to stop, so this is the default behaviour. Tailscale also stops their VPN when quitting the app, even though it works fine with the app closed.
1 parent 314edbe commit 37d7e35

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Coder-Desktop/Coder-Desktop/State.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class AppState: ObservableObject {
5555
}
5656
}
5757

58-
@Published var stopVPNOnQuit: Bool = UserDefaults.standard.bool(forKey: Keys.stopVPNOnQuit) {
58+
// Defaults to `true`
59+
@Published var stopVPNOnQuit: Bool = UserDefaults.standard.optionalBool(forKey: Keys.stopVPNOnQuit) ?? true {
5960
didSet {
6061
guard persistent else { return }
6162
UserDefaults.standard.set(stopVPNOnQuit, forKey: Keys.stopVPNOnQuit)
@@ -239,3 +240,14 @@ extension LiteralHeader {
239240
.init(name: name, value: value)
240241
}
241242
}
243+
244+
extension UserDefaults {
245+
// Unlike the exisitng `bool(forKey:)` method which returns `false` for both
246+
// missing values this method can return `nil`.
247+
func optionalBool(forKey key: String) -> Bool? {
248+
guard object(forKey: key) != nil else {
249+
return nil
250+
}
251+
return bool(forKey: key)
252+
}
253+
}

0 commit comments

Comments
 (0)