Make upload cancelling instant without visual hack
This commit is contained in:
parent
e8d4823227
commit
9bad0132d6
4
TODO.md
4
TODO.md
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
## Before release
|
## Before release
|
||||||
|
|
||||||
- Catch 5xx errors and retry
|
- Catch server 5xx errors when sending message and retry
|
||||||
- nio ClientTimeout
|
- nio ClientTimeout (to fix sync hanging after network changes or hibernation)
|
||||||
- Update docstrings
|
- Update docstrings
|
||||||
- Update README.md
|
- Update README.md
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
self.load_rooms_task: Optional[asyncio.Future] = None
|
self.load_rooms_task: Optional[asyncio.Future] = None
|
||||||
|
|
||||||
self.upload_monitors: Dict[UUID, nio.TransferMonitor] = {}
|
self.upload_monitors: Dict[UUID, nio.TransferMonitor] = {}
|
||||||
|
self.upload_tasks: Dict[UUID, asyncio.Task] = {}
|
||||||
|
|
||||||
self.first_sync_done: asyncio.Event = asyncio.Event()
|
self.first_sync_done: asyncio.Event = asyncio.Event()
|
||||||
self.first_sync_date: Optional[datetime] = None
|
self.first_sync_date: Optional[datetime] = None
|
||||||
|
@ -336,7 +337,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
if isinstance(uuid, str):
|
if isinstance(uuid, str):
|
||||||
uuid = UUID(uuid)
|
uuid = UUID(uuid)
|
||||||
|
|
||||||
self.upload_monitors[uuid].cancel = True
|
self.upload_tasks[uuid].cancel()
|
||||||
|
|
||||||
|
|
||||||
async def send_file(self, room_id: str, path: Union[Path, str]) -> None:
|
async def send_file(self, room_id: str, path: Union[Path, str]) -> None:
|
||||||
|
@ -349,6 +350,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
except (nio.TransferCancelledError, asyncio.CancelledError):
|
except (nio.TransferCancelledError, asyncio.CancelledError):
|
||||||
log.info("Deleting item for cancelled upload %s", item_uuid)
|
log.info("Deleting item for cancelled upload %s", item_uuid)
|
||||||
del self.upload_monitors[item_uuid]
|
del self.upload_monitors[item_uuid]
|
||||||
|
del self.upload_tasks[item_uuid]
|
||||||
del self.models[room_id, "uploads"][str(item_uuid)]
|
del self.models[room_id, "uploads"][str(item_uuid)]
|
||||||
|
|
||||||
|
|
||||||
|
@ -373,9 +375,11 @@ class MatrixClient(nio.AsyncClient):
|
||||||
monitor = nio.TransferMonitor(size)
|
monitor = nio.TransferMonitor(size)
|
||||||
upload_item = Upload(item_uuid, path, total_size=size)
|
upload_item = Upload(item_uuid, path, total_size=size)
|
||||||
|
|
||||||
self.upload_monitors[item_uuid] = monitor
|
|
||||||
self.models[room_id, "uploads"][str(item_uuid)] = upload_item
|
self.models[room_id, "uploads"][str(item_uuid)] = upload_item
|
||||||
|
|
||||||
|
self.upload_monitors[item_uuid] = monitor
|
||||||
|
self.upload_tasks[item_uuid] = asyncio.current_task() # type: ignore
|
||||||
|
|
||||||
def on_transferred(transferred: int) -> None:
|
def on_transferred(transferred: int) -> None:
|
||||||
upload_item.uploaded = transferred
|
upload_item.uploaded = transferred
|
||||||
|
|
||||||
|
@ -539,6 +543,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
content["filename"] = path.name
|
content["filename"] = path.name
|
||||||
|
|
||||||
del self.upload_monitors[item_uuid]
|
del self.upload_monitors[item_uuid]
|
||||||
|
del self.upload_tasks[item_uuid]
|
||||||
del self.models[room_id, "uploads"][str(upload_item.id)]
|
del self.models[room_id, "uploads"][str(upload_item.id)]
|
||||||
|
|
||||||
await self._local_echo(
|
await self._local_echo(
|
||||||
|
|
|
@ -9,6 +9,8 @@ HColumnLayout {
|
||||||
id: transfer
|
id: transfer
|
||||||
|
|
||||||
|
|
||||||
|
property bool cancelPending: false
|
||||||
|
|
||||||
property int msLeft: model.time_left
|
property int msLeft: model.time_left
|
||||||
property int uploaded: model.uploaded
|
property int uploaded: model.uploaded
|
||||||
readonly property int speed: model.speed
|
readonly property int speed: model.speed
|
||||||
|
@ -18,9 +20,7 @@ HColumnLayout {
|
||||||
|
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
// Python might take a sec to cancel, but we want
|
cancelPending = true
|
||||||
// immediate visual feedback
|
|
||||||
transfer.height = 0
|
|
||||||
// Python will delete this model item on cancel
|
// Python will delete this model item on cancel
|
||||||
py.callClientCoro(chat.userId, "cancel_upload", [model.id])
|
py.callClientCoro(chat.userId, "cancel_upload", [model.id])
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,12 @@ HColumnLayout {
|
||||||
HIcon {
|
HIcon {
|
||||||
svgName: "uploading"
|
svgName: "uploading"
|
||||||
colorize:
|
colorize:
|
||||||
transfer.status === "Error" ? theme.colors.negativeBackground :
|
cancelPending || transfer.status === "Error" ?
|
||||||
transfer.paused ? theme.colors.middleBackground :
|
theme.colors.negativeBackground :
|
||||||
|
|
||||||
|
transfer.paused ?
|
||||||
|
theme.colors.middleBackground :
|
||||||
|
|
||||||
theme.icons.colorize
|
theme.icons.colorize
|
||||||
|
|
||||||
Layout.preferredWidth: theme.baseElementsHeight
|
Layout.preferredWidth: theme.baseElementsHeight
|
||||||
|
@ -51,7 +55,11 @@ HColumnLayout {
|
||||||
wrapMode: expand ? Text.Wrap : Text.NoWrap
|
wrapMode: expand ? Text.Wrap : Text.NoWrap
|
||||||
|
|
||||||
text:
|
text:
|
||||||
status === "Uploading" ? fileName :
|
cancelPending ?
|
||||||
|
qsTr("Cancelling...") :
|
||||||
|
|
||||||
|
status === "Uploading" ?
|
||||||
|
fileName :
|
||||||
|
|
||||||
status === "Caching" ?
|
status === "Caching" ?
|
||||||
qsTr("Caching %1...").arg(fileName) :
|
qsTr("Caching %1...").arg(fileName) :
|
||||||
|
@ -179,7 +187,7 @@ HColumnLayout {
|
||||||
|
|
||||||
// TODO: bake this in hprogressbar
|
// TODO: bake this in hprogressbar
|
||||||
foregroundColor:
|
foregroundColor:
|
||||||
status === "Error" ?
|
cancelPending || status === "Error" ?
|
||||||
theme.controls.progressBar.errorForeground :
|
theme.controls.progressBar.errorForeground :
|
||||||
|
|
||||||
transfer.paused ?
|
transfer.paused ?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user