summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/cachingimagemanager.cpp
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-08-27 22:13:21 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-08-27 22:13:21 +1000
commit573423742a77816699f219817ba462c7f6f5d33a (patch)
tree9461ebfe7cb097439489a21094cebc4b3d430d59 /plugin/src/Caelestia/cachingimagemanager.cpp
parentplugin/cim: fix cache dir (diff)
downloadcaelestia-shell-573423742a77816699f219817ba462c7f6f5d33a.tar.gz
caelestia-shell-573423742a77816699f219817ba462c7f6f5d33a.tar.bz2
caelestia-shell-573423742a77816699f219817ba462c7f6f5d33a.zip
plugin: make thread safe
Diffstat (limited to 'plugin/src/Caelestia/cachingimagemanager.cpp')
-rw-r--r--plugin/src/Caelestia/cachingimagemanager.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/plugin/src/Caelestia/cachingimagemanager.cpp b/plugin/src/Caelestia/cachingimagemanager.cpp
index d549e8c..d95af27 100644
--- a/plugin/src/Caelestia/cachingimagemanager.cpp
+++ b/plugin/src/Caelestia/cachingimagemanager.cpp
@@ -70,34 +70,33 @@ void CachingImageManager::setPath(const QString& path) {
if (!path.isEmpty()) {
QThreadPool::globalInstance()->start([path, this] {
- const QString filename = QString("%1@%2x%3.png")
- .arg(sha256sum(path))
- .arg(effectiveWidth())
- .arg(effectiveHeight());
+ const QString sha = sha256sum(path);
- m_cachePath = m_cacheDir.resolved(QUrl(filename));
- emit cachePathChanged();
+ QMetaObject::invokeMethod(this, [path, sha, this]() {
+ const QString filename = QString("%1@%2x%3.png")
+ .arg(sha)
+ .arg(effectiveWidth())
+ .arg(effectiveHeight());
- if (!m_cachePath.isLocalFile()) {
- qWarning() << "CachingImageManager::setPath: cachePath" << m_cachePath << "is not a local file";
- return;
- }
+ m_cachePath = m_cacheDir.resolved(QUrl(filename));
+ emit cachePathChanged();
- if (QFile::exists(m_cachePath.toLocalFile())) {
- QMetaObject::invokeMethod(m_item, [this]() {
- m_item->setProperty("source", m_cachePath);
- }, Qt::QueuedConnection);
+ if (!m_cachePath.isLocalFile()) {
+ qWarning() << "CachingImageManager::setPath: cachePath" << m_cachePath << "is not a local file";
+ return;
+ }
- m_usingCache = true;
- emit usingCacheChanged();
- } else {
- QMetaObject::invokeMethod(m_item, [path, this]() {
+ bool cacheExists = QFile::exists(m_cachePath.toLocalFile());
+
+ if (cacheExists) {
+ m_item->setProperty("source", m_cachePath);
+ } else {
m_item->setProperty("source", QUrl::fromLocalFile(path));
- }, Qt::QueuedConnection);
+ }
- m_usingCache = false;
+ m_usingCache = cacheExists;
emit usingCacheChanged();
- }
+ });
});
}
}