From 75111e0421ae2bf74149cd4062ff2a54e11086e5 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 21 Jun 2019 14:58:40 -0700 Subject: [PATCH] port from cwtch.app to appClient and appService --- android/AndroidManifest.xml | 4 +- go/characters/torstatuspoller.go | 3 ++ go/the/globals.go | 2 + main.go | 72 ++++++++++++++++++++++---------- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index ad2b8849..5c222929 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,7 +1,9 @@ - + diff --git a/go/characters/torstatuspoller.go b/go/characters/torstatuspoller.go index 135f441d..9fe7950c 100644 --- a/go/characters/torstatuspoller.go +++ b/go/characters/torstatuspoller.go @@ -6,6 +6,9 @@ import ( ) func TorStatusPoller(setTorStatus func(int, string), acn connectivity.ACN) { + if acn == nil { + return + } for { time.Sleep(time.Second) diff --git a/go/the/globals.go b/go/the/globals.go index 2d75bd7c..a4239d08 100644 --- a/go/the/globals.go +++ b/go/the/globals.go @@ -8,11 +8,13 @@ import ( ) var CwtchApp app.Application +var CwtchService app.ApplicationService var EventBus event.Manager var AppBus event.Manager var ACN connectivity.ACN var Peer libPeer.CwtchPeer var CwtchDir string +var IPCBridge event.IPCBridge type AckId struct { ID string diff --git a/main.go b/main.go index ed6327a8..9ee3c276 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( libapp "cwtch.im/cwtch/app" + "cwtch.im/cwtch/event/bridge" "cwtch.im/ui/go/characters" "cwtch.im/ui/go/gobjects" "cwtch.im/ui/go/gothings" @@ -20,7 +21,6 @@ import ( "path" "path/filepath" "runtime" - "time" ) const androidBaseDir = "/data/data/ca.openprivacy.cwtch.ui/" @@ -48,6 +48,12 @@ func main() { log.SetLevel(log.LevelInfo) } + // TESTING + log.SetLevel(log.LevelDebug) + log.ExcludeFromPattern("connection/connection") + log.ExcludeFromPattern("outbound/3dhauthchannel") + log.ExcludeFromPattern("event/eventmanager") + if os.Getenv("CWTCH_FOLDER") != "" { the.CwtchDir = os.Getenv("CWTCH_FOLDER") } else if runtime.GOOS == "android" { @@ -61,6 +67,11 @@ func main() { the.CwtchDir = path.Join(usr.HomeDir, ".cwtch") } the.ACN = nil + the.Peer = nil + the.IPCBridge = nil + the.CwtchApp = nil + the.CwtchService = nil + os.MkdirAll(the.CwtchDir, 0700) if *flagService { mainService() @@ -76,15 +87,14 @@ func main() { func mainService() { log.Infoln("I am the service") - loadACN() log.Infoln("Starting a cwtch app...") - the.CwtchApp = libapp.NewApp(the.ACN, the.CwtchDir) + go loadNetworkingAndFiles(nil, true) + + //app := androidextras.NewQAndroidService(len(os.Args), os.Args) + app := gui.NewQGuiApplication(len(os.Args), os.Args) + log.Infoln("Cwtch Service starting app.Exec") + app.Exec() - log.Infoln("Sleepinging???") - for true { - time.Sleep(5 * time.Second) - log.Infoln("Wake up, repeat") - } } func mainUi(flagLocal bool) { @@ -160,13 +170,11 @@ func mainUi(flagLocal bool) { var androidCwtchActivity = android.NewCwtchActivity(nil) engine.RootContext().SetContextProperty("androidCwtchActivity", androidCwtchActivity) - //engine.addImportPath(QStringLiteral("qrc:/")); - //engine.load(QUrl(QStringLiteral("qrc:/source/qml/main.qml"))); - engine.Load(qmlSource) - go loadNetworkingAndFiles(gcd) + go loadNetworkingAndFiles(gcd, false) + log.Infoln("Cwtch App starting app.Exec") app.Exec() } @@ -199,17 +207,37 @@ func loadACN() { } } -func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher) { - if runtime.GOOS != "android" { +func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher, service bool) { + if runtime.GOOS == "android" { + clientIn := path.Join(the.CwtchDir, "clientIn") + serviceIn := path.Join(the.CwtchDir, "serviceIn") + if service { + loadACN() + serviceBridge, err := bridge.NewPipeBridgeService(serviceIn, clientIn) + if err != nil { + log.Errorf("Could not create service bridge: %v\n", err) + os.Exit(1) + } + 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) + } + log.Infoln("Creating New App Client") + the.CwtchApp = libapp.NewAppClient(the.CwtchDir, clientBridge) + } + } else { loadACN() + log.Infoln("Creating New App") + the.CwtchApp = libapp.NewApp(the.ACN, the.CwtchDir) } - the.Peer = nil - - os.MkdirAll(the.CwtchDir, 0700) - - the.CwtchApp = libapp.NewApp(the.ACN, the.CwtchDir) - the.AppBus = the.CwtchApp.GetPrimaryBus() - go characters.AppEventListener(gcd) - the.CwtchApp.LoadProfiles("be gay do crime") + if !service { + the.AppBus = the.CwtchApp.GetPrimaryBus() + go characters.AppEventListener(gcd) + the.CwtchApp.LoadProfiles("be gay do crime") + } } -- 2.25.1