✨ feat: add option to disable actions via command line
This commit is contained in:
@@ -47,7 +47,8 @@ class Bootstrap {
|
|||||||
serviceMgr = new Service::Manager(
|
serviceMgr = new Service::Manager(
|
||||||
configMgr->getActionConfig(),
|
configMgr->getActionConfig(),
|
||||||
*imageMgr,
|
*imageMgr,
|
||||||
*paletteMgr);
|
*paletteMgr,
|
||||||
|
options.disableActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
|
|||||||
@@ -11,7 +11,12 @@ Manager::Manager(
|
|||||||
const Config::ActionConfigItems& actionConfig,
|
const Config::ActionConfigItems& actionConfig,
|
||||||
Image::Manager& imageManager,
|
Image::Manager& imageManager,
|
||||||
Palette::Manager& paletteManager,
|
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);
|
m_wallpaperService = new WallpaperService(m_actionConfig.previewDebounceTime, this);
|
||||||
|
|
||||||
// Forward signals
|
// Forward signals
|
||||||
@@ -35,6 +40,11 @@ void Manager::onStateCaptured() {
|
|||||||
|
|
||||||
void Manager::selectWallpaper(const QString& id) {
|
void Manager::selectWallpaper(const QString& id) {
|
||||||
WR_DEBUG("Select action triggered for id " + 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) {
|
if (m_isProcessing) {
|
||||||
WR_DEBUG("Already processing an select action, ignoring new request");
|
WR_DEBUG("Already processing an select action, ignoring new request");
|
||||||
return;
|
return;
|
||||||
@@ -57,6 +67,11 @@ void Manager::selectWallpaper(const QString& id) {
|
|||||||
|
|
||||||
void Manager::restore() {
|
void Manager::restore() {
|
||||||
WR_DEBUG("Restore action triggered");
|
WR_DEBUG("Restore action triggered");
|
||||||
|
if (m_disableActions) {
|
||||||
|
WR_DEBUG("Actions are disabled, skipping restore");
|
||||||
|
emit restoreCompleted(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (m_isProcessing) {
|
if (m_isProcessing) {
|
||||||
WR_DEBUG("Already processing an restore action, ignoring new request");
|
WR_DEBUG("Already processing an restore action, ignoring new request");
|
||||||
return;
|
return;
|
||||||
@@ -74,11 +89,21 @@ void Manager::restore() {
|
|||||||
|
|
||||||
void Manager::cancel() {
|
void Manager::cancel() {
|
||||||
WR_DEBUG("Cancel action triggered");
|
WR_DEBUG("Cancel action triggered");
|
||||||
|
if (m_disableActions) {
|
||||||
|
WR_DEBUG("Actions are disabled, skipping cancel");
|
||||||
|
emit cancelCompleted();
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_wallpaperService->stopAll();
|
m_wallpaperService->stopAll();
|
||||||
emit cancelCompleted();
|
emit cancelCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::previewWallpaper(const QString& id) {
|
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) {
|
if (!m_stateCaptured) {
|
||||||
WR_DEBUG("State not captured yet, deferring preview for id " + id);
|
WR_DEBUG("State not captured yet, deferring preview for id " + id);
|
||||||
m_pendingPreviewId = id;
|
m_pendingPreviewId = id;
|
||||||
@@ -101,11 +126,15 @@ void Manager::previewWallpaper(const QString& id) {
|
|||||||
|
|
||||||
void Manager::restoreOnQuit() {
|
void Manager::restoreOnQuit() {
|
||||||
if (m_hasSelected) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
Logger::debug("ServiceManager", "Restore on quit");
|
WR_DEBUG("Restore on quit");
|
||||||
m_wallpaperService->stopAll();
|
m_wallpaperService->stopAll();
|
||||||
|
if (m_disableActions) {
|
||||||
|
WR_DEBUG("Actions are disabled, skipping restore on quit");
|
||||||
|
return;
|
||||||
|
}
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(this, &Manager::restoreCompleted, &loop, &QEventLoop::quit);
|
connect(this, &Manager::restoreCompleted, &loop, &QEventLoop::quit);
|
||||||
// Call restore after the event loop starts
|
// Call restore after the event loop starts
|
||||||
@@ -114,14 +143,14 @@ void Manager::restoreOnQuit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Manager::_onSelectCompleted(bool success) {
|
void Manager::_onSelectCompleted(bool success) {
|
||||||
Logger::debug("ServiceManager", "Select completed");
|
WR_DEBUG("Select completed");
|
||||||
_onProcessCompleted();
|
_onProcessCompleted();
|
||||||
m_hasSelected = m_hasSelected || success;
|
m_hasSelected = m_hasSelected || success;
|
||||||
emit selectCompleted(success);
|
emit selectCompleted(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::_onRestoreCompleted(bool success) {
|
void Manager::_onRestoreCompleted(bool success) {
|
||||||
Logger::debug("ServiceManager", "Restore completed");
|
WR_DEBUG("Restore completed");
|
||||||
_onProcessCompleted();
|
_onProcessCompleted();
|
||||||
emit restoreCompleted(success);
|
emit restoreCompleted(success);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ class Manager : public QObject {
|
|||||||
const Config::ActionConfigItems& actionConfig,
|
const Config::ActionConfigItems& actionConfig,
|
||||||
Image::Manager& imageManager,
|
Image::Manager& imageManager,
|
||||||
Palette::Manager& paletteManager,
|
Palette::Manager& paletteManager,
|
||||||
QObject* parent = nullptr);
|
bool disableActions = false,
|
||||||
|
QObject* parent = nullptr);
|
||||||
|
|
||||||
bool isProcessing() const { return m_isProcessing; }
|
bool isProcessing() const { return m_isProcessing; }
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ class Manager : public QObject {
|
|||||||
const Config::ActionConfigItems& m_actionConfig;
|
const Config::ActionConfigItems& m_actionConfig;
|
||||||
Image::Manager& m_imageManager;
|
Image::Manager& m_imageManager;
|
||||||
Palette::Manager& m_paletteManager;
|
Palette::Manager& m_paletteManager;
|
||||||
|
bool m_disableActions;
|
||||||
|
|
||||||
bool m_isProcessing = false;
|
bool m_isProcessing = false;
|
||||||
bool m_hasSelected = false;
|
bool m_hasSelected = false;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "appoptions.hpp"
|
#include "appoptions.hpp"
|
||||||
|
|
||||||
|
#include <qcommandlineoption.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCommandLineOption>
|
#include <QCommandLineOption>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
@@ -67,6 +69,9 @@ void AppOptions::parseArgs(QApplication& app) {
|
|||||||
QCommandLineOption configFileOption(QStringList() << "c" << "config-file", "Specify a custom configuration file", "file");
|
QCommandLineOption configFileOption(QStringList() << "c" << "config-file", "Specify a custom configuration file", "file");
|
||||||
parser.addOption(configFileOption);
|
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");
|
QCommandLineOption applyOption(QStringList() << "a" << "apply", "Apply the specified image as wallpaper and exit", "file");
|
||||||
parser.addOption(applyOption);
|
parser.addOption(applyOption);
|
||||||
|
|
||||||
@@ -124,6 +129,10 @@ void AppOptions::parseArgs(QApplication& app) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(disableActionsOption)) {
|
||||||
|
disableActions = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (parser.isSet(applyOption)) {
|
if (parser.isSet(applyOption)) {
|
||||||
QString path = Utils::expandPath(parser.value(applyOption));
|
QString path = Utils::expandPath(parser.value(applyOption));
|
||||||
if (Utils::checkImageFile(path)) {
|
if (Utils::checkImageFile(path)) {
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ class AppOptions {
|
|||||||
QString configPath;
|
QString configPath;
|
||||||
QStringList appendDirs;
|
QStringList appendDirs;
|
||||||
QString errorText;
|
QString errorText;
|
||||||
QString applyPath; // -a --apply
|
QString applyPath; // -a --apply
|
||||||
bool clearCache = false; // -C --clear-cache
|
bool clearCache = false; // -C --clear-cache
|
||||||
bool doReturn = false; ///< Indicates whether the application should exit after parsing arguments.
|
bool disableActions = false; // -D --disable-actions
|
||||||
|
bool doReturn = false; ///< Indicates whether the application should exit after parsing arguments.
|
||||||
|
|
||||||
AppOptions();
|
AppOptions();
|
||||||
void parseArgs(QApplication& app);
|
void parseArgs(QApplication& app);
|
||||||
|
|||||||
Reference in New Issue
Block a user