After add listener automatically trigger peer list change event (#1044)

In case of alway-on start the peer list was invalid on Android UI.
This commit is contained in:
Zoltan Papp 2023-08-04 14:14:08 +02:00 committed by GitHub
parent 0fc6c477a9
commit a0a6ced148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -17,6 +17,7 @@ type notifier struct {
listener Listener
currentClientState bool
lastNotification int
lastNumberOfPeers int
}
func newNotifier() *notifier {
@ -29,6 +30,7 @@ func (n *notifier) setListener(listener Listener) {
n.serverStateLock.Lock()
n.notifyListener(listener, n.lastNotification)
listener.OnPeersListChanged(n.lastNumberOfPeers)
n.serverStateLock.Unlock()
n.listener = listener
@ -124,6 +126,7 @@ func (n *notifier) calculateState(managementConn, signalConn bool) int {
}
func (n *notifier) peerListChanged(numOfPeers int) {
n.lastNumberOfPeers = numOfPeers
n.listenersLock.Lock()
defer n.listenersLock.Unlock()
if n.listener == nil {

View File

@ -353,9 +353,13 @@ func (d *Status) onConnectionChanged() {
}
func (d *Status) notifyPeerListChanged() {
d.notifier.peerListChanged(len(d.peers) + len(d.offlinePeers))
d.notifier.peerListChanged(d.numOfPeers())
}
func (d *Status) notifyAddressChanged() {
d.notifier.localAddressChanged(d.localPeer.FQDN, d.localPeer.IP)
}
func (d *Status) numOfPeers() int {
return len(d.peers) + len(d.offlinePeers)
}