File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Coder-Desktop/Coder-Desktop Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments