Implement cancelling python coros from QML

This was needed to implement the cancel button featue on the login
screen
This commit is contained in:
miruka
2019-12-07 18:33:33 -04:00
parent 4a93a24f74
commit 6f589dbda5
3 changed files with 66 additions and 15 deletions

View File

@@ -31,7 +31,7 @@ HBox {
signInTimeout.restart()
py.callCoro("login_client", args, userId => {
loginFuture = py.callCoro("login_client", args, userId => {
signInTimeout.stop()
errorMessage.text = ""
button.loading = false
@@ -48,9 +48,14 @@ HBox {
)
}, type => {
if (type === "CancelledError") return
signInTimeout.stop()
if (type === "CancelledError") {
loginFuture = null
button.loading = false
return
}
let txt = qsTr("Invalid request or login type")
if (type === "MatrixForbidden")
@@ -64,11 +69,14 @@ HBox {
})
},
cancel: button => {}
cancel: button => { if (loginFuture) loginFuture.cancel() }
})
property var loginFuture: null
property string signInWith: "username"
readonly property bool canSignIn:
serverField.text && idField.text && passwordField.text &&
! serverField.error