diff --git a/TODO.md b/TODO.md index add1d2ec..06496bae 100644 --- a/TODO.md +++ b/TODO.md @@ -41,6 +41,7 @@ - When starting a long task, e.g. importing keys, quitting the page, and coming back, show the buttons as still loading until operation is done - Make invite/left banners look better in column mode + - Responses - Messages editing - Code highlighting - Support GIF avatars @@ -100,6 +101,7 @@ - Accent color from background - Settings page - Message/text selection + - Notifications - Custom file picker for Linux... diff --git a/src/python/backend.py b/src/python/backend.py index dfcfa030..02b336dd 100644 --- a/src/python/backend.py +++ b/src/python/backend.py @@ -46,17 +46,22 @@ class Backend: # Clients management async def login_client(self, - user: str, - password: str, - device_id: Optional[str] = None, - homeserver: str = "https://matrix.org") -> str: + user: str, + password: str, + device_id: Optional[str] = None, + homeserver: str = "https://matrix.org", + ) -> Tuple[bool, str]: client = MatrixClient( self, user=user, homeserver=homeserver, device_id=device_id, ) - await client.login(password) + try: + await client.login(password) + except RuntimeError as err: + return (False, err.args[0].message) + self.clients[client.user_id] = client self.models[Account][client.user_id] = Account(client.user_id) - return client.user_id + return (True, client.user_id) async def resume_client(self, diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index dd84acd0..78201f0e 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -112,7 +112,7 @@ class MatrixClient(nio.AsyncClient): ) if isinstance(response, nio.LoginError): - log.error(response) + raise RuntimeError(response) else: await self.start() @@ -497,7 +497,7 @@ class MatrixClient(nio.AsyncClient): async def onErrorResponse(self, resp: nio.ErrorResponse) -> None: - # TODO: show something in the client + # TODO: show something in the client, must be seen on login screen too try: log.warning("%s - %s", resp, json.dumps(resp.__dict__, indent=4)) except Exception: diff --git a/src/qml/Pages/SignIn.qml b/src/qml/Pages/SignIn.qml index 5c9ac9c0..adfdcab8 100644 --- a/src/qml/Pages/SignIn.qml +++ b/src/qml/Pages/SignIn.qml @@ -26,8 +26,14 @@ Item { button.loading = true let args = [idField.text, passwordField.text] - py.callCoro("login_client", args, userId => { - pageStack.showPage("RememberAccount", {loginWith, userId}) + py.callCoro("login_client", args, ([success, data]) => { + if (success) { + // data = userId + errorMessage.text = "" + pageStack.showPage("RememberAccount", {loginWith,data}) + } else { + errorMessage.text = qsTr(data) + } button.loading = false }) }, @@ -77,5 +83,19 @@ Item { Layout.fillWidth: true Layout.margins: signInBox.margins } + + HLabel { + id: errorMessage + wrapMode: Text.Wrap + horizontalAlignment: Text.AlignHCenter + color: theme.colors.errorText + + visible: Layout.maximumHeight > 0 + Layout.maximumHeight: text ? implicitHeight : 0 + Behavior on Layout.maximumHeight { HNumberAnimation {} } + + Layout.fillWidth: true + Layout.margins: signInBox.margins + } } } diff --git a/src/themes/Default.qpl b/src/themes/Default.qpl index 9e90f914..43976053 100644 --- a/src/themes/Default.qpl +++ b/src/themes/Default.qpl @@ -53,6 +53,8 @@ colors: color halfDimText: hsluv(0, 0, intensity * 70) color dimText: hsluv(0, 0, intensity * 55) color dimmerText: hsluv(0, 0, intensity * 30) + + color errorText: hsluv(0, saturation * 2.25, 50) color accentText: hsluv(hue - 80, saturation * 2.25, 60) color link: accentText color code: hsluv(hue + 5, saturation * 1.5, intensity * 60)