🔧 fix: trigger preview action when color or palette changes

This commit is contained in:
2026-02-28 22:51:04 +01:00
parent 603adb1a7a
commit 4c482937a1
4 changed files with 53 additions and 25 deletions
+1 -1
View File
@@ -190,7 +190,7 @@ Initial sorting behavior for loaded images.
"previewDebounceTime": 500, "previewDebounceTime": 500,
"quitOnSelected": true, "quitOnSelected": true,
"onPreview": "swww img {{ path }}", "onPreview": "swww img {{ path }}",
"onSelected": "cp {{ path }} ~/.config/current_wallpaper.jpg", "onSelected": "cp {{ path }} ~/.config/wallpaper/current/ && swww img {{ path }}",
"saveState": [ "saveState": [
{ {
"key": "current_wp", "key": "current_wp",
+5
View File
@@ -45,6 +45,11 @@ class Bootstrap {
*paletteMgr); *paletteMgr);
} }
void start() {
configMgr->captureState();
imageMgr->loadAndProcess(configMgr->getWallpapers());
}
~Bootstrap() { ~Bootstrap() {
delete ServiceMgr; delete ServiceMgr;
delete paletteMgr; delete paletteMgr;
+23 -7
View File
@@ -208,24 +208,45 @@ class Carousel : public QObject {
connect(m_serviceMgr, &Service::Manager::restoreCompleted, this, &Carousel::restoreCompleted); connect(m_serviceMgr, &Service::Manager::restoreCompleted, this, &Carousel::restoreCompleted);
connect(m_serviceMgr, &Service::Manager::cancelCompleted, this, &Carousel::cancelCompleted); connect(m_serviceMgr, &Service::Manager::cancelCompleted, this, &Carousel::cancelCompleted);
// "Preview" is costly, but is (usually) protected by a debounce timer, so it seems fine
// to call it multiple times in a short period, and it simplifies the code a lot :)
// Preview on imageid change // Preview on imageid change
connect(this, &Carousel::currentImageIdChanged, this, [this]() { connect(this, &Carousel::currentImageIdChanged, this, [this]() {
if (!m_currentImageId.isEmpty()) { if (!m_currentImageId.isEmpty()) {
m_serviceMgr->previewWallpaper(m_currentImageId); m_serviceMgr->previewWallpaper(m_currentImageId);
} }
}); });
// Update color when imageid changes // Update displayed color when imageid changes
connect(this, &Carousel::currentImageIdChanged, this, [this]() { connect(this, &Carousel::currentImageIdChanged, this, [this]() {
if (!m_currentImageId.isEmpty()) { if (!m_currentImageId.isEmpty()) {
m_paletteMgr->updateColor(m_currentImageId); m_paletteMgr->updateColor(m_currentImageId);
} }
}); });
// Update color when selected color changes // Update displayed color when selected color changes
connect(this, &Carousel::selectedColorChanged, this, [this]() { connect(this, &Carousel::selectedColorChanged, this, [this]() {
if (!m_currentImageId.isEmpty()) { if (!m_currentImageId.isEmpty()) {
m_paletteMgr->updateColor(m_currentImageId); m_paletteMgr->updateColor(m_currentImageId);
} }
}); });
// Preview on selected palette change
connect(this, &Carousel::selectedPaletteChanged, this, [this]() {
if (!m_currentImageId.isEmpty()) {
m_serviceMgr->previewWallpaper(m_currentImageId);
}
});
// Preview on displayed color name change
connect(this, &Carousel::colorNameChanged, this, [this]() {
if (!m_currentImageId.isEmpty()) {
m_serviceMgr->previewWallpaper(m_currentImageId);
}
});
// Preview on displayed color hex change
connect(this, &Carousel::colorChanged, this, [this]() {
if (!m_currentImageId.isEmpty()) {
m_serviceMgr->previewWallpaper(m_currentImageId);
}
});
// Quit on selected // Quit on selected
if (m_configMgr->getActionConfig().quitOnSelected) { if (m_configMgr->getActionConfig().quitOnSelected) {
@@ -257,11 +278,6 @@ class Carousel : public QObject {
setSortDescending(m_configMgr->getSortConfig().descending); setSortDescending(m_configMgr->getSortConfig().descending);
} }
void start() {
m_configMgr->captureState();
m_imageMgr->loadAndProcess(m_configMgr->getWallpapers());
}
private: private:
Config::Manager* m_configMgr; Config::Manager* m_configMgr;
Image::Manager* m_imageMgr; Image::Manager* m_imageMgr;
+8 -1
View File
@@ -20,6 +20,11 @@ using namespace WallReel::Core;
WALLREEL_DECLARE_SENDER("Main") WALLREEL_DECLARE_SENDER("Main")
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Destruction order after QApplication quits its event loop:
// 1. QQmlApplicationEngine (with all QML objects)
// 2. provider (manages states and connections)
// 3. bootstrap (manages lifecycle of all managers)
// 4. QApplication
QApplication a(argc, argv); QApplication a(argc, argv);
a.setApplicationName(APP_NAME); a.setApplicationName(APP_NAME);
@@ -42,6 +47,7 @@ int main(int argc, char* argv[]) {
return 0; return 0;
} }
{
Provider::Carousel provider(&a, bootstrap); Provider::Carousel provider(&a, bootstrap);
qmlRegisterSingletonInstance( qmlRegisterSingletonInstance(
COREMODULE_URI, COREMODULE_URI,
@@ -60,9 +66,10 @@ int main(int argc, char* argv[]) {
Qt::QueuedConnection); Qt::QueuedConnection);
engine.loadFromModule(UIMODULE_URI, "Main"); engine.loadFromModule(UIMODULE_URI, "Main");
provider.start(); bootstrap.start();
return a.exec(); return a.exec();
} }
} }
} }
}