File tree 1 file changed +13
-1
lines changed
Coder-Desktop/Coder-Desktop
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ class AppState: ObservableObject {
55
55
}
56
56
}
57
57
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 {
59
60
didSet {
60
61
guard persistent else { return }
61
62
UserDefaults . standard. set ( stopVPNOnQuit, forKey: Keys . stopVPNOnQuit)
@@ -239,3 +240,14 @@ extension LiteralHeader {
239
240
. init( name: name, value: value)
240
241
}
241
242
}
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
+ }
You can’t perform that action at this time.
0 commit comments