diff --git a/internal/frontend/qml/BridgeTest/UserControl.qml b/internal/frontend/qml/BridgeTest/UserControl.qml index 01ccf259..7dd8dd24 100644 --- a/internal/frontend/qml/BridgeTest/UserControl.qml +++ b/internal/frontend/qml/BridgeTest/UserControl.qml @@ -26,6 +26,7 @@ ColumnLayout { id: root property var user + property var userIndex property var backend spacing : 5 @@ -250,7 +251,25 @@ ColumnLayout { id: loginFinishedIndex colorScheme: root.colorScheme label: "Index:" - text: "0" + text: root.userIndex + } + } + + RowLayout { + Button { + colorScheme: root.colorScheme + text: "Already logged in" + + onClicked: { + root.backend.loginAlreadyLoggedIn(0+loginAlreadyLoggedInIndex.text) + user.resetLoginRequests() + } + } + TextField { + id: loginAlreadyLoggedInIndex + colorScheme: root.colorScheme + label: "Index:" + text: root.userIndex } } diff --git a/internal/frontend/qml/Bridge_test.qml b/internal/frontend/qml/Bridge_test.qml index 7a59b1cb..7cbcca98 100644 --- a/internal/frontend/qml/Bridge_test.qml +++ b/internal/frontend/qml/Bridge_test.qml @@ -436,6 +436,7 @@ Window { colorScheme: root.colorScheme backend: root user: ((root.usersTest.count > usersListView.currentIndex) && usersListView.currentIndex != -1) ? root.usersTest.get(usersListView.currentIndex) : undefined + userIndex: usersListView.currentIndex - 1 // -1 because 0 index is fake user } } @@ -671,6 +672,7 @@ Window { signal login2PasswordError(string errorMsg) signal login2PasswordErrorAbort(string errorMsg) signal loginFinished(int index) + signal loginAlreadyLoggedIn(int index) signal internetOff() signal internetOn() @@ -849,6 +851,9 @@ Window { onLoginFinished: { console.debug("<- loginFinished", index) } + onLoginAlreadyLoggedIn: { + console.debug("<- loginAlreadyLoggedIn", index) + } onInternetOff: { console.debug("<- internetOff") diff --git a/internal/frontend/qml/ContentWrapper.qml b/internal/frontend/qml/ContentWrapper.qml index 11c2444a..bad78a49 100644 --- a/internal/frontend/qml/ContentWrapper.qml +++ b/internal/frontend/qml/ContentWrapper.qml @@ -377,6 +377,7 @@ Item { target: root.backend onLoginFinished: rightContent.showAccount(index) + onLoginAlreadyLoggedIn: rightContent.showAccount(index) } } } diff --git a/internal/frontend/qml/Notifications/Notifications.qml b/internal/frontend/qml/Notifications/Notifications.qml index b58cb7d9..34205bd1 100644 --- a/internal/frontend/qml/Notifications/Notifications.qml +++ b/internal/frontend/qml/Notifications/Notifications.qml @@ -57,6 +57,7 @@ QtObject { root.updateIsLatestVersion, root.loginConnectionError, root.onlyPaidUsers, + root.alreadyLoggedIn, root.enableBeta, root.bugReportSendSuccess, root.bugReportSendError, @@ -414,6 +415,29 @@ QtObject { ] } + property Notification alreadyLoggedIn: Notification { + text: qsTr("This account is already signed it.") + icon: "./icons/ic-exclamation-circle-filled.svg" + type: Notification.NotificationType.Info + group: Notifications.Group.Configuration + + Connections { + target: root.backend + onLoginAlreadyLoggedIn: { + root.alreadyLoggedIn.active = true + } + } + + action: [ + Action { + text: qsTr("OK") + onTriggered: { + root.alreadyLoggedIn.active = false + } + } + ] + } + // Bug reports property Notification bugReportSendSuccess: Notification { text: qsTr("Thank you for the report. We'll get back to you as soon as we can.") diff --git a/internal/frontend/qt/frontend_users.go b/internal/frontend/qt/frontend_users.go index 73dd3e9c..ffd81ca1 100644 --- a/internal/frontend/qt/frontend_users.go +++ b/internal/frontend/qt/frontend_users.go @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with ProtonMail Bridge. If not, see . +//go:build build_qt // +build build_qt package qt @@ -145,6 +146,7 @@ func (f *FrontendQt) finishLogin() { defer f.eventListener.Remove(events.UserChangeDone, done) user, err := f.bridge.FinishLogin(f.authClient, f.auth, f.password) + if err != nil && err != users.ErrUserAlreadyConnected { f.log.WithError(err).Errorf("Finish login failed") f.qml.Login2PasswordErrorAbort(err.Error()) @@ -158,8 +160,12 @@ func (f *FrontendQt) finishLogin() { index := f.qml.Users().indexByID(user.ID()) f.log.WithField("index", index).Debug("Login finished") - defer f.qml.LoginFinished(index) + + if err == users.ErrUserAlreadyConnected { + f.log.WithError(err).Error("User already logged in") + f.qml.LoginAlreadyLoggedIn(index) + } } func (f *FrontendQt) waitForUserChangeDone(done <-chan string, userID string) { diff --git a/internal/frontend/qt/qml_backend.go b/internal/frontend/qt/qml_backend.go index 01bd5065..9bd44e89 100644 --- a/internal/frontend/qt/qml_backend.go +++ b/internal/frontend/qt/qml_backend.go @@ -65,6 +65,7 @@ type QMLBackend struct { _ func(errorMsg string) `signal:"login2PasswordError"` _ func(errorMsg string) `signal:"login2PasswordErrorAbort"` _ func(index int) `signal:"loginFinished"` + _ func(index int) `signal:"loginAlreadyLoggedIn"` _ func() `signal:"internetOff"` _ func() `signal:"internetOn"`