From 49fef3f800e0f3da5f047f08c5a56eddaebc66c4 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 1 Aug 2019 21:45:58 -0700 Subject: [PATCH] Use QAndroidService to properly have the service run on Android --- android/AndroidManifest.xml | 2 +- main.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 5c222929..9e64880d 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -110,7 +110,7 @@ - + diff --git a/main.go b/main.go index 919df035..dc539239 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "flag" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/log" + "github.com/therecipe/qt/androidextras" "github.com/therecipe/qt/core" "github.com/therecipe/qt/gui" "github.com/therecipe/qt/network" @@ -87,12 +88,23 @@ func main() { } } +// QRunnable is a shim for QAndroidService and QGuiApplication +type QRunnable interface { + Exec() int +} + func mainService() { log.Infoln("I am the service") log.Infoln("Starting a cwtch app...") go loadNetworkingAndFiles(nil, true, false) - //app := androidextras.NewQAndroidService(len(os.Args), os.Args) - app := gui.NewQGuiApplication(len(os.Args), os.Args) + var app QRunnable + if runtime.GOOS == "android" { + log.Infoln("Making QAndroidService...") + app = androidextras.NewQAndroidService(len(os.Args), os.Args) + } else { + log.Infoln("Making QGuiApplication...") + app = gui.NewQGuiApplication(len(os.Args), os.Args) + } log.Infoln("Cwtch Service starting app.Exec") app.Exec() }