process fixes for android
This commit is contained in:
parent
e09e9c09a7
commit
001470257a
30
lib.go
30
lib.go
|
@ -67,9 +67,10 @@ func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) int8 {
|
|||
// message: CwtchStarted when start up is complete and app is safe to use
|
||||
// CwtchStartError message when start up fails (includes event.Error data field)
|
||||
func StartCwtch(appDir string, torPath string) int {
|
||||
eventHandler = utils.NewEventHandler()
|
||||
log.SetLevel(log.LevelInfo)
|
||||
|
||||
|
||||
log.Infof("StartCwtch(...)")
|
||||
// Quick hack check that we're being called with the correct params
|
||||
// On android a stale worker could be calling us with "last apps" directory. Best to abort fast so the app can make a new worker
|
||||
if runtime.GOOS == "android" {
|
||||
|
@ -86,13 +87,16 @@ func StartCwtch(appDir string, torPath string) int {
|
|||
}
|
||||
|
||||
func _startCwtch(appDir string, torPath string) {
|
||||
log.Infof("application: %v eventHandler: %v acn: %v", application, eventHandler, globalACN)
|
||||
|
||||
if application != nil {
|
||||
log.Infof("_startCwtch detected existing application; resuming instead of relaunching")
|
||||
ReconnectCwtchForeground()
|
||||
return
|
||||
}
|
||||
|
||||
// Exclude Tapir wire Messages (We need a TRACE level)
|
||||
// Exclude Tapir wire Messages
|
||||
//(We need a TRACE level)
|
||||
log.ExcludeFromPattern("service.go")
|
||||
|
||||
// Ensure that the application directory exists...and then initialize settings..
|
||||
|
@ -112,6 +116,9 @@ func _startCwtch(appDir string, torPath string) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
log.Infof("Creating new EventHandler()")
|
||||
eventHandler = utils.NewEventHandler()
|
||||
|
||||
log.Infof("making directory %v", appDir)
|
||||
os.MkdirAll(path.Join(appDir, "/.tor", "tor"), 0700)
|
||||
tor.NewTorrc().WithSocksPort(port).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)).Build(filepath.Join(appDir, ".tor", "tor", "torrc"))
|
||||
|
@ -167,6 +174,7 @@ func c_ReconnectCwtchForeground() {
|
|||
// Like StartCwtch, but StartCwtch has already been called so we don't need to restart Tor etc (probably)
|
||||
// Do need to re-send initial state tho, eg profiles that are already loaded
|
||||
func ReconnectCwtchForeground() {
|
||||
log.Infof("Reconnecting cwtchforeground")
|
||||
if application == nil {
|
||||
log.Errorf("ReconnectCwtchForeground: Application is nil, presuming stale thread, EXITING Reconnect\n")
|
||||
return
|
||||
|
@ -338,10 +346,18 @@ func c_GetAppBusEvent() *C.char {
|
|||
|
||||
// GetAppBusEvent blocks until an event
|
||||
func GetAppBusEvent() string {
|
||||
log.Infof("appbusevent called")
|
||||
for eventHandler == nil {
|
||||
log.Infof("waiting for eventHandler != nil")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
var json = ""
|
||||
for json == "" {
|
||||
log.Infof("waiting for json != ''")
|
||||
json = eventHandler.GetNextEvent()
|
||||
}
|
||||
log.Infof("appbusevent: %v", json)
|
||||
return json
|
||||
}
|
||||
|
||||
|
@ -701,11 +717,15 @@ func ShutdownCwtch() {
|
|||
eventHandler.Push(event.NewEvent(event.Shutdown, map[event.Field]string{}))
|
||||
|
||||
// Allow for the shutdown events to go through and then purge everything else...
|
||||
log.Debugf("Shutting Down Application...")
|
||||
log.Infof("Shutting Down Application...")
|
||||
application.Shutdown()
|
||||
log.Debugf("Shutting Down ACN...")
|
||||
log.Infof("Shutting Down ACN...")
|
||||
globalACN.Close()
|
||||
log.Debugf("Library Shutdown Complete!")
|
||||
log.Infof("Library Shutdown Complete!")
|
||||
// do not remove - important for state checks elsewhere
|
||||
application = nil
|
||||
globalACN = nil
|
||||
eventHandler = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ func (eh *EventHandler) GetNextEvent() string {
|
|||
// handleAppBusEvent enriches AppBus events so they are usable with out further data fetches
|
||||
func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||
log.Debugf("New AppBus Event to Handle: %v", e)
|
||||
if eh.app != nil {
|
||||
switch e.EventType {
|
||||
case event.ACNStatus:
|
||||
if e.Data[event.Progress] == "100" {
|
||||
|
@ -209,6 +210,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
|
||||
log.Infof("contactsJson %v", e.Data["ContactsJson"])
|
||||
}
|
||||
}
|
||||
|
||||
json, _ := json.Marshal(e)
|
||||
return string(json)
|
||||
|
@ -216,7 +218,9 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
|
||||
// handleProfileEvent enriches Profile events so they are usable with out further data fetches
|
||||
func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||
|
||||
if eh.app == nil {
|
||||
log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?")
|
||||
} else {
|
||||
peer := eh.app.GetPeer(ev.Profile)
|
||||
ph := NewPeerHelper(peer)
|
||||
log.Debugf("New Profile Event to Handle: %v", ev)
|
||||
|
@ -304,6 +308,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json, _ := json.Marshal(unwrap(ev))
|
||||
return string(json)
|
||||
|
|
Loading…
Reference in New Issue