Use ACN events
This commit is contained in:
parent
3ba48d3bfd
commit
56b7aec403
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
6
main.go
6
main.go
|
@ -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)
|
||||
}
|
||||
|
|
Reference in New Issue