diff --git a/features/servers/servers_functionality.go b/features/servers/servers_functionality.go index 0f679d1..ff9cdbe 100644 --- a/features/servers/servers_functionality.go +++ b/features/servers/servers_functionality.go @@ -3,6 +3,7 @@ package servers import ( "cwtch.im/cwtch/event" "fmt" + "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" "git.openprivacy.ca/cwtch.im/server" "git.openprivacy.ca/openprivacy/connectivity" "path" @@ -43,11 +44,16 @@ func InitServers(acn connectivity.ACN, appdir string) { defer lock.Unlock() if appServers == nil { appServers = server.NewServers(acn, path.Join(appdir, "servers")) + appServers.LoadServers(constants.DefactoPasswordForUnencryptedProfiles) } } func DeactivateServers() { - appServers.Stop() + lock.Lock() + defer lock.Unlock() + if appServers == nil { + appServers.Stop() + } } // ServersFunctionality provides experiment gated server functionality diff --git a/lib.go b/lib.go index 6e0616c..2db08a3 100644 --- a/lib.go +++ b/lib.go @@ -214,7 +214,7 @@ func _startCwtch(appDir string, torPath string) { newApp.LoadProfiles(constants.DefactoPasswordForUnencryptedProfiles) application = newApp - LoadServers(constants.DefactoPasswordForUnencryptedProfiles) + publishLoadedServers() LaunchServers() // Send global settings to the UI... @@ -278,6 +278,16 @@ func ReconnectCwtchForeground() { } } + publishLoadedServers() + + settingsJson, _ := json.Marshal(settings) + application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) + application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{})) + application.QueryACNStatus() + application.QueryACNVersion() +} + +func publishLoadedServers() { serversHandler, err := servers.ExperimentGate(utils.ReadGlobalSettings().Experiments) if err == nil { serversList := serversHandler.ListServers() @@ -288,12 +298,6 @@ func ReconnectCwtchForeground() { application.GetPrimaryBus().Publish(ev) } } - - settingsJson, _ := json.Marshal(settings) - application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) - application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{})) - application.QueryACNStatus() - application.QueryACNVersion() } //export c_SendAppEvent @@ -325,10 +329,10 @@ func SendAppEvent(eventJson string) { settings := utils.ReadGlobalSettings() - serverHandler, err := servers.ExperimentGate(settings.Experiments) + _, err = servers.ExperimentGate(settings.Experiments) if err == nil { servers.InitServers(globalACN, globalAppDir) - serverHandler.LoadServers(constants.DefactoPasswordForUnencryptedProfiles) + publishLoadedServers() LaunchServers() } else { servers.DeactivateServers()