From 6144786cf92ce2d2e2e15d7ea041bcc258186ad7 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 10 Apr 2024 18:43:24 -0700 Subject: [PATCH] Move all app settings to the settings bundle and link from the app settings view Add enter shortcut to alert ok buttons on the node list --- Meshtastic/Views/Nodes/NodeList.swift | 6 +- Meshtastic/Views/Settings/AppSettings.swift | 77 ++------------------- Meshtastic/Views/Settings/Channels.swift | 3 +- Settings.bundle/Root.plist | 72 +++++++++++++++++-- 4 files changed, 77 insertions(+), 81 deletions(-) diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index 4eb8b001..2c157ab2 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -146,7 +146,7 @@ struct NodeList: View { "Position Sent", isPresented: $isPresentingPositionSentAlert ) { - Button("OK", role: .cancel) { } + Button("OK") { }.keyboardShortcut(.defaultAction) } message: { Text("Your position has been sent with a request for a response with their position.") } @@ -154,7 +154,7 @@ struct NodeList: View { "Trace Route Sent", isPresented: $isPresentingTraceRouteSentAlert ) { - Button("OK", role: .cancel) { } + Button("OK") { }.keyboardShortcut(.defaultAction) } message: { Text("This could take a while, response will appear in the trace route log for the node it was sent to.") } @@ -162,7 +162,7 @@ struct NodeList: View { "Client History Request Sent", isPresented: $isPresentingClientHistorySentAlert ) { - Button("OK", role: .cancel) { } + Button("OK") { }.keyboardShortcut(.defaultAction) } message: { Text("Any missed messages will be delivered again.") } diff --git a/Meshtastic/Views/Settings/AppSettings.swift b/Meshtastic/Views/Settings/AppSettings.swift index 3693df1e..e614153a 100644 --- a/Meshtastic/Views/Settings/AppSettings.swift +++ b/Meshtastic/Views/Settings/AppSettings.swift @@ -10,55 +10,19 @@ struct AppSettings: View { @ObservedObject var tileManager = OfflineTileManager.shared @State var totalDownloadedTileSize = "" @StateObject var locationHelper = LocationHelper() - @State var provideLocation: Bool = UserDefaults.provideLocation - @State var enableSmartPosition: Bool = UserDefaults.enableSmartPosition - @State var newNodeNotifications: Bool = UserDefaults.newNodeNotifications - @State var useLegacyMap: Bool = UserDefaults.mapUseLegacy - @State var provideLocationInterval: Int = UserDefaults.provideLocationInterval @State private var isPresentingCoreDataResetConfirm = false @State private var isPresentingDeleteMapTilesConfirm = false var body: some View { VStack { Form { - Section(header: Text("Location Settings")) { - Toggle(isOn: $provideLocation) { - Label("appsettings.provide.location", systemImage: "location.circle.fill") - } - .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - Text("Use your phone's gps to provide a location to your node. Must have location access and precise location enabled for Meshtastic in Settings.") - .font(.caption2) - .foregroundColor(.gray) - if provideLocation { - Toggle(isOn: $enableSmartPosition) { - Label("appsettings.smartposition", systemImage: "brain") - Text("Will only send a position to the phone if it is recent and of high horizontal accuracy.") - .font(.caption2) - .foregroundColor(.gray) - } - .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - VStack { - Picker("update.interval", selection: $provideLocationInterval) { - ForEach(LocationUpdateInterval.allCases) { lu in - Text(lu.description) - } - } - .pickerStyle(DefaultPickerStyle()) - Text("phone.gps.interval.description") - .font(.caption2) - .foregroundColor(.gray) + Section(header: Text("App Settings")) { + Button("Open Settings", systemImage: "gear") { + // Get the settings URL and open it + if let url = URL(string: UIApplication.openSettingsURLString) { + UIApplication.shared.open(url) } } - Toggle(isOn: $useLegacyMap) { - Label("map.use.legacy", systemImage: "map") - } - .toggleStyle(SwitchToggleStyle(tint: .accentColor)) } - -// Section(header: Text("Notifications")){ -// Toggle(isOn: $newNodeNotifications){ -// Label("appsettings.newNodeNotifications", systemImage: "bell.fill") -// } -// } Section(header: Text("phone.gps")) { if #available(iOS 17.0, macOS 14.0, *) { GPSStatus() @@ -139,14 +103,6 @@ struct AppSettings: View { } } } - .onReceive( - NotificationCenter.default - .publisher(for: UserDefaults.didChangeNotification) - .receive(on: RunLoop.main) - ) { _ in - provideLocation = !UserDefaults.provideLocation - enableSmartPosition = UserDefaults.enableSmartPosition - } .onAppear(perform: { totalDownloadedTileSize = tileManager.getAllDownloadedSize() }) @@ -157,32 +113,9 @@ struct AppSettings: View { ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "?") }) .onAppear { - if provideLocationInterval <= 0 { - provideLocationInterval = 30 - UserDefaults.provideLocationInterval = provideLocationInterval - } if self.bleManager.context == nil { self.bleManager.context = context } } - .onChange(of: provideLocation) { newProvideLocation in - UserDefaults.provideLocation = newProvideLocation - if bleManager.connectedPeripheral != nil { - self.bleManager.sendWantConfig() - } - } - - .onChange(of: newNodeNotifications){ newNewNodeNotifications in - UserDefaults.newNodeNotifications = newNewNodeNotifications - } - .onChange(of: enableSmartPosition) { newEnableSmartPosition in - UserDefaults.enableSmartPosition = newEnableSmartPosition - } - .onChange(of: (provideLocationInterval)) { newProvideLocationInterval in - UserDefaults.provideLocationInterval = newProvideLocationInterval - } - .onChange(of: useLegacyMap) { newMapUseLegacy in - UserDefaults.mapUseLegacy = newMapUseLegacy - } } } diff --git a/Meshtastic/Views/Settings/Channels.swift b/Meshtastic/Views/Settings/Channels.swift index 5f0f44fc..a00ca073 100644 --- a/Meshtastic/Views/Settings/Channels.swift +++ b/Meshtastic/Views/Settings/Channels.swift @@ -231,8 +231,9 @@ struct Channels: View { Button { goBack() } label: { - Label("close", systemImage: "xmark") + Label("close me", systemImage: "xmark") } + .keyboardShortcut("w") .buttonStyle(.bordered) .buttonBorderShape(.capsule) .controlSize(.large) diff --git a/Settings.bundle/Root.plist b/Settings.bundle/Root.plist index 1591d7b2..5a04826b 100644 --- a/Settings.bundle/Root.plist +++ b/Settings.bundle/Root.plist @@ -8,19 +8,71 @@ Type - PSGroupSpecifier + PSToggleSwitchSpecifier Title - Notifications + Share Location + Key + provideLocation + DefaultValue + Type PSToggleSwitchSpecifier Title - New Nodes + Smart Position Key - newNodeNotifications + enableSmartPosition DefaultValue - + + + + Type + PSMultiValueSpecifier + Title + Location Interval + Key + provideLocationInterval + Values + + 10 + 15 + 30 + 45 + 60 + 300 + 600 + 900 + + Titles + + Ten Seconds + Fifteen Seconds + Thirty Seconds + Forty Five Seconds + One Minute + Five Minutes + Ten Minutes + Fifteen Minutes + + DefaultValue + Thirty Seconds + + + Type + PSToggleSwitchSpecifier + Title + Use Legacy Mesh Map + Key + mapUseLegacy + DefaultValue + + + + Type + PSGroupSpecifier + Title + Notifications Type @@ -32,6 +84,16 @@ DefaultValue + + Type + PSToggleSwitchSpecifier + Title + New Nodes + Key + newNodeNotifications + DefaultValue + +