diff --git a/README.md b/README.md index 32ce986..2e8eb56 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ Initial sorting behavior for loaded images. "previewDebounceTime": 500, "quitOnSelected": true, "onPreview": "swww img {{ path }}", - "onSelected": "cp {{ path }} ~/.config/current_wallpaper.jpg", + "onSelected": "cp {{ path }} ~/.config/wallpaper/current/ && swww img {{ path }}", "saveState": [ { "key": "current_wp", diff --git a/WallReel/Core/Provider/bootstrap.hpp b/WallReel/Core/Provider/bootstrap.hpp index cd81aa8..0c8d4b1 100644 --- a/WallReel/Core/Provider/bootstrap.hpp +++ b/WallReel/Core/Provider/bootstrap.hpp @@ -45,6 +45,11 @@ class Bootstrap { *paletteMgr); } + void start() { + configMgr->captureState(); + imageMgr->loadAndProcess(configMgr->getWallpapers()); + } + ~Bootstrap() { delete ServiceMgr; delete paletteMgr; diff --git a/WallReel/Core/Provider/carousel.hpp b/WallReel/Core/Provider/carousel.hpp index 6d997e1..532741f 100644 --- a/WallReel/Core/Provider/carousel.hpp +++ b/WallReel/Core/Provider/carousel.hpp @@ -208,24 +208,45 @@ class Carousel : public QObject { connect(m_serviceMgr, &Service::Manager::restoreCompleted, this, &Carousel::restoreCompleted); 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 connect(this, &Carousel::currentImageIdChanged, this, [this]() { if (!m_currentImageId.isEmpty()) { m_serviceMgr->previewWallpaper(m_currentImageId); } }); - // Update color when imageid changes + // Update displayed color when imageid changes connect(this, &Carousel::currentImageIdChanged, this, [this]() { if (!m_currentImageId.isEmpty()) { m_paletteMgr->updateColor(m_currentImageId); } }); - // Update color when selected color changes + // Update displayed color when selected color changes connect(this, &Carousel::selectedColorChanged, this, [this]() { if (!m_currentImageId.isEmpty()) { 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 if (m_configMgr->getActionConfig().quitOnSelected) { @@ -257,11 +278,6 @@ class Carousel : public QObject { setSortDescending(m_configMgr->getSortConfig().descending); } - void start() { - m_configMgr->captureState(); - m_imageMgr->loadAndProcess(m_configMgr->getWallpapers()); - } - private: Config::Manager* m_configMgr; Image::Manager* m_imageMgr; diff --git a/WallReel/main.cpp b/WallReel/main.cpp index 774f3b4..cdce1e6 100644 --- a/WallReel/main.cpp +++ b/WallReel/main.cpp @@ -20,6 +20,11 @@ using namespace WallReel::Core; WALLREEL_DECLARE_SENDER("Main") 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); a.setApplicationName(APP_NAME); @@ -42,27 +47,29 @@ int main(int argc, char* argv[]) { return 0; } - Provider::Carousel provider(&a, bootstrap); - qmlRegisterSingletonInstance( - COREMODULE_URI, - MODULE_VERSION_MAJOR, - MODULE_VERSION_MINOR, - "CarouselProvider", - &provider); { - QQmlApplicationEngine engine; + Provider::Carousel provider(&a, bootstrap); + qmlRegisterSingletonInstance( + COREMODULE_URI, + MODULE_VERSION_MAJOR, + MODULE_VERSION_MINOR, + "CarouselProvider", + &provider); + { + QQmlApplicationEngine engine; - QObject::connect( - &engine, - &QQmlApplicationEngine::objectCreationFailed, - &a, - []() { QCoreApplication::exit(-1); }, - Qt::QueuedConnection); - engine.loadFromModule(UIMODULE_URI, "Main"); + QObject::connect( + &engine, + &QQmlApplicationEngine::objectCreationFailed, + &a, + []() { QCoreApplication::exit(-1); }, + Qt::QueuedConnection); + engine.loadFromModule(UIMODULE_URI, "Main"); - provider.start(); + bootstrap.start(); - return a.exec(); + return a.exec(); + } } } }