refactoring of main to mainUi() and mainService()
This commit is contained in:
parent
8a666a7f37
commit
9400d5aa63
69
main.go
69
main.go
|
@ -8,7 +8,6 @@ import (
|
||||||
"cwtch.im/ui/go/gothings/android"
|
"cwtch.im/ui/go/gothings/android"
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
"github.com/therecipe/qt/core"
|
"github.com/therecipe/qt/core"
|
||||||
|
@ -49,23 +48,46 @@ func main() {
|
||||||
log.SetLevel(log.LevelInfo)
|
log.SetLevel(log.LevelInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("cwtch main args: %v\n", os.Args)
|
if os.Getenv("CWTCH_FOLDER") != "" {
|
||||||
|
the.CwtchDir = os.Getenv("CWTCH_FOLDER")
|
||||||
|
} else if runtime.GOOS == "android" {
|
||||||
|
the.CwtchDir = path.Join(androidBaseDir, "files")
|
||||||
|
} else {
|
||||||
|
usr, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("\nerror: could not load current user: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
the.CwtchDir = path.Join(usr.HomeDir, ".cwtch")
|
||||||
|
}
|
||||||
|
the.ACN = nil
|
||||||
|
|
||||||
if *flagService {
|
if *flagService {
|
||||||
|
mainService()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
mainUi(*flagLocal)
|
||||||
|
}
|
||||||
|
|
||||||
|
if the.ACN != nil {
|
||||||
|
the.ACN.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainService() {
|
||||||
log.Infoln("I am the service")
|
log.Infoln("I am the service")
|
||||||
torpath := path.Join(androidBaseDir, "lib/libtor.so")
|
loadACN()
|
||||||
log.Infoln("Starting Tor...")
|
|
||||||
acn, _ := connectivity.StartTor(the.CwtchDir, torpath)
|
|
||||||
log.Infoln("Starting a cwtch app...")
|
log.Infoln("Starting a cwtch app...")
|
||||||
the.CwtchApp = libapp.NewApp(acn, the.CwtchDir)
|
the.CwtchApp = libapp.NewApp(the.ACN, the.CwtchDir)
|
||||||
|
|
||||||
log.Infoln("Sleepinging???")
|
log.Infoln("Sleepinging???")
|
||||||
for true {
|
for true {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
log.Infoln("Wake up, repeat")
|
log.Infoln("Wake up, repeat")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
func mainUi(flagLocal bool) {
|
||||||
log.Infoln("I am the application")
|
log.Infoln("I am the application")
|
||||||
|
|
||||||
app := gui.NewQGuiApplication(len(os.Args), os.Args)
|
app := gui.NewQGuiApplication(len(os.Args), os.Args)
|
||||||
|
@ -89,7 +111,7 @@ func main() {
|
||||||
|
|
||||||
// this is to load local qml files quickly when developing
|
// this is to load local qml files quickly when developing
|
||||||
var qmlSource *core.QUrl
|
var qmlSource *core.QUrl
|
||||||
if *flagLocal {
|
if flagLocal {
|
||||||
qmlSource = core.QUrl_FromLocalFile("./qml/main.qml")
|
qmlSource = core.QUrl_FromLocalFile("./qml/main.qml")
|
||||||
} else {
|
} else {
|
||||||
qmlSource = core.NewQUrl3("qrc:/qml/main.qml", 0)
|
qmlSource = core.NewQUrl3("qrc:/qml/main.qml", 0)
|
||||||
|
@ -137,41 +159,19 @@ func main() {
|
||||||
|
|
||||||
var androidCwtchActivity = android.NewCwtchActivity(nil)
|
var androidCwtchActivity = android.NewCwtchActivity(nil)
|
||||||
engine.RootContext().SetContextProperty("androidCwtchActivity", androidCwtchActivity)
|
engine.RootContext().SetContextProperty("androidCwtchActivity", androidCwtchActivity)
|
||||||
/*if runtime.GOOS == "android" {
|
|
||||||
androidCwtchActivity.StartCwtchService()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//engine.addImportPath(QStringLiteral("qrc:/"));
|
//engine.addImportPath(QStringLiteral("qrc:/"));
|
||||||
//engine.load(QUrl(QStringLiteral("qrc:/source/qml/main.qml")));
|
//engine.load(QUrl(QStringLiteral("qrc:/source/qml/main.qml")));
|
||||||
|
|
||||||
engine.Load(qmlSource)
|
engine.Load(qmlSource)
|
||||||
|
|
||||||
the.ACN = nil
|
|
||||||
go loadNetworkingAndFiles(gcd)
|
go loadNetworkingAndFiles(gcd)
|
||||||
|
|
||||||
app.Exec()
|
app.Exec()
|
||||||
}
|
|
||||||
|
|
||||||
if the.ACN != nil {
|
|
||||||
the.ACN.Close()
|
|
||||||
}
|
|
||||||
log.Infoln("Exiting main()")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher) {
|
func loadACN() {
|
||||||
if os.Getenv("CWTCH_FOLDER") != "" {
|
|
||||||
the.CwtchDir = os.Getenv("CWTCH_FOLDER")
|
|
||||||
} else if runtime.GOOS == "android" {
|
|
||||||
the.CwtchDir = path.Join(androidBaseDir, "files")
|
|
||||||
} else {
|
|
||||||
usr, err := user.Current()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("\nerror: could not load current user: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
the.CwtchDir = path.Join(usr.HomeDir, ".cwtch")
|
|
||||||
}
|
|
||||||
|
|
||||||
torpath := "tor"
|
torpath := "tor"
|
||||||
if runtime.GOOS == "android" {
|
if runtime.GOOS == "android" {
|
||||||
torpath = path.Join(androidBaseDir, "lib/libtor.so")
|
torpath = path.Join(androidBaseDir, "lib/libtor.so")
|
||||||
|
@ -197,8 +197,15 @@ func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher) {
|
||||||
log.Errorf("Could not start Tor: %v", err)
|
log.Errorf("Could not start Tor: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher) {
|
||||||
|
if runtime.GOOS != "android" {
|
||||||
|
loadACN()
|
||||||
|
}
|
||||||
|
|
||||||
the.Peer = nil
|
the.Peer = nil
|
||||||
|
|
||||||
os.MkdirAll(the.CwtchDir, 0700)
|
os.MkdirAll(the.CwtchDir, 0700)
|
||||||
|
|
||||||
the.CwtchApp = libapp.NewApp(the.ACN, the.CwtchDir)
|
the.CwtchApp = libapp.NewApp(the.ACN, the.CwtchDir)
|
||||||
|
|
Reference in New Issue