Implement upload pause function
This commit is contained in:
parent
d354480840
commit
e51f1f2c79
|
@ -216,6 +216,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
try:
|
||||
await self._send_file(item_uuid, room_id, path)
|
||||
except (nio.TransferCancelledError, asyncio.CancelledError):
|
||||
log.info("Deleting item for cancelled upload %s", item_uuid)
|
||||
del self.models[Upload, room_id][str(item_uuid)]
|
||||
|
||||
|
||||
|
@ -233,8 +234,8 @@ class MatrixClient(nio.AsyncClient):
|
|||
# This error will be caught again by the try block later below
|
||||
size = 0
|
||||
|
||||
task = asyncio.Task.current_task()
|
||||
upload_item = Upload(item_uuid, task, path, total_size=size)
|
||||
monitor = nio.TransferMonitor(size)
|
||||
upload_item = Upload(item_uuid, monitor, path, total_size=size)
|
||||
self.models[Upload, room_id][str(item_uuid)] = upload_item
|
||||
|
||||
def on_transfered(transfered: int) -> None:
|
||||
|
@ -244,7 +245,8 @@ class MatrixClient(nio.AsyncClient):
|
|||
def on_speed_change(speed: float) -> None:
|
||||
upload_item.speed = speed
|
||||
|
||||
monitor = nio.TransferMonitor(size, on_transfered, on_speed_change)
|
||||
monitor.on_transfered = on_transfered
|
||||
monitor.on_speed_change = on_speed_change
|
||||
|
||||
try:
|
||||
url, mime, crypt_dict = await self.upload(
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import asyncio
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timedelta
|
||||
|
@ -114,9 +113,9 @@ class UploadStatus(AutoStrEnum):
|
|||
|
||||
@dataclass
|
||||
class Upload(ModelItem):
|
||||
uuid: UUID = field()
|
||||
task: asyncio.Task = field()
|
||||
filepath: Path = field()
|
||||
uuid: UUID = field()
|
||||
monitor: nio.TransferMonitor = field()
|
||||
filepath: Path = field()
|
||||
|
||||
total_size: int = 0
|
||||
uploaded: int = 0
|
||||
|
|
|
@ -61,7 +61,7 @@ Rectangle {
|
|||
// immediate visual feedback
|
||||
hideBind.when = true
|
||||
// Python will delete this model item on cancel
|
||||
py.call(py.getattr(model.task, "cancel"))
|
||||
py.setattr(model.monitor, "cancel", true)
|
||||
}
|
||||
|
||||
Layout.preferredWidth: theme.baseElementsHeight
|
||||
|
@ -187,7 +187,9 @@ Rectangle {
|
|||
|
||||
onClicked: {
|
||||
delegate.guiPaused = ! delegate.guiPaused
|
||||
// py.ev("model.task. TODO
|
||||
py.setattr(
|
||||
model.monitor, "pause", model.status !== "Paused",
|
||||
)
|
||||
}
|
||||
|
||||
Layout.preferredWidth:
|
||||
|
|
|
@ -10,6 +10,10 @@ Python {
|
|||
property bool startupAnyAccountsSaved: false
|
||||
property var pendingCoroutines: ({})
|
||||
|
||||
function setattr(obj, attr, value, callback=null) {
|
||||
py.call(py.getattr(obj, "__setattr__"), [attr, value], callback)
|
||||
}
|
||||
|
||||
function callSync(name, args=[]) {
|
||||
return call_sync("APP.backend." + name, args)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user