From f485e372a7b6b9fb2c11676ae9f66927b1665da1 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 17 Apr 2023 10:48:58 -0700 Subject: [PATCH] ReconnectCwtchForeground should reload Profiles --- templates/lib_template.go | 11 ++++++++++- utils/eventHandler.go | 9 +++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/templates/lib_template.go b/templates/lib_template.go index c962d54..ed66281 100644 --- a/templates/lib_template.go +++ b/templates/lib_template.go @@ -232,7 +232,16 @@ func ReconnectCwtchForeground() { return } - // TODO: Need To Repopulate UI + // Repopulate the UI on Android by iterating through all loaded profiles and treating them as New Peer loads. The ReloadEvent field + // suppresses any listen/connection actions and simply sends updated attributes to the UI. + // The UI is designed in such a way that "NewPeer" events are treated as updates. + // TODO: if/when we break apart NewPeer into smaller chunks for the UI to fetch, the need to do this here will go away. + peerList := application.ListProfiles() + for _, onion := range peerList { + eventHandler.Push(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: onion, utils.ReloadEvent: event.True})) + } + + settingsJson, _ := json.Marshal(application.ReadSettings()) application.GetPrimaryBus().Publish(event.NewEvent(settings.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 03fe29d..4d23285 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -30,11 +30,6 @@ type EventProfileEnvelope struct { Profile string } -type LCG_API_Handler struct { - LaunchServers func() - StopServers func() -} - type EventHandler struct { app app.Application appBusQueue event.Queue @@ -46,6 +41,8 @@ type EventHandlerInterface interface { OnACNStatusEvent(appl app.Application, e *event.Event) } +const ReloadEvent = event.Field("Reload") + // We should be reading from profile events pretty quickly, but we make this buffer fairly large... const profileEventsBufferSize = 512 @@ -143,7 +140,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { } log.Debug("New Peer Event: %v", e) - if e.Data["Reload"] != event.True { + if e.Data[ReloadEvent] != event.True { eh.startHandlingPeer(onion) }