first pass of server functionality API #33
|
@ -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,12 +44,17 @@ 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() {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
if appServers == nil {
|
||||||
appServers.Stop()
|
appServers.Stop()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ServersFunctionality provides experiment gated server functionality
|
// ServersFunctionality provides experiment gated server functionality
|
||||||
type ServersFunctionality struct {
|
type ServersFunctionality struct {
|
||||||
|
|
22
lib.go
22
lib.go
|
@ -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()
|
||||||
|
|
Reference in New Issue