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

@ -143,7 +143,7 @@ Item {
RowLayout { RowLayout {
Label { Label {
colorScheme: root.colorScheme colorScheme: root.colorScheme
text: root.usedSpace text: user.loggedIn ? root.usedSpace : qsTr("Signed out")
color: root.usedSpaceColor color: root.usedSpaceColor
type: { type: {
switch (root.type) { switch (root.type) {
@ -155,7 +155,7 @@ Item {
Label { Label {
colorScheme: root.colorScheme colorScheme: root.colorScheme
text: " / " + root.totalSpace text: user.loggedIn ? " / " + root.totalSpace : ""
color: root.colorScheme.text_weak color: root.colorScheme.text_weak
type: { type: {
switch (root.type) { switch (root.type) {
@ -168,8 +168,7 @@ Item {
Rectangle { Rectangle {
visible: root.type == AccountDelegate.LargeView visible: root.type == AccountDelegate.LargeView && user.loggedIn
width: 140 width: 140
height: 4 height: 4
radius: 3 radius: 3

View File

@ -83,19 +83,21 @@ ScrollView {
Button { Button {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
colorScheme: root.colorScheme colorScheme: root.colorScheme
icon.source: "icons/ic-trash.svg" text: qsTr("Sign in")
secondary: true secondary: true
visible: root.user.loggedIn visible: !root.user.loggedIn
onClicked: root.user.remove() enabled: !root.user.loggedIn
onClicked: root.parent.rightContent.showSignIn()
} }
Button { Button {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
colorScheme: root.colorScheme colorScheme: root.colorScheme
text: qsTr("Sign in") icon.source: "icons/ic-trash.svg"
secondary: true secondary: true
visible: !root.user.loggedIn visible: true
onClicked: root.parent.rightContent.showSignIn() enabled: true
onClicked: root.user.remove()
} }
} }

View File

@ -79,22 +79,22 @@ QtObject {
onShowMainWindow: { onShowMainWindow: {
mainWindow.visible = true mainWindow.showAndRise()
} }
onShowHelp: { onShowHelp: {
mainWindow.showHelp() mainWindow.showHelp()
mainWindow.visible = true mainWindow.showAndRise()
} }
onShowSettings: { onShowSettings: {
mainWindow.showSettings() mainWindow.showSettings()
mainWindow.visible = true mainWindow.showAndRise()
} }
onShowSignIn: { onShowSignIn: {
mainWindow.showSignIn(username) mainWindow.showSignIn(username)
mainWindow.visible = true mainWindow.showAndRise()
} }
onQuit: { onQuit: {
@ -111,7 +111,7 @@ QtObject {
visible: true visible: true
iconSource: "./icons/ic-systray.svg" iconSource: "./icons/ic-systray.svg"
onActivated: { onActivated: {
function calcStatusWindowPosition(statusWidth, statusHeight) { function calcStatusWindowPosition() {
function isInInterval(num, lower_limit, upper_limit) { function isInInterval(num, lower_limit, upper_limit) {
return lower_limit <= num && num <= upper_limit return lower_limit <= num && num <= upper_limit
} }
@ -152,17 +152,26 @@ QtObject {
statusWindow.y_max = screen.virtualY + screen.height - iconHeight statusWindow.y_max = screen.virtualY + screen.height - iconHeight
} }
function toggleWindow(win) {
if (win.visible) {
win.close()
} else {
win.showAndRise()
}
}
switch (reason) { switch (reason) {
case SystemTrayIcon.Unknown: case SystemTrayIcon.Unknown:
break; break;
case SystemTrayIcon.Context: case SystemTrayIcon.Context:
case SystemTrayIcon.Trigger: case SystemTrayIcon.Trigger:
calcStatusWindowPosition() calcStatusWindowPosition()
statusWindow.visible = !statusWindow.visible toggleWindow(statusWindow)
break break
case SystemTrayIcon.DoubleClick: case SystemTrayIcon.DoubleClick:
case SystemTrayIcon.MiddleClick: case SystemTrayIcon.MiddleClick:
mainWindow.visible = !mainWindow.visible toggleWindow(mainWindow)
break; break;
default: default:
break; break;
@ -172,11 +181,13 @@ QtObject {
Component.onCompleted: { Component.onCompleted: {
if (root.backend.users.count === 0) { if (root.backend.users.count === 0) {
mainWindow.show() mainWindow.showAndRise()
} }
if (root.backend.users.count === 1 && root.backend.users.get(0).loggedIn === false) { if (root.backend.users.count === 1 && root.backend.users.get(0).loggedIn === false) {
mainWindow.show() mainWindow.showAndRise()
} }
root.backend.guiReady()
} }
} }

View File

@ -54,6 +54,10 @@ Window {
} }
} }
function guiReady() {
console.log("Gui Ready")
}
function _log(msg, color) { function _log(msg, color) {
logTextArea.text += "<p style='color: " + color + ";'>" + msg + "</p>" logTextArea.text += "<p style='color: " + color + ";'>" + msg + "</p>"
logTextArea.text += "\n" logTextArea.text += "\n"
@ -334,7 +338,7 @@ Window {
enabled: bridge === undefined || bridge === null enabled: bridge === undefined || bridge === null
onClicked: { onClicked: {
bridge = bridgeComponent.createObject() bridge = bridgeComponent.createObject()
if (true) bridge._mainWindow.show() if (true) bridge._mainWindow.showAndRise()
} }
} }

View File

@ -78,6 +78,14 @@ ApplicationWindow {
} }
} }
Connections {
target: root.backend
onShowMainWindow: {
root.showAndRise()
}
}
StackLayout { StackLayout {
id: contentLayout id: contentLayout
@ -187,4 +195,12 @@ ApplicationWindow {
contentLayout._showSetup = false contentLayout._showSetup = false
} }
} }
function showAndRise() {
root.show()
root.raise()
if (!root.active) {
root.requestActivate()
}
}
} }

View File

@ -31,7 +31,7 @@ Window {
height: contentLayout.implicitHeight height: contentLayout.implicitHeight
width: contentLayout.implicitWidth width: contentLayout.implicitWidth
flags: Qt.FramelessWindowHint flags: Qt.FramelessWindowHint | Qt.NoDropShadowWindowHint | Qt.WindowStaysOnTopHint
property ColorScheme colorScheme: ProtonStyle.currentStyle property ColorScheme colorScheme: ProtonStyle.currentStyle
@ -202,7 +202,7 @@ Window {
text: qsTr("Sign in") text: qsTr("Sign in")
onClicked: { onClicked: {
root.showSignIn(viewItem.username) root.showSignIn(viewItem.username)
root.visible = false root.close()
} }
} }
} }
@ -243,7 +243,7 @@ Window {
onClicked: { onClicked: {
root.showMainWindow() root.showMainWindow()
root.visible = false root.close()
} }
} }
@ -274,7 +274,7 @@ Window {
text: qsTr("Help") text: qsTr("Help")
onClicked: { onClicked: {
root.showHelp() root.showHelp()
root.visible = false root.close()
} }
} }
MenuItem { MenuItem {
@ -282,7 +282,7 @@ Window {
text: qsTr("Settings") text: qsTr("Settings")
onClicked: { onClicked: {
root.showSettings() root.showSettings()
root.visible = false root.close()
} }
} }
MenuItem { MenuItem {
@ -290,7 +290,7 @@ Window {
text: qsTr("Quit ProtonBridge") text: qsTr("Quit ProtonBridge")
onClicked: { onClicked: {
root.quit() root.quit()
root.visible = false root.close()
} }
} }
@ -309,4 +309,12 @@ Window {
onActiveChanged: { onActiveChanged: {
if (!active) root.close() if (!active) root.close()
} }
function showAndRise() {
root.show()
root.raise()
if (!root.active) {
root.requestActivate()
}
}
} }

View File

@ -33,6 +33,7 @@ import (
"github.com/ProtonMail/proton-bridge/pkg/listener" "github.com/ProtonMail/proton-bridge/pkg/listener"
"github.com/ProtonMail/proton-bridge/pkg/pmapi" "github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/qml" "github.com/therecipe/qt/qml"
"github.com/therecipe/qt/widgets" "github.com/therecipe/qt/widgets"
) )
@ -59,6 +60,8 @@ type FrontendQt struct {
log *logrus.Entry log *logrus.Entry
usersMtx sync.Mutex usersMtx sync.Mutex
initializing sync.WaitGroup
initializationDone sync.Once
app *widgets.QApplication app *widgets.QApplication
engine *qml.QQmlApplicationEngine engine *qml.QQmlApplicationEngine
@ -81,7 +84,9 @@ func New(
autostart *autostart.App, autostart *autostart.App,
restarter types.Restarter, restarter types.Restarter,
) *FrontendQt { ) *FrontendQt {
return &FrontendQt{ userAgent.SetPlatform(core.QSysInfo_PrettyProductName())
f := &FrontendQt{
programName: "Proton Mail Bridge", programName: "Proton Mail Bridge",
programVersion: version, programVersion: version,
log: logrus.WithField("pkg", "frontend/qt"), log: logrus.WithField("pkg", "frontend/qt"),
@ -96,6 +101,19 @@ func New(
autostart: autostart, autostart: autostart,
restarter: restarter, 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 { func (f *FrontendQt) Loop() error {
@ -142,5 +160,5 @@ func (f *FrontendQt) NotifySilentUpdateError(err error) {
} }
func (f *FrontendQt) WaitUntilFrontendIsReady() { 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.log.Warn("Your wish is my command.. I quit!")
f.app.Exit(0) 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 core.QObject
_ func() *core.QPoint `slot:"getCursorPos"` _ func() *core.QPoint `slot:"getCursorPos"`
_ func() `slot:"guiReady"`
_ func() `slot:"quit"` _ func() `slot:"quit"`
_ func() `slot:"restart"` _ func() `slot:"restart"`
@ -141,6 +142,7 @@ func (q *QMLBackend) setup(f *FrontendQt) {
q.ConnectGetCursorPos(getCursorPos) q.ConnectGetCursorPos(getCursorPos)
q.ConnectQuit(f.quit) q.ConnectQuit(f.quit)
q.ConnectRestart(f.restart) q.ConnectRestart(f.restart)
q.ConnectGuiReady(f.guiReady)
q.ConnectIsDockIconVisible(func() bool { q.ConnectIsDockIconVisible(func() bool {
return dockIcon.GetDockIconVisibleState() return dockIcon.GetDockIconVisibleState()