Use ACN events

This commit is contained in:
Dan Ballard 2019-07-10 13:38:56 -07:00
parent 3ba48d3bfd
commit 56b7aec403
3 changed files with 22 additions and 37 deletions

View File

@ -8,6 +8,7 @@ import (
"cwtch.im/ui/go/the"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"os"
"strconv"
)
func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
@ -15,11 +16,30 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
the.AppBus.Subscribe(event.NewPeer, q.EventChannel)
the.AppBus.Subscribe(event.PeerError, q.EventChannel)
the.AppBus.Subscribe(event.AppError, q.EventChannel)
the.AppBus.Subscribe(event.ACNStatus, q.EventChannel)
for {
e := q.Next()
switch e.EventType {
case event.ACNStatus:
progStr := e.Data[event.Progreess]
percent, _ := strconv.Atoi(progStr)
message := e.Data[event.Status]
var statuscode int
if percent == 0 {
statuscode = 0
message = "can't find tor. is it running? is the controlport configured?"
} else if percent == 100 {
statuscode = 3
message = "tor appears to be running just fine!"
} else if percent < 80 {
statuscode = 1
} else {
statuscode = 2
}
gcd.TorStatus(statuscode, message)
case event.PeerError:
// current only case
log.Errorf("couldn't load profiles: %v", e.Data[event.Error])
@ -28,6 +48,7 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
case event.AppError:
if e.Data[event.Error] == event.AppErrLoaded0 {
// TODO: only an error if other profiles are not loaded
log.Infoln("couldn't load your config file. attempting to create one now")
the.CwtchApp.CreatePeer("alice", "be gay do crime")
@ -83,7 +104,6 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
}
}
go IncomingListener(&gcd.UIState)
go TorStatusPoller(gcd.TorStatus, the.ACN)
go PresencePoller(&gcd.UIState)
// load ui preferences

View File

@ -1,31 +0,0 @@
package characters
import (
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"time"
)
func TorStatusPoller(setTorStatus func(int, string), acn connectivity.ACN) {
if acn == nil {
return
}
for {
time.Sleep(time.Second)
percent, message := acn.GetBootstrapStatus()
var statuscode int
if percent == 0 {
statuscode = 0
message = "can't find tor. is it running? is the controlport configured?"
} else if percent == 100 {
statuscode = 3
message = "tor appears to be running just fine!"
} else if percent < 80 {
statuscode = 1
} else {
statuscode = 2
}
setTorStatus(statuscode, message)
}
}

View File

@ -222,11 +222,7 @@ func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher, service bool,
log.Infoln("Creating New App Service")
the.CwtchService = libapp.NewAppService(the.ACN, the.CwtchDir, serviceBridge)
} else {
clientBridge, err := bridge.NewPipeBridgeClient(clientIn, serviceIn)
if err != nil {
log.Errorf("Could not create client bridge: %v\n", err)
os.Exit(1)
}
clientBridge := bridge.NewPipeBridgeClient(clientIn, serviceIn)
log.Infoln("Creating New App Client")
the.CwtchApp = libapp.NewAppClient(the.CwtchDir, clientBridge)
}