Don't pass Python Future objects to QML

Returning a Future doesn't work on Windows for some reason
(https://github.com/thp/pyotherside/issues/116).

Instead of using these objects from QML to cancel running coroutines,
call a Python QMLBridge function that takes a coroutine UUID and will
take care of the cancelling.
This commit is contained in:
miruka
2020-09-28 23:06:50 -04:00
parent 53d2ab17af
commit ee1091b4dc
20 changed files with 161 additions and 178 deletions

View File

@@ -6,12 +6,11 @@ import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../../.."
import "../../../Base"
import "../../../PythonBridge"
HColumnLayout {
id: eventDelegate
property var fetchProfilesFuture: null
property string fetchProfilesFutureId: ""
// Remember timeline goes from newest message at index 0 to oldest
readonly property var previousModel: eventList.model.get(model.index + 1)
@@ -72,16 +71,16 @@ HColumnLayout {
onCursorShapeChanged: eventList.cursorShape = cursorShape
Component.onCompleted: if (model.fetch_profile)
fetchProfilesFuture = py.callClientCoro(
fetchProfilesFutureId = py.callClientCoro(
chat.userId,
"get_event_profiles",
[chat.roomId, model.id],
// The if avoids segfault if eventDelegate is already destroyed
() => { if (eventDelegate) fetchProfilesFuture = null }
() => { if (eventDelegate) fetchProfilesFutureId = "" }
)
Component.onDestruction:
if (fetchProfilesFuture) fetchProfilesFuture.cancel()
if (fetchProfilesFutureId) py.cancelCoro(fetchProfilesFutureId)
ListView.onRemove: eventList.uncheck(model.id)

View File

@@ -218,8 +218,8 @@ Rectangle {
HListView {
id: eventList
property Future updateMarkerFuture: null
property Future loadPastEventsFuture: null
property string updateMarkerFutureId: ""
property string loadPastEventsFutureId: ""
property bool moreToLoad: true
property bool ownEventsOnLeft:
@@ -355,13 +355,13 @@ Rectangle {
}
function loadPastEvents() {
loadPastEventsFuture = py.callClientCoro(
loadPastEventsFutureId = py.callClientCoro(
chat.userId,
"load_past_events",
[chat.roomId],
more => {
moreToLoad = more
loadPastEventsFuture = null
moreToLoad = more
loadPastEventsFutureId = ""
}
)
}
@@ -519,7 +519,7 @@ Rectangle {
footer: Item {
width: eventList.width
height: (button.height + theme.spacing * 2) * opacity
opacity: eventList.loadPastEventsFuture ? 1 : 0
opacity: eventList.loadPastEventsFutureId ? 1 : 0
visible: opacity > 0
Behavior on opacity { HNumberAnimation {} }
@@ -554,14 +554,14 @@ Rectangle {
interval: 200
running:
eventList.shouldLoadPastEvents &&
! eventList.loadPastEventsFuture
! eventList.loadPastEventsFutureId
triggeredOnStart: true
onTriggered: eventList.loadPastEvents()
}
Component.onDestruction: {
if (loadPastEventsFuture) loadPastEventsFuture.cancel()
if (loadPastEventsFutureId) py.cancelCoro(loadPastEventsFutureId)
}
MouseArea {
@@ -585,7 +585,7 @@ Rectangle {
interval: Math.max(100, window.settings.markRoomReadMsecDelay)
running:
! eventList.updateMarkerFuture &&
! eventList.updateMarkerFutureId &&
(
chat.roomInfo.unreads ||
chat.roomInfo.highlights ||
@@ -600,11 +600,11 @@ Rectangle {
const item = eventList.model.get(i)
if (item.sender !== chat.userId) {
eventList.updateMarkerFuture = py.callCoro(
eventList.updateMarkerFutureId = py.callCoro(
"update_room_read_marker",
[chat.roomId, item.event_id],
() => { eventList.updateMarkerFuture = null },
() => { eventList.updateMarkerFuture = null },
() => { eventList.updateMarkerFutureId = "" },
() => { eventList.updateMarkerFutureId = "" },
)
return
}