package main import ( "os" "github.com/therecipe/qt/core" "github.com/therecipe/qt/gui" "github.com/therecipe/qt/qml" "github.com/therecipe/qt/quickcontrols2" "git.openprivacy.ca/openprivacy/asaur" "cwtch.im/cwtch/app" "os/exec" "log" "os/user" "path" "time" "strconv" ) type QmlCwtchApp struct { core.QObject _ int `property:"torStatusProgress"` _ string `property:"torStatusSummary"` //_ QIdentityListModel `property:"identities"` _ func() `constructor:"init"` } func (qCwtchApp *QmlCwtchApp) init() { } var cwtchApp app.Application func InitCwtch(engine *qml.QQmlApplicationEngine, qCwtchApp *QmlCwtchApp, identityList *QIdentityListModel) error { torPath, err := exec.LookPath("tor") if err != nil { log.Fatal("tor could not be found on this system. Please install it in the system $PATH") } usr, err := user.Current() if err != nil { log.Fatalf("\nError: could not load current user: %v\n", err) } doneChan := make(chan bool) go func() { for { time.Sleep(100 * time.Millisecond) rawStatus, _ := asaur.GetInfo("localhost:9051", "tcp4", "", "status/bootstrap-phase") status := asaur.ParseBootstrapPhase(rawStatus) progress, _ := strconv.Atoi(status["PROGRESS"]) qCwtchApp.SetTorStatusProgress(progress) qCwtchApp.SetTorStatusSummary(status["SUMMARY"]) if status["TAG"] == "done" { break } } doneChan <- true }() cwtchApp, err = app.NewApp(path.Join(usr.HomeDir, ".cwtch"), torPath) if err != nil { log.Fatalf("Error initializing application: %v", err) } /*identityList.Add(*NewIdentityListItemValues("alice", "1234567890abcdef", "red", identity)) identityList.Add( *NewIdentityListItemValues( "unlock", "", "#af921d", unlock)) identityList.Add( *NewIdentityListItemValues("add", "", "#e0e0e0", add))*/ identityList.Add( IdentityListItem{"alice", "1234567890abcdef", "red", identity}) identityList.Add( IdentityListItem{"unlock", "", "#af921d", unlock}) identityList.Add( IdentityListItem{"add", "", "#e0e0e0", add}) <-doneChan return nil } func main() { // enable high dpi scaling // useful for devices with high pixel density displays // such as smartphones, retina displays, ... core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true) // needs to be called once before you can start using QML gui.NewQGuiApplication(len(os.Args), os.Args) // use the material style // the other inbuild styles are: // Default, Fusion, Imagine, Universal quickcontrols2.QQuickStyle_SetStyle("Material") var qCwtchApp = NewQmlCwtchApp(nil) var identityList = NewQIdentityListModel(nil) //qCwtchApp.SetIdentities(append(qCwtchApp.Identities(), alice))*/ // create the qml application engine engine := qml.NewQQmlApplicationEngine(nil) //engine.QmlRegisterType() engine.RootContext().SetContextProperty("cwtchApp", qCwtchApp) engine.RootContext().SetContextProperty("identityList", identityList) // load the embeeded qml file // created by either qtrcc or qtdeploy //engine.Load(core.NewQUrl3("qrc:/qml/LoadingWindow.qml", 0)) //engine.Load(core.NewQUrl3("qrc:/qml/MainWindow.qml", 0)) // you can also load a local file like this instead: //engine.Load(core.QUrl_FromLocalFile("./qml/main.qml")) engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0)) go InitCwtch(engine, qCwtchApp, identityList) // start the main Qt event loop // and block until app.Exit() is called // or the window is closed by the user gui.QGuiApplication_Exec() // Cleanup cwtchApp.Shutdown() }