refactor: move preventsleep option into CoreArgs
This commit is contained in:
committed by
Chris Rizzitello
parent
a8348b1ccb
commit
c2ee366e23
@ -139,8 +139,6 @@ bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) cons
|
||||
// HACK: stop error happening when using portable (deskflowp)
|
||||
} else if (isArg(i, argc, argv, nullptr, "--client")) {
|
||||
// HACK: stop error happening when using portable (deskflowp)
|
||||
} else if (isArg(i, argc, argv, nullptr, "--prevent-sleep")) {
|
||||
argsBase().m_preventSleep = true;
|
||||
} else {
|
||||
// option not supported here
|
||||
return false;
|
||||
|
||||
@ -50,9 +50,6 @@ public:
|
||||
/// @brief Will cause the application to exit with fail code when set to true
|
||||
bool m_shouldExitFail = false;
|
||||
|
||||
/// @brief Stop this computer from sleeping
|
||||
bool m_preventSleep = false;
|
||||
|
||||
protected:
|
||||
/// @brief deletes pointers and sets the value to null
|
||||
template <class T> static inline void destroy(T *&p)
|
||||
|
||||
@ -83,6 +83,13 @@ void CoreArgParser::parse()
|
||||
if (m_parser.isSet(CoreArgs::tlsCertOption)) {
|
||||
Settings::setValue(Settings::Security::Certificate, m_parser.value(CoreArgs::tlsCertOption));
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::preventSleepOption)) {
|
||||
bool value =
|
||||
((m_parser.value(CoreArgs::preventSleepOption).toLower() == "true") ||
|
||||
(m_parser.value(CoreArgs::preventSleepOption) == "1"));
|
||||
Settings::setValue(Settings::Core::PreventSleep, value);
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||
|
||||
@ -44,6 +44,11 @@ struct CoreArgs
|
||||
inline static const auto tlsCertOption =
|
||||
QCommandLineOption("tls-cert", "Use file in place of default TLS certificate path", "file");
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption, portOption,
|
||||
nameOption, logLevelOption, logFileOption, secureOption, tlsCertOption};
|
||||
inline static const auto preventSleepOption = QCommandLineOption(
|
||||
"prevent-sleep", "When true the machine will be prevented from sleeping while the program is running", "value"
|
||||
);
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
|
||||
portOption, nameOption, logLevelOption, logFileOption,
|
||||
secureOption, tlsCertOption, preventSleepOption};
|
||||
};
|
||||
|
||||
@ -360,8 +360,6 @@ void CoreProcess::start(std::optional<ProcessMode> processModeOption)
|
||||
|
||||
QStringList args;
|
||||
|
||||
addGenericArgs(args);
|
||||
|
||||
if (mode() == Server) {
|
||||
args.prepend(QStringLiteral("server"));
|
||||
if (!addServerArgs(args))
|
||||
@ -454,15 +452,6 @@ void CoreProcess::cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
bool CoreProcess::addGenericArgs(QStringList &args) const
|
||||
{
|
||||
if (Settings::value(Settings::Core::PreventSleep).toBool()) {
|
||||
args << "--prevent-sleep";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CoreProcess::addServerArgs(QStringList &args)
|
||||
{
|
||||
if (Settings::value(Settings::Log::ToFile).toBool()) {
|
||||
|
||||
@ -115,7 +115,6 @@ private:
|
||||
void startProcessFromDaemon(const QStringList &args);
|
||||
void stopForegroundProcess() const;
|
||||
void stopProcessFromDaemon();
|
||||
bool addGenericArgs(QStringList &args) const;
|
||||
bool addServerArgs(QStringList &args);
|
||||
bool addClientArgs(QStringList &args);
|
||||
QString persistServerConfig() const;
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "base/Log.h"
|
||||
#include "base/Stopwatch.h"
|
||||
#include "common/Constants.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/App.h"
|
||||
#include "deskflow/Clipboard.h"
|
||||
#include "deskflow/KeyMap.h"
|
||||
@ -76,7 +77,7 @@ EiScreen::EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, deskflow
|
||||
}
|
||||
|
||||
// disable sleep if the flag is set
|
||||
if (App::instance().argsBase().m_preventSleep) {
|
||||
if (Settings::value(Settings::Core::PreventSleep).toBool()) {
|
||||
m_powerManager.disableSleep();
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "base/TMethodJob.h"
|
||||
#include "client/Client.h"
|
||||
#include "common/Constants.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/App.h"
|
||||
#include "deskflow/ArgsBase.h"
|
||||
#include "deskflow/ClientApp.h"
|
||||
@ -117,7 +118,7 @@ MSWindowsScreen::MSWindowsScreen(
|
||||
LOG_DEBUG("screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_multimon ? "(multi-monitor)" : "");
|
||||
LOG_DEBUG("window is 0x%08x", m_window);
|
||||
|
||||
if (App::instance().argsBase().m_preventSleep) {
|
||||
if (Settings::value(Settings::Core::PreventSleep).toBool()) {
|
||||
m_powerManager.disableSleep();
|
||||
}
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "base/Log.h"
|
||||
#include "base/TMethodJob.h"
|
||||
#include "client/Client.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/ClientApp.h"
|
||||
#include "deskflow/Clipboard.h"
|
||||
#include "deskflow/DisplayInvalidException.h"
|
||||
@ -114,7 +115,7 @@ OSXScreen::OSXScreen(
|
||||
m_screensaver = new OSXScreenSaver(m_events, getEventTarget());
|
||||
m_keyState = new OSXKeyState(m_events, AppUtil::instance().getKeyboardLayoutList(), enableLangSync);
|
||||
|
||||
if (App::instance().argsBase().m_preventSleep) {
|
||||
if (Settings::value(Settings::Core::PreventSleep).toBool()) {
|
||||
m_powerManager.disableSleep();
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "common/Settings.h" // must include first
|
||||
|
||||
#include "platform/XWindowsScreen.h"
|
||||
|
||||
#include "arch/Arch.h"
|
||||
@ -141,7 +143,7 @@ XWindowsScreen::XWindowsScreen(
|
||||
}
|
||||
|
||||
// disable sleep if the flag is set
|
||||
if (App::instance().argsBase().m_preventSleep) {
|
||||
if (Settings::value(Settings::Core::PreventSleep).toBool()) {
|
||||
m_powerManager.disableSleep();
|
||||
}
|
||||
|
||||
|
||||
@ -234,18 +234,6 @@ void ArgParserTests::client_setInvertScroll()
|
||||
QCOMPARE(clientArgs.m_clientScrollDirection, deskflow::ClientScrollDirection::Inverted);
|
||||
}
|
||||
|
||||
void ArgParserTests::client_commonArgs()
|
||||
{
|
||||
deskflow::ClientArgs clientArgs;
|
||||
clientArgs.m_enableLangSync = false;
|
||||
const int argc = 2;
|
||||
std::array<const char *, argc> kLangCmd = {"stub", "--prevent-sleep"};
|
||||
|
||||
m_parser.parseClientArgs(clientArgs, argc, kLangCmd.data());
|
||||
|
||||
QVERIFY(clientArgs.m_preventSleep);
|
||||
}
|
||||
|
||||
void ArgParserTests::client_setAddress()
|
||||
{
|
||||
deskflow::ClientArgs clientArgs;
|
||||
|
||||
@ -28,7 +28,6 @@ private Q_SLOTS:
|
||||
void client_yScroll();
|
||||
void client_setLangSync();
|
||||
void client_setInvertScroll();
|
||||
void client_commonArgs();
|
||||
void client_setAddress();
|
||||
void client_badArgs();
|
||||
void deprecatedArg_crypoPass_true();
|
||||
|
||||
@ -160,4 +160,44 @@ void CoreArgParserTests::tlsCert()
|
||||
QCOMPARE(Settings::value(Settings::Security::Certificate).toString(), "certFile");
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_false()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "false"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_1()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_0()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "0"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(!Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "true"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QVERIFY(Settings::value(Settings::Core::PreventSleep).toBool());
|
||||
}
|
||||
|
||||
QTEST_MAIN(CoreArgParserTests)
|
||||
|
||||
@ -28,6 +28,10 @@ private Q_SLOTS:
|
||||
void secure_0();
|
||||
void secure_1();
|
||||
void tlsCert();
|
||||
void preventSleep_true();
|
||||
void preventSleep_false();
|
||||
void preventSleep_1();
|
||||
void preventSleep_0();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
|
||||
Reference in New Issue
Block a user