better support reloading servers on experiment enable/disable
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dan Ballard 2021-11-01 19:36:14 -07:00
parent 063ad61e36
commit f3b753827f
2 changed files with 20 additions and 10 deletions

View File

@ -3,6 +3,7 @@ package servers
import ( import (
"cwtch.im/cwtch/event" "cwtch.im/cwtch/event"
"fmt" "fmt"
"git.openprivacy.ca/cwtch.im/libcwtch-go/constants"
"git.openprivacy.ca/cwtch.im/server" "git.openprivacy.ca/cwtch.im/server"
"git.openprivacy.ca/openprivacy/connectivity" "git.openprivacy.ca/openprivacy/connectivity"
"path" "path"
@ -43,11 +44,16 @@ func InitServers(acn connectivity.ACN, appdir string) {
defer lock.Unlock() defer lock.Unlock()
if appServers == nil { if appServers == nil {
appServers = server.NewServers(acn, path.Join(appdir, "servers")) appServers = server.NewServers(acn, path.Join(appdir, "servers"))
appServers.LoadServers(constants.DefactoPasswordForUnencryptedProfiles)
} }
} }
func DeactivateServers() { func DeactivateServers() {
appServers.Stop() lock.Lock()
defer lock.Unlock()
if appServers == nil {
appServers.Stop()
}
} }
// ServersFunctionality provides experiment gated server functionality // ServersFunctionality provides experiment gated server functionality

22
lib.go
View File

@ -214,7 +214,7 @@ func _startCwtch(appDir string, torPath string) {
newApp.LoadProfiles(constants.DefactoPasswordForUnencryptedProfiles) newApp.LoadProfiles(constants.DefactoPasswordForUnencryptedProfiles)
application = newApp application = newApp
LoadServers(constants.DefactoPasswordForUnencryptedProfiles) publishLoadedServers()
LaunchServers() LaunchServers()
// Send global settings to the UI... // 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) serversHandler, err := servers.ExperimentGate(utils.ReadGlobalSettings().Experiments)
if err == nil { if err == nil {
serversList := serversHandler.ListServers() serversList := serversHandler.ListServers()
@ -288,12 +298,6 @@ func ReconnectCwtchForeground() {
application.GetPrimaryBus().Publish(ev) 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 //export c_SendAppEvent
@ -325,10 +329,10 @@ func SendAppEvent(eventJson string) {
settings := utils.ReadGlobalSettings() settings := utils.ReadGlobalSettings()
serverHandler, err := servers.ExperimentGate(settings.Experiments) _, err = servers.ExperimentGate(settings.Experiments)
if err == nil { if err == nil {
servers.InitServers(globalACN, globalAppDir) servers.InitServers(globalACN, globalAppDir)
serverHandler.LoadServers(constants.DefactoPasswordForUnencryptedProfiles) publishLoadedServers()
LaunchServers() LaunchServers()
} else { } else {
servers.DeactivateServers() servers.DeactivateServers()