Fix uplaod item delete, pause and cancel bugs

This commit is contained in:
miruka 2019-12-06 08:59:35 -04:00
parent e51f1f2c79
commit 8ae4bbb6cf
3 changed files with 7 additions and 4 deletions

View File

@ -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())

View File

@ -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()

View File

@ -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,
)
}