From aeceb7d5936829603f419d88d8cc433e183ded69 Mon Sep 17 00:00:00 2001 From: Jakub Date: Mon, 13 Sep 2021 17:22:53 +0200 Subject: [PATCH] GODT-1298: signal GUI is ready and rise window --- internal/frontend/qml/AccountDelegate.qml | 7 +++--- internal/frontend/qml/AccountView.qml | 14 ++++++----- internal/frontend/qml/Bridge.qml | 29 ++++++++++++++++------- internal/frontend/qml/Bridge_test.qml | 6 ++++- internal/frontend/qml/MainWindow.qml | 16 +++++++++++++ internal/frontend/qml/StatusWindow.qml | 20 +++++++++++----- internal/frontend/qt/frontend.go | 26 ++++++++++++++++---- internal/frontend/qt/frontend_settings.go | 4 ++++ internal/frontend/qt/qml_backend.go | 2 ++ 9 files changed, 94 insertions(+), 30 deletions(-) diff --git a/internal/frontend/qml/AccountDelegate.qml b/internal/frontend/qml/AccountDelegate.qml index 011565b7..72e16cb7 100644 --- a/internal/frontend/qml/AccountDelegate.qml +++ b/internal/frontend/qml/AccountDelegate.qml @@ -143,7 +143,7 @@ Item { RowLayout { Label { colorScheme: root.colorScheme - text: root.usedSpace + text: user.loggedIn ? root.usedSpace : qsTr("Signed out") color: root.usedSpaceColor type: { switch (root.type) { @@ -155,7 +155,7 @@ Item { Label { colorScheme: root.colorScheme - text: " / " + root.totalSpace + text: user.loggedIn ? " / " + root.totalSpace : "" color: root.colorScheme.text_weak type: { switch (root.type) { @@ -168,8 +168,7 @@ Item { Rectangle { - visible: root.type == AccountDelegate.LargeView - + visible: root.type == AccountDelegate.LargeView && user.loggedIn width: 140 height: 4 radius: 3 diff --git a/internal/frontend/qml/AccountView.qml b/internal/frontend/qml/AccountView.qml index d1e11044..16267baf 100644 --- a/internal/frontend/qml/AccountView.qml +++ b/internal/frontend/qml/AccountView.qml @@ -83,19 +83,21 @@ ScrollView { Button { Layout.alignment: Qt.AlignTop colorScheme: root.colorScheme - icon.source: "icons/ic-trash.svg" + text: qsTr("Sign in") secondary: true - visible: root.user.loggedIn - onClicked: root.user.remove() + visible: !root.user.loggedIn + enabled: !root.user.loggedIn + onClicked: root.parent.rightContent.showSignIn() } Button { Layout.alignment: Qt.AlignTop colorScheme: root.colorScheme - text: qsTr("Sign in") + icon.source: "icons/ic-trash.svg" secondary: true - visible: !root.user.loggedIn - onClicked: root.parent.rightContent.showSignIn() + visible: true + enabled: true + onClicked: root.user.remove() } } diff --git a/internal/frontend/qml/Bridge.qml b/internal/frontend/qml/Bridge.qml index 11c1151e..433c8b00 100644 --- a/internal/frontend/qml/Bridge.qml +++ b/internal/frontend/qml/Bridge.qml @@ -79,22 +79,22 @@ QtObject { onShowMainWindow: { - mainWindow.visible = true + mainWindow.showAndRise() } onShowHelp: { mainWindow.showHelp() - mainWindow.visible = true + mainWindow.showAndRise() } onShowSettings: { mainWindow.showSettings() - mainWindow.visible = true + mainWindow.showAndRise() } onShowSignIn: { mainWindow.showSignIn(username) - mainWindow.visible = true + mainWindow.showAndRise() } onQuit: { @@ -111,7 +111,7 @@ QtObject { visible: true iconSource: "./icons/ic-systray.svg" onActivated: { - function calcStatusWindowPosition(statusWidth, statusHeight) { + function calcStatusWindowPosition() { function isInInterval(num, lower_limit, upper_limit) { return lower_limit <= num && num <= upper_limit } @@ -152,17 +152,26 @@ QtObject { statusWindow.y_max = screen.virtualY + screen.height - iconHeight } + function toggleWindow(win) { + if (win.visible) { + win.close() + } else { + win.showAndRise() + } + } + + switch (reason) { case SystemTrayIcon.Unknown: break; case SystemTrayIcon.Context: case SystemTrayIcon.Trigger: calcStatusWindowPosition() - statusWindow.visible = !statusWindow.visible + toggleWindow(statusWindow) break case SystemTrayIcon.DoubleClick: case SystemTrayIcon.MiddleClick: - mainWindow.visible = !mainWindow.visible + toggleWindow(mainWindow) break; default: break; @@ -172,11 +181,13 @@ QtObject { Component.onCompleted: { if (root.backend.users.count === 0) { - mainWindow.show() + mainWindow.showAndRise() } if (root.backend.users.count === 1 && root.backend.users.get(0).loggedIn === false) { - mainWindow.show() + mainWindow.showAndRise() } + + root.backend.guiReady() } } diff --git a/internal/frontend/qml/Bridge_test.qml b/internal/frontend/qml/Bridge_test.qml index 03a8f1bd..7f731575 100644 --- a/internal/frontend/qml/Bridge_test.qml +++ b/internal/frontend/qml/Bridge_test.qml @@ -54,6 +54,10 @@ Window { } } + function guiReady() { + console.log("Gui Ready") + } + function _log(msg, color) { logTextArea.text += "

" + msg + "

" logTextArea.text += "\n" @@ -334,7 +338,7 @@ Window { enabled: bridge === undefined || bridge === null onClicked: { bridge = bridgeComponent.createObject() - if (true) bridge._mainWindow.show() + if (true) bridge._mainWindow.showAndRise() } } diff --git a/internal/frontend/qml/MainWindow.qml b/internal/frontend/qml/MainWindow.qml index d57a5843..b6729be0 100644 --- a/internal/frontend/qml/MainWindow.qml +++ b/internal/frontend/qml/MainWindow.qml @@ -78,6 +78,14 @@ ApplicationWindow { } } + Connections { + target: root.backend + + onShowMainWindow: { + root.showAndRise() + } + } + StackLayout { id: contentLayout @@ -187,4 +195,12 @@ ApplicationWindow { contentLayout._showSetup = false } } + + function showAndRise() { + root.show() + root.raise() + if (!root.active) { + root.requestActivate() + } + } } diff --git a/internal/frontend/qml/StatusWindow.qml b/internal/frontend/qml/StatusWindow.qml index a2897422..b1820659 100644 --- a/internal/frontend/qml/StatusWindow.qml +++ b/internal/frontend/qml/StatusWindow.qml @@ -31,7 +31,7 @@ Window { height: contentLayout.implicitHeight width: contentLayout.implicitWidth - flags: Qt.FramelessWindowHint + flags: Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint | Qt.WindowStaysOnTopHint property ColorScheme colorScheme: ProtonStyle.currentStyle @@ -202,7 +202,7 @@ Window { text: qsTr("Sign in") onClicked: { root.showSignIn(viewItem.username) - root.visible = false + root.close() } } } @@ -243,7 +243,7 @@ Window { onClicked: { root.showMainWindow() - root.visible = false + root.close() } } @@ -274,7 +274,7 @@ Window { text: qsTr("Help") onClicked: { root.showHelp() - root.visible = false + root.close() } } MenuItem { @@ -282,7 +282,7 @@ Window { text: qsTr("Settings") onClicked: { root.showSettings() - root.visible = false + root.close() } } MenuItem { @@ -290,7 +290,7 @@ Window { text: qsTr("Quit ProtonBridge") onClicked: { root.quit() - root.visible = false + root.close() } } @@ -309,4 +309,12 @@ Window { onActiveChanged: { if (!active) root.close() } + + function showAndRise() { + root.show() + root.raise() + if (!root.active) { + root.requestActivate() + } + } } diff --git a/internal/frontend/qt/frontend.go b/internal/frontend/qt/frontend.go index 3cba590a..b0d30e4a 100644 --- a/internal/frontend/qt/frontend.go +++ b/internal/frontend/qt/frontend.go @@ -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() } diff --git a/internal/frontend/qt/frontend_settings.go b/internal/frontend/qt/frontend_settings.go index 3cdb8c84..d37826b9 100644 --- a/internal/frontend/qt/frontend_settings.go +++ b/internal/frontend/qt/frontend_settings.go @@ -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) +} diff --git a/internal/frontend/qt/qml_backend.go b/internal/frontend/qt/qml_backend.go index 05a5fe03..032279da 100644 --- a/internal/frontend/qt/qml_backend.go +++ b/internal/frontend/qt/qml_backend.go @@ -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()