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
+24 -28
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,43 +625,36 @@ 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 let publicKeyData = self.encryptionService.publicKey.rawRepresentation
guard let self = self else { return } let packet = BitchatPacket(
type: MessageType.keyExchange.rawValue,
senderID: self.myPeerID.data(using: .utf8)!,
recipientID: nil,
timestamp: UInt64(Date().timeIntervalSince1970),
payload: try! JSONEncoder().encode(publicKeyData),
signature: nil,
ttl: 1
)
let publicKeyData = self.encryptionService.publicKey.rawRepresentation if let data = packet.data {
let packet = BitchatPacket( peripheral.writeValue(data, for: characteristic, type: .withResponse)
type: MessageType.keyExchange.rawValue, }
// Send announce packet immediately after key exchange
if let vm = self.delegate as? ChatViewModel {
let announcePacket = BitchatPacket(
type: MessageType.announce.rawValue,
senderID: self.myPeerID.data(using: .utf8)!, senderID: self.myPeerID.data(using: .utf8)!,
recipientID: nil, recipientID: nil,
timestamp: UInt64(Date().timeIntervalSince1970), timestamp: UInt64(Date().timeIntervalSince1970),
payload: try! JSONEncoder().encode(publicKeyData), payload: vm.nickname.data(using: .utf8)!,
signature: nil, signature: nil,
ttl: 1 ttl: 1
) )
if let data = announcePacket.data {
if let data = packet.data {
peripheral.writeValue(data, for: characteristic, type: .withResponse) peripheral.writeValue(data, for: characteristic, type: .withResponse)
} }
// Send announce packet immediately after key exchange
if let vm = self.delegate as? ChatViewModel {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let announcePacket = BitchatPacket(
type: MessageType.announce.rawValue,
senderID: self.myPeerID.data(using: .utf8)!,
recipientID: nil,
timestamp: UInt64(Date().timeIntervalSince1970),
payload: vm.nickname.data(using: .utf8)!,
signature: nil,
ttl: 1
)
if let data = announcePacket.data {
peripheral.writeValue(data, for: characteristic, type: .withResponse)
}
}
}
} }
} }
} }
+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]) {
+12 -7
View File
@@ -106,14 +106,15 @@ struct ContentView: View {
.opacity(0) .opacity(0)
} else { } else {
// Public chat header // Public chat header
Text("bitchat") HStack(spacing: 12) {
.font(.system(size: 18, weight: .medium, design: .monospaced)) Text("bitchat")
.foregroundColor(textColor) .font(.system(size: 18, weight: .medium, design: .monospaced))
.foregroundColor(textColor)
Spacer() // Peer status section
peerStatusView
// Peer status section .frame(maxWidth: 120)
peerStatusView }
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 {