mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
136 lines
3.1 KiB
Swift
136 lines
3.1 KiB
Swift
//
|
|
// UserDefaults.swift
|
|
// Meshtastic
|
|
//
|
|
// Copyright(c) Garth Vander Houwen 4/24/23.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension UserDefaults {
|
|
|
|
enum Keys: String, CaseIterable {
|
|
case meshtasticUsername
|
|
case preferredPeripheralId
|
|
case provideLocation
|
|
case provideLocationInterval
|
|
case mapLayer
|
|
case meshMapRecentering
|
|
case meshMapShowNodeHistory
|
|
case meshMapShowRouteLines
|
|
case enableOfflineMaps
|
|
case mapTileServer
|
|
case mapTilesAboveLabels
|
|
}
|
|
|
|
func reset() {
|
|
Keys.allCases.forEach { removeObject(forKey: $0.rawValue) }
|
|
}
|
|
|
|
static var meshtasticUsername: String {
|
|
get {
|
|
UserDefaults.standard.string(forKey: "meshtasticUsername") ?? ""
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "meshtasticUsername")
|
|
}
|
|
}
|
|
|
|
static var preferredPeripheralId: String {
|
|
get {
|
|
UserDefaults.standard.string(forKey: "preferredPeripheralId") ?? ""
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "preferredPeripheralId")
|
|
}
|
|
}
|
|
|
|
static var provideLocation: Bool {
|
|
get {
|
|
UserDefaults.standard.bool(forKey: "provideLocation")
|
|
} set {
|
|
UserDefaults.standard.set(newValue, forKey: "provideLocation")
|
|
}
|
|
}
|
|
|
|
static var provideLocationInterval: Int {
|
|
get {
|
|
UserDefaults.standard.integer(forKey: "provideLocationInterval")
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "provideLocationInterval")
|
|
}
|
|
}
|
|
|
|
static var mapLayer: MapLayer {
|
|
get {
|
|
MapLayer(rawValue: UserDefaults.standard.string(forKey: "mapLayer") ?? MapLayer.standard.rawValue) ?? MapLayer.standard
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue.rawValue, forKey: "mapLayer")
|
|
}
|
|
}
|
|
|
|
static var enableMapRecentering: Bool {
|
|
get {
|
|
UserDefaults.standard.bool(forKey: "meshMapRecentering")
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "meshMapRecentering")
|
|
}
|
|
}
|
|
|
|
static var enableMapNodeHistoryPins: Bool {
|
|
get {
|
|
UserDefaults.standard.bool(forKey: "meshMapShowNodeHistory")
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "meshMapShowNodeHistory")
|
|
}
|
|
}
|
|
|
|
static var enableMapRouteLines: Bool {
|
|
get {
|
|
UserDefaults.standard.bool(forKey: "meshMapShowRouteLines")
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "meshMapShowRouteLines")
|
|
}
|
|
}
|
|
|
|
static var enableOfflineMaps: Bool {
|
|
get {
|
|
UserDefaults.standard.bool(forKey: "enableOfflineMaps")
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "enableOfflineMaps")
|
|
}
|
|
}
|
|
static var enableOfflineMapsMBTiles: Bool {
|
|
get {
|
|
UserDefaults.standard.bool(forKey: "enableOfflineMapsMBTiles")
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "enableOfflineMapsMBTiles")
|
|
}
|
|
}
|
|
|
|
static var mapTileServer: MapTileServerLinks {
|
|
get {
|
|
|
|
MapTileServerLinks(rawValue: UserDefaults.standard.string(forKey: "mapTileServer") ?? MapTileServerLinks.openStreetMap.rawValue) ?? MapTileServerLinks.openStreetMap
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue.rawValue, forKey: "mapTileServer")
|
|
}
|
|
}
|
|
|
|
static var mapTilesAboveLabels: Bool {
|
|
get {
|
|
UserDefaults.standard.bool(forKey: "mapTilesAboveLabels")
|
|
}
|
|
set {
|
|
UserDefaults.standard.set(newValue, forKey: "mapTilesAboveLabels")
|
|
}
|
|
}
|
|
}
|