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