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 {
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

View File

@ -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()
}
}

View File

@ -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()
}
}

View File

@ -54,6 +54,10 @@ Window {
}
}
function guiReady() {
console.log("Gui Ready")
}
function _log(msg, color) {
logTextArea.text += "<p style='color: " + color + ";'>" + msg + "</p>"
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()
}
}

View File

@ -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()
}
}
}

View File

@ -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()
}
}
}

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"
)
@ -59,6 +60,8 @@ type FrontendQt struct {
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()