diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index ee5f0fac..df22a1e3 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -234,8 +234,9 @@ class MatrixClient(nio.AsyncClient): # This error will be caught again by the try block later below size = 0 + task = asyncio.Task.current_task() monitor = nio.TransferMonitor(size) - upload_item = Upload(item_uuid, monitor, path, total_size=size) + upload_item = Upload(item_uuid, task, monitor, path, total_size=size) self.models[Upload, room_id][str(item_uuid)] = upload_item def on_transfered(transfered: int) -> None: @@ -370,7 +371,7 @@ class MatrixClient(nio.AsyncClient): content["msgtype"] = "m.file" content["filename"] = path.name - del self.models[Upload, room_id][upload_item.uuid] + del self.models[Upload, room_id][str(upload_item.uuid)] uuid = str(uuid4()) diff --git a/src/python/models/items.py b/src/python/models/items.py index 10452fc2..9eafe58b 100644 --- a/src/python/models/items.py +++ b/src/python/models/items.py @@ -1,3 +1,4 @@ +import asyncio import re from dataclasses import dataclass, field from datetime import datetime, timedelta @@ -114,6 +115,7 @@ class UploadStatus(AutoStrEnum): @dataclass class Upload(ModelItem): uuid: UUID = field() + task: asyncio.Task = field() monitor: nio.TransferMonitor = field() filepath: Path = field() diff --git a/src/qml/Chat/UploadsBar.qml b/src/qml/Chat/UploadsBar.qml index 350a3c9f..ce9cc43a 100644 --- a/src/qml/Chat/UploadsBar.qml +++ b/src/qml/Chat/UploadsBar.qml @@ -61,7 +61,7 @@ Rectangle { // immediate visual feedback hideBind.when = true // Python will delete this model item on cancel - py.setattr(model.monitor, "cancel", true) + py.call(py.getattr(model.task, "cancel")) } Layout.preferredWidth: theme.baseElementsHeight @@ -188,7 +188,7 @@ Rectangle { onClicked: { delegate.guiPaused = ! delegate.guiPaused py.setattr( - model.monitor, "pause", model.status !== "Paused", + model.monitor, "pause", delegate.guiPaused, ) }