HMxcImage: cancel media retrieval on destruction
This commit is contained in:
parent
7e5896f52b
commit
630e011cfd
|
@ -1,15 +1,18 @@
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
|
import "../PythonBridge"
|
||||||
|
|
||||||
HImage {
|
HImage {
|
||||||
id: image
|
id: image
|
||||||
inderterminateProgressBar: isMxc
|
inderterminateProgressBar: isMxc
|
||||||
source: sourceOverride || (show ? cachedPath : "")
|
source: sourceOverride || (show ? cachedPath : "")
|
||||||
|
|
||||||
onWidthChanged: Qt.callLater(update)
|
onWidthChanged: Qt.callLater(update)
|
||||||
onHeightChanged: Qt.callLater(update)
|
onHeightChanged: Qt.callLater(update)
|
||||||
onVisibleChanged: Qt.callLater(update)
|
onVisibleChanged: Qt.callLater(update)
|
||||||
onMxcChanged: Qt.callLater(update)
|
onMxcChanged: Qt.callLater(update)
|
||||||
|
Component.onDestruction: if (getFuture) getFuture.cancel()
|
||||||
|
|
||||||
|
|
||||||
property string mxc
|
property string mxc
|
||||||
|
@ -20,6 +23,9 @@ HImage {
|
||||||
|
|
||||||
property bool show: false
|
property bool show: false
|
||||||
property string cachedPath: ""
|
property string cachedPath: ""
|
||||||
|
|
||||||
|
property Future getFuture: null
|
||||||
|
|
||||||
readonly property bool isMxc: mxc.startsWith("mxc://")
|
readonly property bool isMxc: mxc.startsWith("mxc://")
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,15 +51,16 @@ HImage {
|
||||||
[image.mxc, image.title, w, h, cryptDict] :
|
[image.mxc, image.title, w, h, cryptDict] :
|
||||||
[image.mxc, image.title, cryptDict]
|
[image.mxc, image.title, cryptDict]
|
||||||
|
|
||||||
py.callCoro("media_cache." + method, args, path => {
|
getFuture = py.callCoro("media_cache." + method, args, path => {
|
||||||
if (! image) return
|
if (! image) return
|
||||||
if (image.cachedPath !== path) image.cachedPath = path
|
if (image.cachedPath !== path) image.cachedPath = path
|
||||||
|
|
||||||
image.broken = false
|
image.broken = false
|
||||||
image.show = image.visible
|
image.show = image.visible
|
||||||
|
|
||||||
}, () => {
|
}, (type, args, error, traceback) => {
|
||||||
image.broken = true
|
print(`Error retrieving ${mxc} (${title}):\n${traceback}`)
|
||||||
|
if (image) image.broken = true
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,7 @@ QtObject {
|
||||||
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
||||||
const args = py.getattr(error, "args")
|
const args = py.getattr(error, "args")
|
||||||
|
|
||||||
if (type === "CancelledError") {
|
if (type === "CancelledError") return
|
||||||
console.warn(`python: cancelled: ${uuid}`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onError) {
|
if (onError) {
|
||||||
onError(type, args, error, traceback)
|
onError(type, args, error, traceback)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user