Merge pull request #30 from garthvh/feature/messaging_updates

Feature/messaging updates Round 2
This commit is contained in:
Garth Vander Houwen 2022-01-10 18:28:50 -08:00 committed by GitHub
commit b7632d66fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 25 deletions

View file

@ -718,7 +718,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 13;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\"";
DEVELOPMENT_TEAM = GCH7VS5Y9R;
ENABLE_PREVIEWS = YES;
@ -746,7 +746,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 13;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\"";
DEVELOPMENT_TEAM = GCH7VS5Y9R;
ENABLE_PREVIEWS = YES;

View file

@ -120,9 +120,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
}
connectedPeripheral = nil
self.lastConnectionError = "🚫 BLE Connecting Timeout after making \(timeoutTimerCount) attempts to connect to \(name)."
print("🚫 BLE Connecting Timeout after making \(timeoutTimerCount) attempts to connect to \(name).")
if meshLoggingEnabled { MeshLogger.log("🚫 BLE Connecting Timeout after making \(timeoutTimerCount) attempts to connect to \(String(name)).") }
self.lastConnectionError = "🚨 BLE Connection Timeout after making \(timeoutTimerCount) attempts to connect to \(name)."
print("🚨 BLE Connection Timeout after making \(timeoutTimerCount) attempts to connect to \(name).")
if meshLoggingEnabled { MeshLogger.log("🚨 BLE Connection Timeout after making \(timeoutTimerCount) attempts to connect to \(String(name)). This can occur when a device has been taken out of BLE range, or if a device is already connected to another phone, tablet or computer.") }
self.timeoutTimerCount = 0
self.timeoutTimer?.invalidate()
@ -256,7 +256,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Happens when device is manually reset / powered off
// We will try and re-connect to this device
lastConnectionError = "🚫 \(e.localizedDescription) The app will automatically reconnect to the preferred radio if it reappears within 10 seconds."
lastConnectionError = "🚨 \(e.localizedDescription) The app will automatically reconnect to the preferred radio if it reappears within 10 seconds."
if peripheral.identifier.uuidString == UserDefaults.standard.object(forKey: "preferredPeripheralId") as? String ?? "" {
if meshLoggingEnabled { MeshLogger.log(" BLE Reconnecting: \(peripheral.name ?? "Unknown")") }
print(" BLE Reconnecting: \(peripheral.name ?? "Unknown")")
@ -267,20 +267,20 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Seems to be what is received when a tbeam sleeps, immediately recconnecting does not work.
lastConnectionError = e.localizedDescription
print("🚫 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)")
if meshLoggingEnabled { MeshLogger.log("🚫 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)") }
print("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)")
if meshLoggingEnabled { MeshLogger.log("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)") }
} else if errorCode == 14 { // Peer removed pairing information
// Forgetting and reconnecting seems to be necessary so we need to show the user an error telling them to do that
lastConnectionError = "🚫 \(e.localizedDescription) This error usually cannot be fixed without forgetting the device unders Settings > Bluetooth and re-connecting to the radio."
lastConnectionError = "🚨 \(e.localizedDescription) This error usually cannot be fixed without forgetting the device unders Settings > Bluetooth and re-connecting to the radio."
if meshLoggingEnabled { MeshLogger.log("🚫 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(lastConnectionError)") }
if meshLoggingEnabled { MeshLogger.log("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(lastConnectionError)") }
} else {
lastConnectionError = e.localizedDescription
print("🚫 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)")
if meshLoggingEnabled { MeshLogger.log("🚫 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)") }
print("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)")
if meshLoggingEnabled { MeshLogger.log("🚨 BLE Disconnected: \(peripheral.name ?? "Unknown") Error Code: \(errorCode) Error: \(e.localizedDescription)") }
}
} else {
@ -424,7 +424,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Swift does strings weird, this does work
let lastDotIndex = decodedInfo.myInfo.firmwareVersion.lastIndex(of: ".")//.lastIndex(of: ".", offsetBy: -1)
var version = decodedInfo.myInfo.firmwareVersion[...(lastDotIndex ?? String.Index(encodedOffset:6))]
var version = decodedInfo.myInfo.firmwareVersion[...(lastDotIndex ?? String.Index(utf16Offset: 6, in: decodedInfo.myInfo.firmwareVersion))]
version = version.dropLast()
myInfo.firmwareVersion = String(version)
lastConnnectionVersion = String(version)
@ -463,7 +463,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
fetchedMyInfo[0].hasGps = decodedInfo.myInfo.hasGps_p
fetchedMyInfo[0].numBands = Int32(bitPattern: decodedInfo.myInfo.numBands)
let lastDotIndex = decodedInfo.myInfo.firmwareVersion.lastIndex(of: ".")//.lastIndex(of: ".", offsetBy: -1)
var version = decodedInfo.myInfo.firmwareVersion[...(lastDotIndex ?? String.Index(encodedOffset:6))]
var version = decodedInfo.myInfo.firmwareVersion[...(lastDotIndex ?? String.Index(utf16Offset:6, in: decodedInfo.myInfo.firmwareVersion))]
version = version.dropLast()
fetchedMyInfo[0].firmwareVersion = String(version)
lastConnnectionVersion = String(version)
@ -670,9 +670,24 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
let newMessage = MessageEntity(context: context!)
newMessage.messageId = Int64(decodedInfo.packet.id)
newMessage.messageTimestamp = Int32(bitPattern: decodedInfo.packet.rxTime)
if decodedInfo.packet.rxTime == 0 {
newMessage.messageTimestamp = Int32(Date().timeIntervalSince1970)
} else {
newMessage.messageTimestamp = Int32(bitPattern: decodedInfo.packet.rxTime)
}
newMessage.receivedACK = false
newMessage.direction = "IN"
newMessage.isTapback = decodedInfo.packet.isTapback
if decodedInfo.packet.replyID > 0 {
newMessage.replyID = Int64(decodedInfo.packet.replyID)
}
if decodedInfo.packet.to == broadcastNodeNum && fetchedUsers.count == 1 {
@ -907,6 +922,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
print("🚫 Message Users Not Found, Fail")
success = false
} else if fetchedUsers.count >= 1 {
let newMessage = MessageEntity(context: context!)
@ -945,6 +961,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
var meshPacket = MeshPacket()
meshPacket.to = UInt32(toUserNum)
meshPacket.from = UInt32(fromUserNum)
meshPacket.isTapback = isTapback
if replyID > 0 {
meshPacket.replyID = UInt32(replyID)
}

View file

@ -179,12 +179,18 @@ struct Connect: View {
HStack(alignment: .center) {
Spacer()
Button(action: {
self.bleManager.startScanning()
}) {
Image(systemName: "play.fill").imageScale(.large).foregroundColor(.gray)
Image(systemName: "play.circle")
.symbolRenderingMode(.hierarchical)
.imageScale(.large)
.foregroundColor(self.bleManager.isScanning ? .gray : .accentColor)
Text("Start Scanning").font(.caption)
.font(.caption)
.foregroundColor(.gray)
}
.disabled(self.bleManager.isScanning)
.padding()
@ -192,12 +198,18 @@ struct Connect: View {
.clipShape(Capsule())
Spacer()
Button(action: {
self.bleManager.stopScanning()
}) {
Image(systemName: "stop.fill").imageScale(.large).foregroundColor(.gray)
Image(systemName: "stop.circle")
.symbolRenderingMode(.hierarchical)
.imageScale(.large)
.foregroundColor(!self.bleManager.isScanning ? .gray : .accentColor)
Text("Stop Scanning")
.font(.caption)
.foregroundColor(.gray)
}
.disabled(!self.bleManager.isScanning)
.padding()

View file

@ -24,7 +24,7 @@ struct Contacts: View {
List(users) { (user: UserEntity) in
let currentUserNum = self.bleManager.connectedPeripheral != nil ? self.bleManager.connectedPeripheral.num : 0
//let currentUserNum = self.bleManager.connectedPeripheral != nil ? self.bleManager.connectedPeripheral.num : 0
let allMessages = user.value(forKey: "allMessages") as! [MessageEntity]

View file

@ -310,9 +310,8 @@ struct UserMessageList: View {
self.bleManager.context = context
messageCount = ((user.sentMessages?.count ?? 0) + (user.receivedMessages?.count ?? 0))
if messageCount > 0 {
if allMessages.count > 2 {
scrollView.scrollTo(allMessages.firstIndex(of: allMessages.last! ), anchor: .bottom)
}
})
@ -325,7 +324,6 @@ struct UserMessageList: View {
if index > 2 {
scrollView.scrollTo(index, anchor: .bottom)
}
})
}

View file

@ -267,9 +267,10 @@ struct NodeDetail: View {
}
}
.edgesIgnoringSafeArea([.leading, .trailing])
.padding(1)
}
}
.navigationTitle(node.user!.longName ?? "Unknown")
.navigationTitle(node != nil ? String(node.user!.longName ?? "Unknown") : "Unknown")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing: