🔧 fix: trigger preview action when color or palette changes
This commit is contained in:
@@ -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",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
+24
-17
@@ -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,27 +47,29 @@ int main(int argc, char* argv[]) {
|
|||||||
return 0;
|
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(
|
QObject::connect(
|
||||||
&engine,
|
&engine,
|
||||||
&QQmlApplicationEngine::objectCreationFailed,
|
&QQmlApplicationEngine::objectCreationFailed,
|
||||||
&a,
|
&a,
|
||||||
[]() { QCoreApplication::exit(-1); },
|
[]() { QCoreApplication::exit(-1); },
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
engine.loadFromModule(UIMODULE_URI, "Main");
|
engine.loadFromModule(UIMODULE_URI, "Main");
|
||||||
|
|
||||||
provider.start();
|
bootstrap.start();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user