Fix peer dropdown layout and announcement timing

- Move peer dropdown next to bitchat title
- Add immediate peer announcement on connection
- Fix iOS menu chevron visibility with platform-specific styling
- Force UI updates for join/leave messages
- Add peers to active list immediately on connection
- Remove all announcement delays for instant name resolution
This commit is contained in:
jack
2025-07-02 21:39:31 +02:00
parent e50f14eeed
commit 1eaba703e9
3 changed files with 44 additions and 37 deletions
+4 -8
View File
@@ -559,6 +559,9 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
connectedPeripherals[peerID] = peripheral connectedPeripherals[peerID] = peripheral
print("[DEBUG] Connected to peer: \(peerID)") print("[DEBUG] Connected to peer: \(peerID)")
// Add to active peers immediately
activePeers.insert(peerID)
print("[DEBUG] Active peers: \(activePeers)") print("[DEBUG] Active peers: \(activePeers)")
// Update peer list to show we're connecting // Update peer list to show we're connecting
@@ -622,10 +625,7 @@ extension BluetoothMeshService: CBPeripheralDelegate {
peripheral.setNotifyValue(true, for: characteristic) peripheral.setNotifyValue(true, for: characteristic)
peripheralCharacteristics[peripheral] = characteristic peripheralCharacteristics[peripheral] = characteristic
// Send key exchange and announce immediately // Send key exchange and announce immediately without any delay
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let publicKeyData = self.encryptionService.publicKey.rawRepresentation let publicKeyData = self.encryptionService.publicKey.rawRepresentation
let packet = BitchatPacket( let packet = BitchatPacket(
type: MessageType.keyExchange.rawValue, type: MessageType.keyExchange.rawValue,
@@ -643,8 +643,6 @@ extension BluetoothMeshService: CBPeripheralDelegate {
// Send announce packet immediately after key exchange // Send announce packet immediately after key exchange
if let vm = self.delegate as? ChatViewModel { if let vm = self.delegate as? ChatViewModel {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let announcePacket = BitchatPacket( let announcePacket = BitchatPacket(
type: MessageType.announce.rawValue, type: MessageType.announce.rawValue,
senderID: self.myPeerID.data(using: .utf8)!, senderID: self.myPeerID.data(using: .utf8)!,
@@ -661,8 +659,6 @@ extension BluetoothMeshService: CBPeripheralDelegate {
} }
} }
} }
}
}
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
guard let data = characteristic.value, guard let data = characteristic.value,
+6
View File
@@ -252,6 +252,9 @@ extension ChatViewModel: BitchatDelegate {
) )
messages.append(systemMessage) messages.append(systemMessage)
print("[DEBUG] Added join message, total messages: \(messages.count)") print("[DEBUG] Added join message, total messages: \(messages.count)")
// Force UI update
objectWillChange.send()
} }
func didDisconnectFromPeer(_ peerID: String) { func didDisconnectFromPeer(_ peerID: String) {
@@ -265,6 +268,9 @@ extension ChatViewModel: BitchatDelegate {
) )
messages.append(systemMessage) messages.append(systemMessage)
print("[DEBUG] Added leave message, total messages: \(messages.count)") print("[DEBUG] Added leave message, total messages: \(messages.count)")
// Force UI update
objectWillChange.send()
} }
func didUpdatePeerList(_ peers: [String]) { func didUpdatePeerList(_ peers: [String]) {
+7 -2
View File
@@ -106,14 +106,15 @@ struct ContentView: View {
.opacity(0) .opacity(0)
} else { } else {
// Public chat header // Public chat header
HStack(spacing: 12) {
Text("bitchat") Text("bitchat")
.font(.system(size: 18, weight: .medium, design: .monospaced)) .font(.system(size: 18, weight: .medium, design: .monospaced))
.foregroundColor(textColor) .foregroundColor(textColor)
Spacer()
// Peer status section // Peer status section
peerStatusView peerStatusView
.frame(maxWidth: 120)
}
Spacer() Spacer()
@@ -188,7 +189,11 @@ struct ContentView: View {
} }
} }
} }
#if os(macOS)
.menuStyle(.borderlessButton) .menuStyle(.borderlessButton)
#else
.menuStyle(.automatic)
#endif
} }
private var messagesView: some View { private var messagesView: some View {