Use QAndroidService to properly have the service run on Android

This commit is contained in:
Dan Ballard 2019-08-01 21:45:58 -07:00
parent 3c9abe2a0b
commit 49fef3f800
2 changed files with 15 additions and 3 deletions

View File

@ -110,7 +110,7 @@
</application>
<uses-sdk android:minSdkVersion="16" /> <!-- android:targetSdkVersion="26"/> -->
<uses-sdk android:minSdkVersion="21" /><!-- android:targetSdkVersion="26"/> -->
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/>

16
main.go
View File

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