Meshtastic-Apple/Meshtastic/Helpers/LocationsHandler.swift

304 lines
13 KiB
Swift
Raw Normal View History

//
// LocationsHandler.swift
// Meshtastic
//
// Copyright Garth Vander Houwen 12/4/23.
//
import SwiftUI
import CoreLocation
2024-06-03 02:17:55 -07:00
import OSLog
// The @MainActor annotation ensures that all state changes and UI updates happen on the main thread,
// preventing potential race conditions and crashes related to UI updates from background threads.
2025-07-14 20:27:02 -07:00
@MainActor class LocationsHandler: NSObject, ObservableObject, @preconcurrency CLLocationManagerDelegate {
static let shared = LocationsHandler() // Create a single, shared instance of the object.
2025-07-14 20:27:02 -07:00
public var manager = CLLocationManager()
private var background: CLBackgroundActivitySession?
var enableSmartPosition: Bool = UserDefaults.enableSmartPosition
2025-07-14 20:27:02 -07:00
@Published var locationsArray: [CLLocation] = [CLLocation]()
@Published var isStationary = false
@Published var count = 0
@Published var isRecording = false
@Published var isRecordingPaused = false
@Published var recordingStarted: Date?
@Published var distanceTraveled = 0.0
@Published var elevationGain = 0.0
@Published var heading: Double = 0.0 // Current heading in degrees
@Published var headingUpdatesStarted: Bool = false // Track heading updates state
@Published
var updatesStarted: Bool = UserDefaults.standard.bool(forKey: "liveUpdatesStarted") {
didSet { UserDefaults.standard.set(updatesStarted, forKey: "liveUpdatesStarted") }
}
@Published
var backgroundActivity: Bool = UserDefaults.standard.bool(forKey: "BGActivitySessionStarted") {
didSet {
// Invalidate or create the background activity session based on the new value.
backgroundActivity ? self.background = CLBackgroundActivitySession() : self.background?.invalidate()
UserDefaults.standard.set(backgroundActivity, forKey: "BGActivitySessionStarted")
}
}
2025-05-03 20:44:12 -07:00
// The continuation we will use to asynchronously ask the user permission to track their location.
// This is an Optional to ensure it can be nilled out after use.
2025-07-14 20:27:02 -07:00
private var permissionContinuation: CheckedContinuation<CLAuthorizationStatus, Never>?
// A flag to prevent multiple concurrent permission requests
private var isRequestingPermission = false
/// Requests "Always" location authorization from the user.
/// This method uses Swift's structured concurrency to await the user's decision.
/// It includes a timeout to prevent continuation leaks if the delegate method isn't called.
/// - Returns: The `CLAuthorizationStatus` reflecting the user's choice.
2025-05-03 20:44:12 -07:00
func requestLocationAlwaysPermissions() async -> CLAuthorizationStatus {
// If a request is already in progress, return the current status immediately.
// This prevents creating multiple continuations and potential leaks.
guard !isRequestingPermission else {
Logger.services.debug("📍 [App] requestLocationAlwaysPermissions called while a request is already active. Returning current status.")
return manager.authorizationStatus
}
// Set flag to indicate a request is in progress
isRequestingPermission = true
2025-05-03 20:44:12 -07:00
return await withCheckedContinuation { continuation in
// Store the continuation.
2025-07-14 20:27:02 -07:00
self.permissionContinuation = continuation
// Request authorization. The response will come via `locationManagerDidChangeAuthorization`.
2025-07-14 20:27:02 -07:00
manager.requestAlwaysAuthorization()
// Add a timeout to ensure the continuation is always resumed.
// If the delegate method doesn't fire within a reasonable time (e.g., 10 seconds),
// we'll resume the continuation with .notDetermined to prevent a leak.
Task { @MainActor in // Ensure this task runs on the MainActor
do {
2.7.3 Working Changes (#1404) * Remove non functional module override button * Remove stale keys * Onboarding and lora config bug fixes * Add Annotations view and try and simplify online annimations to improve performance. * Bump version * Fix proto bug * Don't show ignored nodes on the mesh map * More node annotation animation improvements * Ham * Remove liquid glass form icon * Update MQTT config logic * Liquid glass chirpy and ham on the watch * Use Hops away value for DM's (#1409) * Set hopLimit for DM messages (DM's and Exchange position) to the hops away value for the node you are sending to. * Update Meshtastic/Accessory/Accessory Manager/AccessoryManager+ToRadio.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Icons * 🐰 * DataDog action logging (#1411) Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Update location usage details * Good doggo (#1414) * DataDog action logging * Filter version hash --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Update Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Helpers/LocationsHandler.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Nodes/Helpers/Map/MapContent/AnimatedNodePin.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: jake-b <1012393+jake-b@users.noreply.github.com> Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
2025-09-18 13:19:45 -07:00
try await Task.sleep(for: .seconds(5)) // Wait for 5 seconds
if let currentContinuation = self.permissionContinuation {
// If the continuation hasn't been nilled out yet, it means
// locationManagerDidChangeAuthorization hasn't been called.
Logger.services.warning("📍 [App] Location permission request timed out. Resuming continuation with .notDetermined.")
2.7.3 Working Changes (#1404) * Remove non functional module override button * Remove stale keys * Onboarding and lora config bug fixes * Add Annotations view and try and simplify online annimations to improve performance. * Bump version * Fix proto bug * Don't show ignored nodes on the mesh map * More node annotation animation improvements * Ham * Remove liquid glass form icon * Update MQTT config logic * Liquid glass chirpy and ham on the watch * Use Hops away value for DM's (#1409) * Set hopLimit for DM messages (DM's and Exchange position) to the hops away value for the node you are sending to. * Update Meshtastic/Accessory/Accessory Manager/AccessoryManager+ToRadio.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Icons * 🐰 * DataDog action logging (#1411) Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Update location usage details * Good doggo (#1414) * DataDog action logging * Filter version hash --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Update Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Helpers/LocationsHandler.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Nodes/Helpers/Map/MapContent/AnimatedNodePin.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: jake-b <1012393+jake-b@users.noreply.github.com> Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
2025-09-18 13:19:45 -07:00
currentContinuation.resume(returning: .denied)
self.permissionContinuation = nil // Clear the reference
}
} catch is CancellationError {
// This task was cancelled, likely because the main continuation was already resumed
// by locationManagerDidChangeAuthorization. This is expected and safe.
Logger.services.debug("📍 [App] Permission timeout task cancelled.")
} catch {
Logger.services.error("💥 [App] Error in permission timeout task: \(error.localizedDescription, privacy: .public)")
}
}
}
// This defer block ensures `isRequestingPermission` is reset and `permissionContinuation` is nilled out
// regardless of how the `withCheckedContinuation` block exits (success, error, or cancellation).
// It acts as a final cleanup mechanism.
defer {
self.isRequestingPermission = false
// This nil assignment is somewhat redundant with the one in locationManagerDidChangeAuthorization
// and the timeout Task, but it provides an extra layer of safety.
self.permissionContinuation = nil
2025-05-03 20:44:12 -07:00
}
}
/// Delegate method called when the location authorization status changes.
/// - Parameter manager: The CLLocationManager instance.
2025-07-14 20:27:02 -07:00
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
// Ensure the continuation exists before attempting to resume it.
// If it's nil, it means either no request was pending or it was already resumed (e.g., by the timeout).
guard let continuation = permissionContinuation else {
Logger.services.debug("📍 [App] locationManagerDidChangeAuthorization called but no permissionContinuation is active or it was already handled.")
return
}
// Resume the continuation with the current authorization status.
continuation.resume(returning: manager.authorizationStatus)
// CRUCIAL: Nil out the continuation immediately after resuming it.
// This prevents attempting to resume the same continuation multiple times,
// which would lead to a runtime crash.
self.permissionContinuation = nil
self.isRequestingPermission = false // Reset the flag as the request has completed
2025-07-14 20:27:02 -07:00
}
2025-07-14 20:27:02 -07:00
override init() {
super.init()
self.manager.delegate = self
// Allow background location updates for continuous tracking.
self.manager.allowsBackgroundLocationUpdates = true
// Set desired accuracy for location updates.
// Consider your app's needs: kCLLocationAccuracyBestForNavigation, kCLLocationAccuracyBest, etc.
// For general tracking, kCLLocationAccuracyHundredMeters might be sufficient to save battery.
self.manager.desiredAccuracy = kCLLocationAccuracyBest
// Set the distance filter to only receive updates when the device has moved a certain distance.
self.manager.distanceFilter = kCLDistanceFilterNone // Receive all updates initially
if CLLocationManager.headingAvailable() {
self.manager.headingFilter = 1 // Update heading when it changes by 1 degree
self.manager.headingOrientation = .portrait // Adjust based on device orientation
}
}
func startLocationUpdates() {
2025-05-03 20:44:12 -07:00
let status = self.manager.authorizationStatus
// Guard against starting updates without proper authorization.
2025-05-03 20:44:12 -07:00
guard status == .authorizedAlways || status == .authorizedWhenInUse else {
Logger.services.warning("📍 [App] Cannot start location updates: insufficient authorization status: \(status.rawValue)")
2025-05-03 20:44:12 -07:00
return
}
2024-06-23 16:11:02 -07:00
Logger.services.info("📍 [App] Starting location updates")
// Using a Task for asynchronous operations. The @MainActor isolation of the class
// ensures that all state changes within this Task (accessing @Published properties)
// will be performed on the main actor.
Task { @MainActor in
do {
self.updatesStarted = true
// `liveUpdates()` provides a stream of location updates.
let updates = CLLocationUpdate.liveUpdates()
for try await update in updates {
// Check for task cancellation to allow graceful stopping.
try Task.checkCancellation()
// If `updatesStarted` is set to false (e.g., by `stopLocationUpdates`),
// break out of the loop to stop processing updates.
if !self.updatesStarted {
Logger.services.info("🛑 [App] Location updates loop stopped due to updatesStarted being false.")
break
}
if let loc = update.location {
self.isStationary = update.isStationary
let locationAdded = addLocation(loc, smartPostion: enableSmartPosition)
if !isRecording && locationAdded {
self.count = 1
} else if locationAdded && isRecording {
2023-12-27 12:45:46 -08:00
self.count += 1
}
}
}
} catch is CancellationError {
// Handle explicit task cancellation gracefully.
Logger.services.info("📍 [App] Location updates task was cancelled.")
} catch {
// Catch any other errors during location updates.
2025-03-31 22:06:00 -07:00
Logger.services.error("💥 [App] Could not start location updates: \(error.localizedDescription, privacy: .public)")
}
// The Task completes implicitly here.
}
}
// New method to start heading updates
func startHeadingUpdates() {
guard CLLocationManager.headingAvailable() else {
Logger.services.warning("📍 [App] Heading updates not available on this device.")
return
}
guard manager.authorizationStatus == .authorizedAlways || manager.authorizationStatus == .authorizedWhenInUse else {
Logger.services.warning("📍 [App] Cannot start heading updates: insufficient authorization status.")
return
}
Logger.services.info("📍 [App] Starting heading updates")
manager.startUpdatingHeading()
headingUpdatesStarted = true
}
// New method to stop heading updates
func stopHeadingUpdates() {
Logger.services.info("🛑 [App] Stopping heading updates")
manager.stopUpdatingHeading()
headingUpdatesStarted = false
}
// Implement the CLLocationManagerDelegate method for heading updates
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
// Update heading on the main thread
Task { @MainActor in
self.heading = newHeading.trueHeading >= 0 ? newHeading.trueHeading : newHeading.magneticHeading
}
}
/// Stops receiving live location updates.
func stopLocationUpdates() {
2024-06-23 16:11:02 -07:00
Logger.services.info("🛑 [App] Stopping location updates")
// Setting `updatesStarted` to false will cause the `liveUpdates()` loop to break.
self.updatesStarted = false
}
/// Adds a location to the array and updates tracking metrics, applying smart position filters if enabled.
/// - Parameters:
/// - location: The `CLLocation` object to add.
/// - smartPostion: A boolean indicating whether to apply smart position filtering.
/// - Returns: `true` if the location was added, `false` if it was filtered out by smart position.
func addLocation(_ location: CLLocation, smartPostion: Bool) -> Bool {
if smartPostion {
let age = -location.timestamp.timeIntervalSinceNow
if age > 10 {
2025-04-01 17:33:39 -07:00
Logger.services.info("📍 [App] Smart Position - Bad Location: Too Old \(age, privacy: .public) seconds ago \(location, privacy: .private(mask: .none))")
return false
}
if location.horizontalAccuracy < 0 {
2025-03-31 23:11:40 -07:00
Logger.services.info("📍 [App] Smart Position - Bad Location: Horizontal Accuracy: \(location.horizontalAccuracy) \(location, privacy: .private(mask: .none))")
return false
}
// Consider adjusting this threshold based on your needs. 5 meters is quite strict.
2024-04-11 19:30:05 -07:00
if location.horizontalAccuracy > 5 {
2025-03-31 23:11:40 -07:00
Logger.services.info("📍 [App] Smart Position - Bad Location: Horizontal Accuracy: \(location.horizontalAccuracy) \(location, privacy: .private(mask: .none))")
return false
}
}
if isRecording {
2024-01-21 12:24:18 -08:00
if let lastLocation = locationsArray.last {
let distance = location.distance(from: lastLocation)
let gain = location.altitude - lastLocation.altitude
distanceTraveled += distance
if gain > 0 {
elevationGain += gain
}
}
locationsArray.append(location)
} else {
// If not recording, only keep the latest location.
locationsArray = [location]
}
return true
}
// Default location (Apple Park) used as a fallback.
Transports Interface to Support TCP for all Platforms and Serial on Mac (#1341) * Initial implementation of transports * Initial LogRadio implementation * Fixes for Settings view (caused by debug commenting) * Refinement of the object and actor model * Connect view text and tab updates * Fix mac catalyst and tests * Warning and logging clean-up * In progress commit * Serial Transport and Reconnect draft work * Serial transport and reconnection draft work * Quick fix for BLE - still more work to do * interim commit * More in progress changes * Minor improvements * Pretty good initial implementation * Bump version beyond the app store * Fix for disconnection swipeAction * Tweaks to TCPConnection implementation * Retry for NONCE_ONLY_DB * Revert json string change * Simplified some of the API + "Anti-discovery" * Tweaks for devices leaving the discovery process * Bump version * iOS26 Tweaks * Tweaks and bug fixes * Add link with slash sf symbol * update symbol image on connect view * BLE disconnect handling * Log privacy attributes * Onboarding and minor fixes. * change database to nodes, add emoji to tcp logs * Error handling improvements * More logging emojis * Suppressed unnecessary errors on disconnect * Heartbeat emoji * Add bluetooth symbol * add privacy attributes to [TCP] logs, add custom bluetooth logo * Improve routing logs * Emoji for connect logs * Heartbeat emoji * Add CBCentralManagerScanOptionAllowDuplicatesKey options to central for bluetooth * fix nav errors by switching from observableobject to state * Update connection indicator icon * fix for BLE disconnects * Connection process fixes * More fixes/tweaks to connection process * Strict concurrency * Fix some warnings, remove wifi warning * delete stale keys * interim commit * Update privacy for log, fix wrong space * fix a couple of linting items * Switch to targeted * interim commit * BLE Signal strenth on connect view * Remove BLE RSSI from long press menu * Modem lights * minor spacing tweak * Additional BLE logging and a scanning fix. * Discovery and BLE RSSI improvements * Background suspension * Update isConnected to enable UI during db load * update protobufs * Replace config if statements with switches, Fix unknown module config logging, make dark mode modem circle stroke color white so they are visible * Additional logging cleanup * hast * Set unmessagable to true if the longname has the unmessagable emoji * Connect error handling improvements * Admin popup list icon and activity lights updates * Revert use of .toolbar back to .navigationBarItems * More public logging * Better BLE error handling * Node DB progress meter * minor tweak to activity light interaction timing * Fix comment linting, remove stale keys * Remove stale keys * Easy linting fixes * Two more simple linting fixes * clean up meshtasticapp * More public logging * Replay config * Logging * Fix for unselected node on Settings * Tweak to progress meter based on device idiom * Update protos * Session replay redaction of messages * Serial fix for old devices, and a let statement * Mask text too * Fix typo * BLE poweredOff is now an auto-reconnectable error * Update logging * Fix for peerRemovedPairingInformation * Logging for BLE peripheral:didUpdateValueFor errors. * Fix for inconsistent swipe disconnect behavior * periperal:didUpdateValueFor error handling * Fix for BLEConnection continuation guarding * BLEConnection actor deadlock on disconnect * Heartbeat nonce * Fix for swipe disconnect and task cancellation * Fix for swipe actions not honoring .disabled() * Tell BLETransport when BLEConnection is cancelled * Update navigation logging * Logging updates * Bump version to 2.7.0 * Organize into folders and heartbeat stuff * Minor improvements to manual TCP connection * Auto-connect toggle * Possible BLE bug, still waiting to see in logs * Concurrency tweaks * Concurrency improvements * requestDeviceMetadata fix. fixes remote admin * Minor typo fixes * "All" button for log filters: category and level * More robust continuation handling for BLE * @FetchRequest based ChannelMessageList * Update info.plist and device hardware file * Move auto connect toggle to app settings and debug mode, tint properly with the accent color * Add label to auto connect toggle * Update log for node info received from ourselves over the mesh * Remove unused scrollViewProxy * Update Meshtastic/Views/Onboarding/DeviceOnboarding.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update target for connect view * Properly Set datadog environment * Comment out ble manager * Adjust cyclomatic complexity thresholds in .swiftlint.yml * Linting fixes, delete ble manager * Make session replay debug only --------- Co-authored-by: jake-b <jake-b@users.noreply.github.com> Co-authored-by: jake <jake@jakes-Mac-mini.local> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-27 08:09:02 -07:00
// nonisolated because it is never mutated
nonisolated static let DefaultLocation = CLLocationCoordinate2D(latitude: 37.3346, longitude: -122.0090)
/// Provides the current location, falling back to last known or a default if necessary.
2.7.4 Working Changes (#1415) * Update messaging list separator insets * Dont show unread messages or notifications for emoji reactions matching iMessage. * Restore ble state method (#1416) * Restore BLE State * Log privacy * AccessoryManager to handle restored connection * Comment task out * Update restore state function based on conversation with jake * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Two Column Node List (#1425) * Restore BLE State * Log privacy * AccessoryManager to handle restored connection * Comment task out * Switch the node list to a two column layout * Keep asian translations of channel details string * Update restore state function based on conversation with jake * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * always show node list search bar * Update auto correct modifier * Dont show online animations for ios 17, remove online animation from node map, remove online circle from position popover * Work in progress. * Update detents * Gate the discovery process while restoring * Use geometry reader to size weather tiles on node details * Update BLE Transport * Update location weather condistion styles * Log privacy in didReceive * Remove extra dividers from admin key config, fix onboarding typo * Bump minimum catalyst target * Bump mac target version * Use @FetchRequest for UserList to try and use less memory on ios 17 * Revert change to @fetchrequest * Stab in the dark for Devices crash * Updated UserList (back?) to @FetchRequest * Set mac minimum to 15 * Nil out continuation after use * Use @FetchRequest for the node list to stop crashes on iOS 17 * Handle failed connections during restoration --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update protos * Update protos * Remove stale keys * Serbian translations update (#1422) * Log privacy * Add Serbian translations --------- Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com> * Clarify public key sub-text in security settings (#1412) * Clarify public key sub-text in settings * Trigger lint * freq slot num pad (#1410) * kill keyboard toolbar on lora config * delete extranious scrollDismissesKeyboard * Properly set catalyst target * Update Meshtastic/Views/Onboarding/DeviceOnboarding.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Settings/Config/SecurityConfig.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Enums/DeviceEnums.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Make current location nilable, remove log spam * clean up toUser logic * Fix telemetry entity not added in nodeInfoPacket * fix typo: powerMetrics.hasChXCurrent mismatch * Duplicate decoding of telemetry.current removed * Clean up mesh map fetch request and distance filter logic * Revert attempt to fix message logic * Bump datadog version * Missing message fix, attempt #2 (#1431) Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Retry fewer times for longer * Revert "Missing message fix, attempt #2 (#1431)" (#1432) This reverts commit a96d318adb476eccc624a460fcdc7fb92aa9edbb. * Make retry 2 seconds * Add back link to node details from position popover without navigation stack and link, clear notifications when deleting database * Add clear notifications function * Link from channel messages to node info * Link to node details * Discovery on retry fix * Discovery on retry fix fix * Add contact to device node db if you get an encrypted send faild routing error * Seperate channel message view into two views for better performance. * Refactor User Message List * Update device hardware Add liquid glass to config save button * Save button cleanup * Update button structure on users view * Move encrypted send logic out of the router. Update protos * Restore node long- and short- names (#1442) Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLEConnection.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert routing error * Toggle for enabling device telemetry broadcast enable * Update * Enhancements for interval dropdowns (#1445) * Cleanup * Fix core data version * Add never to update interval * Device telemetry Enabled Boolean (#1446) * Update core data and interval picker * Move formatter * Rework to nest options under enabled * Clearer names * Safer devicehardware api call, remove node history filter from mesh map * Fix build * Simplify mesh map filter * Remove stale translation keys --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Nikola Dašić <dasic.nikola@yandex.com> Co-authored-by: Spencer Smith <dontaskspencer@gmail.com> Co-authored-by: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
2025-10-05 17:51:18 -07:00
static var currentLocation: CLLocationCoordinate2D? {
// Attempt to get the most recent location from the manager.
if let location = shared.manager.location {
return location.coordinate
} else {
2.7.4 Working Changes (#1415) * Update messaging list separator insets * Dont show unread messages or notifications for emoji reactions matching iMessage. * Restore ble state method (#1416) * Restore BLE State * Log privacy * AccessoryManager to handle restored connection * Comment task out * Update restore state function based on conversation with jake * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Two Column Node List (#1425) * Restore BLE State * Log privacy * AccessoryManager to handle restored connection * Comment task out * Switch the node list to a two column layout * Keep asian translations of channel details string * Update restore state function based on conversation with jake * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLETransport.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * always show node list search bar * Update auto correct modifier * Dont show online animations for ios 17, remove online animation from node map, remove online circle from position popover * Work in progress. * Update detents * Gate the discovery process while restoring * Use geometry reader to size weather tiles on node details * Update BLE Transport * Update location weather condistion styles * Log privacy in didReceive * Remove extra dividers from admin key config, fix onboarding typo * Bump minimum catalyst target * Bump mac target version * Use @FetchRequest for UserList to try and use less memory on ios 17 * Revert change to @fetchrequest * Stab in the dark for Devices crash * Updated UserList (back?) to @FetchRequest * Set mac minimum to 15 * Nil out continuation after use * Use @FetchRequest for the node list to stop crashes on iOS 17 * Handle failed connections during restoration --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update protos * Update protos * Remove stale keys * Serbian translations update (#1422) * Log privacy * Add Serbian translations --------- Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com> * Clarify public key sub-text in security settings (#1412) * Clarify public key sub-text in settings * Trigger lint * freq slot num pad (#1410) * kill keyboard toolbar on lora config * delete extranious scrollDismissesKeyboard * Properly set catalyst target * Update Meshtastic/Views/Onboarding/DeviceOnboarding.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Views/Settings/Config/SecurityConfig.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Meshtastic/Enums/DeviceEnums.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Make current location nilable, remove log spam * clean up toUser logic * Fix telemetry entity not added in nodeInfoPacket * fix typo: powerMetrics.hasChXCurrent mismatch * Duplicate decoding of telemetry.current removed * Clean up mesh map fetch request and distance filter logic * Revert attempt to fix message logic * Bump datadog version * Missing message fix, attempt #2 (#1431) Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Retry fewer times for longer * Revert "Missing message fix, attempt #2 (#1431)" (#1432) This reverts commit a96d318adb476eccc624a460fcdc7fb92aa9edbb. * Make retry 2 seconds * Add back link to node details from position popover without navigation stack and link, clear notifications when deleting database * Add clear notifications function * Link from channel messages to node info * Link to node details * Discovery on retry fix * Discovery on retry fix fix * Add contact to device node db if you get an encrypted send faild routing error * Seperate channel message view into two views for better performance. * Refactor User Message List * Update device hardware Add liquid glass to config save button * Save button cleanup * Update button structure on users view * Move encrypted send logic out of the router. Update protos * Restore node long- and short- names (#1442) Co-authored-by: Jake-B <jake-b@users.noreply.github.com> * Update Meshtastic/Accessory/Transports/Bluetooth Low Energy/BLEConnection.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Revert routing error * Toggle for enabling device telemetry broadcast enable * Update * Enhancements for interval dropdowns (#1445) * Cleanup * Fix core data version * Add never to update interval * Device telemetry Enabled Boolean (#1446) * Update core data and interval picker * Move formatter * Rework to nest options under enabled * Clearer names * Safer devicehardware api call, remove node history filter from mesh map * Fix build * Simplify mesh map filter * Remove stale translation keys --------- Co-authored-by: Jake-B <jake-b@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Nikola Dašić <dasic.nikola@yandex.com> Co-authored-by: Spencer Smith <dontaskspencer@gmail.com> Co-authored-by: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
2025-10-05 17:51:18 -07:00
return nil
2025-01-21 09:19:14 -08:00
}
}
/// Estimates the number of satellites in view based on horizontal and vertical accuracy.
/// This is a heuristic and not a direct report of satellite count.
static var satsInView: Int {
2023-12-23 22:47:56 -08:00
var sats = 0
2024-01-21 12:24:18 -08:00
if let newLocation = shared.locationsArray.last {
sats = 1
if newLocation.verticalAccuracy > 0 {
sats = 4
if 0...5 ~= newLocation.horizontalAccuracy {
sats = 12
} else if 6...15 ~= newLocation.horizontalAccuracy {
sats = 10
} else if 16...30 ~= newLocation.horizontalAccuracy {
sats = 9
} else if 31...45 ~= newLocation.horizontalAccuracy {
sats = 7
} else if 46...60 ~= newLocation.horizontalAccuracy {
sats = 5
}
} else if newLocation.verticalAccuracy < 0 && 60...300 ~= newLocation.horizontalAccuracy {
sats = 3
} else if newLocation.verticalAccuracy < 0 && newLocation.horizontalAccuracy > 300 {
sats = 2
}
}
return sats
}
}