2019-06-05 20:40:55 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import "cwtch.im/cwtch/event"
|
2020-02-10 22:09:24 +00:00
|
|
|
import "git.openprivacy.ca/openprivacy/log"
|
2019-06-05 20:40:55 +00:00
|
|
|
|
2019-07-19 17:27:50 +00:00
|
|
|
const (
|
|
|
|
// DestApp should be used as a destination for IPC messages that are for the application itself an not a peer
|
|
|
|
DestApp = "app"
|
|
|
|
)
|
|
|
|
|
2019-06-05 20:40:55 +00:00
|
|
|
type applicationBridge struct {
|
|
|
|
applicationCore
|
|
|
|
|
|
|
|
bridge event.IPCBridge
|
|
|
|
handle func(*event.Event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ab *applicationBridge) listen() {
|
|
|
|
log.Infoln("ab.listen()")
|
|
|
|
for {
|
|
|
|
ipcMessage, ok := ab.bridge.Read()
|
2019-07-10 20:30:24 +00:00
|
|
|
log.Debugf("listen() got %v for %v\n", ipcMessage.Message.EventType, ipcMessage.Dest)
|
2019-06-05 20:40:55 +00:00
|
|
|
if !ok {
|
2019-07-19 17:27:50 +00:00
|
|
|
log.Debugln("exiting appBridge.listen()")
|
2019-06-05 20:40:55 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ipcMessage.Dest == DestApp {
|
|
|
|
ab.handle(&ipcMessage.Message)
|
|
|
|
} else {
|
|
|
|
if eventBus, exists := ab.eventBuses[ipcMessage.Dest]; exists {
|
|
|
|
eventBus.PublishLocal(ipcMessage.Message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ab *applicationBridge) Shutdown() {
|
|
|
|
}
|