port from cwtch.app to appClient and appService

This commit is contained in:
Dan Ballard 2019-06-21 14:58:40 -07:00
parent 9400d5aa63
commit 75111e0421
4 changed files with 58 additions and 23 deletions

View File

@ -1,7 +1,9 @@
<?xml version="1.0"?>
<manifest package="ca.openprivacy.cwtch.ui" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="cwtch" android:icon="@drawable/ic_launcher">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="ca.openprivacy.cwtch.ui.CwtchActivity" android:label="cwtch" android:theme="@style/AppTheme" android:screenOrientation="unspecified" android:launchMode="singleTop" android:windowSoftInputMode="adjustResize">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation"
android:name="ca.openprivacy.cwtch.ui.CwtchActivity"
android:label="cwtch" android:theme="@style/AppTheme" android:screenOrientation="unspecified" android:launchMode="singleTop" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>

View File

@ -6,6 +6,9 @@ import (
)
func TorStatusPoller(setTorStatus func(int, string), acn connectivity.ACN) {
if acn == nil {
return
}
for {
time.Sleep(time.Second)

View File

@ -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

72
main.go
View File

@ -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")
}
}