From 2a9c75e24fc3f6485c32d64b1fceee66d1455d2b Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 9 Jan 2025 15:08:58 +0100 Subject: [PATCH] Improve handling of DonwloadAction Set the progress the download action only when the currentProgressInfo changed, otherwise we sometimes end up in a data race. --- src/qml/NeochatMaximizeComponent.qml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/qml/NeochatMaximizeComponent.qml b/src/qml/NeochatMaximizeComponent.qml index 0dcbf7ff0..fc9ff7f48 100644 --- a/src/qml/NeochatMaximizeComponent.qml +++ b/src/qml/NeochatMaximizeComponent.qml @@ -29,13 +29,20 @@ Components.AlbumMaximizeComponent { 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. */ property bool isThread: false downloadAction: Components.DownloadAction { - id: downloadAction onTriggered: { 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) { 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 { Components.Avatar { id: userAvatar