From 48d1b1d837e5ee60c13be2d0b4b1b9fdde43d493 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 25 Feb 2022 18:13:12 -1000 Subject: [PATCH] Mac Specific disconnect button since swipe actions don't function on macOS --- Meshtastic Client.xcodeproj/project.pbxproj | 4 +- MeshtasticClient/Helpers/BLEManager.swift | 1 - .../Views/Bluetooth/Connect.swift | 42 +++++++++++++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 580ee094..90634861 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -738,7 +738,7 @@ CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; @@ -769,7 +769,7 @@ CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 13; DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 1a3831d8..50ba0728 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -920,7 +920,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph print("💥 Error Saving ACK for message MessageID \(decodedInfo.packet.id) Error: \(nsError)") } } - if meshLoggingEnabled { MeshLogger.log("ℹ️ MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") } print("ℹ️ MESH PACKET received for Routing App UNHANDLED \(try decodedInfo.packet.jsonString())") diff --git a/MeshtasticClient/Views/Bluetooth/Connect.swift b/MeshtasticClient/Views/Bluetooth/Connect.swift index 7acae4bd..2690da73 100644 --- a/MeshtasticClient/Views/Bluetooth/Connect.swift +++ b/MeshtasticClient/Views/Bluetooth/Connect.swift @@ -85,7 +85,7 @@ struct Connect: View { } Spacer() - VStack(alignment: .center) { + VStack(alignment: .trailing) { Text("Preferred").font(.caption2) Text("Radio").font(.caption2) @@ -109,14 +109,15 @@ struct Connect: View { } else { - if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.identifier.uuidString == userSettings.preferredPeripheralId { + if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.identifier.uuidString == userSettings.preferredPeripheralId { - userSettings.preferredPeripheralId = "" - userSettings.preferredPeripheralName = "" - } + userSettings.preferredPeripheralId = "" + userSettings.preferredPeripheralName = "" } } + } } + } .swipeActions { @@ -130,6 +131,8 @@ struct Connect: View { } } .padding([.top, .bottom]) + + } else { HStack { Image(systemName: "antenna.radiowaves.left.and.right.slash") @@ -196,7 +199,6 @@ struct Connect: View { .padding() .background(Color(.systemGray6)) .clipShape(Capsule()) - Spacer() Button(action: { self.bleManager.stopScanning() @@ -215,7 +217,33 @@ struct Connect: View { .padding() .background(Color(.systemGray6)) .clipShape(Capsule()) - Spacer() + + #if targetEnvironment(macCatalyst) + + if bleManager.connectedPeripheral != nil { + Button(role: .destructive, action: { + + if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected { + bleManager.disconnectPeripheral() + isPreferredRadio = false + } + + }) { + + Image(systemName: "antenna.radiowaves.left.and.right.slash") + .symbolRenderingMode(.hierarchical) + .imageScale(.large) + .foregroundColor(.red) + Text("Disconnect").font(.caption) + .font(.caption) + + } + .padding() + .background(Color(.systemGray6)) + .clipShape(Capsule()) + } + #endif + Spacer() } .padding(.bottom, 10)