Improve handling of DonwloadAction

Set the progress the download action only when the currentProgressInfo
changed, otherwise we sometimes end up in a data race.
This commit is contained in:
Carl Schwan
2025-01-09 15:08:58 +01:00
committed by Carl Schwan
parent 7231662f94
commit 2a9c75e24f

View File

@@ -29,13 +29,20 @@ Components.AlbumMaximizeComponent {
readonly property var currentProgressInfo: model.data(model.index(content.currentIndex, 0), TimelineMessageModel.ProgressInfoRole) readonly property var currentProgressInfo: model.data(model.index(content.currentIndex, 0), TimelineMessageModel.ProgressInfoRole)
onCurrentProgressInfoChanged: () => {
if (root.currentProgressInfo) {
root.downloadAction.progress = root.currentProgressInfo.progress / root.currentProgressInfo.total * 100.0;
} else {
root.downloadAction.progress = 0;
}
}
/** /**
* @brief Whether the delegate is part of a thread timeline. * @brief Whether the delegate is part of a thread timeline.
*/ */
property bool isThread: false property bool isThread: false
downloadAction: Components.DownloadAction { downloadAction: Components.DownloadAction {
id: downloadAction
onTriggered: { onTriggered: {
currentRoom.downloadFile(root.currentEventId, Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + root.currentEventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(root.currentEventId)); currentRoom.downloadFile(root.currentEventId, Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + root.currentEventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(root.currentEventId));
} }
@@ -62,19 +69,11 @@ Components.AlbumMaximizeComponent {
function onFileTransferProgress(id, progress, total) { function onFileTransferProgress(id, progress, total) {
if (id == root.currentEventId) { if (id == root.currentEventId) {
downloadAction.progress = progress / total * 100.0; root.downloadAction.progress = progress / total * 100.0;
} }
} }
} }
Connections {
target: content
function onCurrentIndexChanged() {
downloadAction.progress = currentProgressInfo.progress / currentProgressInfo.total * 100.0;
}
}
leading: RowLayout { leading: RowLayout {
Components.Avatar { Components.Avatar {
id: userAvatar id: userAvatar