From 23c80d30e9c6122123b9b220b95f668aa6c31d31 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Tue, 24 Mar 2026 05:36:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20option=20to=20disable?= =?UTF-8?q?=20actions=20via=20command=20line?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WallReel/Core/Provider/bootstrap.hpp | 3 ++- WallReel/Core/Service/manager.cpp | 39 ++++++++++++++++++++++++---- WallReel/Core/Service/manager.hpp | 4 ++- WallReel/Core/appoptions.cpp | 9 +++++++ WallReel/Core/appoptions.hpp | 7 ++--- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/WallReel/Core/Provider/bootstrap.hpp b/WallReel/Core/Provider/bootstrap.hpp index 4f4b4c9..e561ce3 100644 --- a/WallReel/Core/Provider/bootstrap.hpp +++ b/WallReel/Core/Provider/bootstrap.hpp @@ -47,7 +47,8 @@ class Bootstrap { serviceMgr = new Service::Manager( configMgr->getActionConfig(), *imageMgr, - *paletteMgr); + *paletteMgr, + options.disableActions); } void start() { diff --git a/WallReel/Core/Service/manager.cpp b/WallReel/Core/Service/manager.cpp index 3e45000..bd1345e 100644 --- a/WallReel/Core/Service/manager.cpp +++ b/WallReel/Core/Service/manager.cpp @@ -11,7 +11,12 @@ Manager::Manager( const Config::ActionConfigItems& actionConfig, Image::Manager& imageManager, Palette::Manager& paletteManager, - QObject* parent) : m_actionConfig(actionConfig), m_imageManager(imageManager), m_paletteManager(paletteManager) { + bool disableActions, + QObject* parent) + : m_actionConfig(actionConfig), + m_imageManager(imageManager), + m_paletteManager(paletteManager), + m_disableActions(disableActions) { m_wallpaperService = new WallpaperService(m_actionConfig.previewDebounceTime, this); // Forward signals @@ -35,6 +40,11 @@ void Manager::onStateCaptured() { void Manager::selectWallpaper(const QString& id) { WR_DEBUG("Select action triggered for id " + id); + if (m_disableActions) { + WR_DEBUG("Actions are disabled, skipping select for id " + id); + emit selectCompleted(true); + return; + } if (m_isProcessing) { WR_DEBUG("Already processing an select action, ignoring new request"); return; @@ -57,6 +67,11 @@ void Manager::selectWallpaper(const QString& id) { void Manager::restore() { WR_DEBUG("Restore action triggered"); + if (m_disableActions) { + WR_DEBUG("Actions are disabled, skipping restore"); + emit restoreCompleted(true); + return; + } if (m_isProcessing) { WR_DEBUG("Already processing an restore action, ignoring new request"); return; @@ -74,11 +89,21 @@ void Manager::restore() { void Manager::cancel() { WR_DEBUG("Cancel action triggered"); + if (m_disableActions) { + WR_DEBUG("Actions are disabled, skipping cancel"); + emit cancelCompleted(); + return; + } m_wallpaperService->stopAll(); emit cancelCompleted(); } void Manager::previewWallpaper(const QString& id) { + if (m_disableActions) { + WR_DEBUG("Actions are disabled, skipping preview for id " + id); + emit previewCompleted(true); + return; + } if (!m_stateCaptured) { WR_DEBUG("State not captured yet, deferring preview for id " + id); m_pendingPreviewId = id; @@ -101,11 +126,15 @@ void Manager::previewWallpaper(const QString& id) { void Manager::restoreOnQuit() { if (m_hasSelected) { - Logger::debug("ServiceManager", "Quit with selected wallpaper, no need to restore"); + WR_DEBUG("Quit with selected wallpaper, no need to restore"); return; } - Logger::debug("ServiceManager", "Restore on quit"); + WR_DEBUG("Restore on quit"); m_wallpaperService->stopAll(); + if (m_disableActions) { + WR_DEBUG("Actions are disabled, skipping restore on quit"); + return; + } QEventLoop loop; connect(this, &Manager::restoreCompleted, &loop, &QEventLoop::quit); // Call restore after the event loop starts @@ -114,14 +143,14 @@ void Manager::restoreOnQuit() { } void Manager::_onSelectCompleted(bool success) { - Logger::debug("ServiceManager", "Select completed"); + WR_DEBUG("Select completed"); _onProcessCompleted(); m_hasSelected = m_hasSelected || success; emit selectCompleted(success); } void Manager::_onRestoreCompleted(bool success) { - Logger::debug("ServiceManager", "Restore completed"); + WR_DEBUG("Restore completed"); _onProcessCompleted(); emit restoreCompleted(success); } diff --git a/WallReel/Core/Service/manager.hpp b/WallReel/Core/Service/manager.hpp index e87b6d5..ddfe343 100644 --- a/WallReel/Core/Service/manager.hpp +++ b/WallReel/Core/Service/manager.hpp @@ -21,7 +21,8 @@ class Manager : public QObject { const Config::ActionConfigItems& actionConfig, Image::Manager& imageManager, Palette::Manager& paletteManager, - QObject* parent = nullptr); + bool disableActions = false, + QObject* parent = nullptr); bool isProcessing() const { return m_isProcessing; } @@ -65,6 +66,7 @@ class Manager : public QObject { const Config::ActionConfigItems& m_actionConfig; Image::Manager& m_imageManager; Palette::Manager& m_paletteManager; + bool m_disableActions; bool m_isProcessing = false; bool m_hasSelected = false; diff --git a/WallReel/Core/appoptions.cpp b/WallReel/Core/appoptions.cpp index a6528ea..270319c 100644 --- a/WallReel/Core/appoptions.cpp +++ b/WallReel/Core/appoptions.cpp @@ -1,5 +1,7 @@ #include "appoptions.hpp" +#include + #include #include #include @@ -67,6 +69,9 @@ void AppOptions::parseArgs(QApplication& app) { QCommandLineOption configFileOption(QStringList() << "c" << "config-file", "Specify a custom configuration file", "file"); parser.addOption(configFileOption); + QCommandLineOption disableActionsOption(QStringList() << "D" << "disable-actions", "Disable actions set in configuration file"); + parser.addOption(disableActionsOption); + QCommandLineOption applyOption(QStringList() << "a" << "apply", "Apply the specified image as wallpaper and exit", "file"); parser.addOption(applyOption); @@ -124,6 +129,10 @@ void AppOptions::parseArgs(QApplication& app) { } } + if (parser.isSet(disableActionsOption)) { + disableActions = true; + } + if (parser.isSet(applyOption)) { QString path = Utils::expandPath(parser.value(applyOption)); if (Utils::checkImageFile(path)) { diff --git a/WallReel/Core/appoptions.hpp b/WallReel/Core/appoptions.hpp index bc1ac51..9238a6b 100644 --- a/WallReel/Core/appoptions.hpp +++ b/WallReel/Core/appoptions.hpp @@ -26,9 +26,10 @@ class AppOptions { QString configPath; QStringList appendDirs; QString errorText; - QString applyPath; // -a --apply - bool clearCache = false; // -C --clear-cache - bool doReturn = false; ///< Indicates whether the application should exit after parsing arguments. + QString applyPath; // -a --apply + bool clearCache = false; // -C --clear-cache + bool disableActions = false; // -D --disable-actions + bool doReturn = false; ///< Indicates whether the application should exit after parsing arguments. AppOptions(); void parseArgs(QApplication& app);