GODT-1298: signal GUI is ready and rise window

This commit is contained in:
Jakub
2021-09-13 17:22:53 +02:00
parent 85c06809d2
commit aeceb7d593
9 changed files with 94 additions and 30 deletions

View File

@ -33,6 +33,7 @@ import (
"github.com/ProtonMail/proton-bridge/pkg/listener"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/sirupsen/logrus"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/qml"
"github.com/therecipe/qt/widgets"
)
@ -57,8 +58,10 @@ type FrontendQt struct {
newVersionInfo updater.VersionInfo
log *logrus.Entry
usersMtx sync.Mutex
log *logrus.Entry
usersMtx sync.Mutex
initializing sync.WaitGroup
initializationDone sync.Once
app *widgets.QApplication
engine *qml.QQmlApplicationEngine
@ -81,7 +84,9 @@ func New(
autostart *autostart.App,
restarter types.Restarter,
) *FrontendQt {
return &FrontendQt{
userAgent.SetPlatform(core.QSysInfo_PrettyProductName())
f := &FrontendQt{
programName: "Proton Mail Bridge",
programVersion: version,
log: logrus.WithField("pkg", "frontend/qt"),
@ -96,6 +101,19 @@ func New(
autostart: autostart,
restarter: restarter,
}
// Initializing.Done is only called sync.Once. Please keep the increment
// set to 1
f.initializing.Add(1)
if showWindowOnStart {
go func() {
f.initializing.Wait()
f.qml.ShowMainWindow()
}()
}
return f
}
func (f *FrontendQt) Loop() error {
@ -142,5 +160,5 @@ func (f *FrontendQt) NotifySilentUpdateError(err error) {
}
func (f *FrontendQt) WaitUntilFrontendIsReady() {
// TODO: Implement
f.initializing.Wait()
}

View File

@ -178,3 +178,7 @@ func (f *FrontendQt) quit() {
f.log.Warn("Your wish is my command.. I quit!")
f.app.Exit(0)
}
func (f *FrontendQt) guiReady() {
f.initializationDone.Do(f.initializing.Done)
}

View File

@ -33,6 +33,7 @@ type QMLBackend struct {
core.QObject
_ func() *core.QPoint `slot:"getCursorPos"`
_ func() `slot:"guiReady"`
_ func() `slot:"quit"`
_ func() `slot:"restart"`
@ -141,6 +142,7 @@ func (q *QMLBackend) setup(f *FrontendQt) {
q.ConnectGetCursorPos(getCursorPos)
q.ConnectQuit(f.quit)
q.ConnectRestart(f.restart)
q.ConnectGuiReady(f.guiReady)
q.ConnectIsDockIconVisible(func() bool {
return dockIcon.GetDockIconVisibleState()