Clean up user defaults

This commit is contained in:
Garth Vander Houwen 2023-05-06 16:50:41 -07:00
parent e1bf4b0212
commit fa08cf8959
3 changed files with 5 additions and 37 deletions

View file

@ -10,12 +10,10 @@ import Foundation
extension UserDefaults {
enum Keys: String, CaseIterable {
case hasBeenLaunched
case meshtasticUsername
case preferredPeripheralId
case provideLocation
case provideLocationInterval
//case meshMapType
case meshMapRecentering
case meshMapShowNodeHistory
case meshMapShowRouteLines
@ -27,16 +25,6 @@ extension UserDefaults {
Keys.allCases.forEach { removeObject(forKey: $0.rawValue) }
}
static var hasBeenLaunched: Bool {
get {
let result = UserDefaults.standard.bool(forKey: "hasBeenLaunched")
UserDefaults.standard.set(true, forKey: "hasBeenLaunched")
return result
} set {
UserDefaults.standard.set(newValue, forKey: "hasBeenLaunched")
}
}
static var meshtasticUsername: String {
get {
UserDefaults.standard.string(forKey: "meshtasticUsername") ?? ""
@ -57,9 +45,7 @@ extension UserDefaults {
static var provideLocation: Bool {
get {
let result = UserDefaults.standard.bool(forKey: "provideLocation")
UserDefaults.standard.set(true, forKey: "provideLocation")
return result
UserDefaults.standard.bool(forKey: "provideLocation")
} set {
UserDefaults.standard.set(newValue, forKey: "provideLocation")
}
@ -74,15 +60,6 @@ extension UserDefaults {
}
}
// static var mapType: Int {
// get {
// UserDefaults.standard.integer(forKey: "meshMapType")
// }
// set {
// UserDefaults.standard.set(newValue, forKey: "meshMapType")
// }
// }
static var mapLayer: MapLayer {
get {
MapLayer(rawValue: UserDefaults.standard.string(forKey: "mapLayer") ?? MapLayer.standard.rawValue) ?? MapLayer.standard

View file

@ -222,7 +222,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
}
/// Set selected map layer
// setOverlays(mapView: mapView)
setOverlays(mapView: mapView)
let annotationCount = waypoints.count + (showNodeHistory ? positions.count : latest.count)
if annotationCount != mapView.annotations.count {
@ -274,11 +274,6 @@ struct MapViewSwiftUI: UIViewRepresentable {
self.parent.mapView.addGestureRecognizer(longPressRecognizer)
}
func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) {
//print (mapView.visibleMapRect)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
switch annotation {
@ -448,7 +443,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
}
public func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
switch overlay {
case let overlay as MKTileOverlay:
return MKTileOverlayRenderer(tileOverlay: overlay)

View file

@ -60,10 +60,6 @@ struct AppSettings: View {
Label("provide.location", systemImage: "location.circle.fill")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.onTapGesture {
self.provideLocation.toggle()
UserDefaults.provideLocation = self.provideLocation
}
if UserDefaults.provideLocation {
@ -119,8 +115,8 @@ struct AppSettings: View {
.onChange(of: (meshtasticUsername)) { newMeshtasticUsername in
UserDefaults.meshtasticUsername = newMeshtasticUsername
}
.onChange(of: provideLocation) { _ in
.onChange(of: provideLocation) { newProvideLocation in
UserDefaults.provideLocation = newProvideLocation
if bleManager.connectedPeripheral != nil {
self.bleManager.sendWantConfig()
}