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

Skip to content

Commit 748eb8c

Browse files
committed
chore: set 'stop VPN on quit' setting to true by default
1 parent 565665f commit 748eb8c

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)