refactor: move --no-hooks to coreArgs

This commit is contained in:
sithlord48
2025-09-24 20:38:18 -04:00
committed by Chris Rizzitello
parent eeaf139bd9
commit 1884ab3555
12 changed files with 46 additions and 29 deletions

View File

@ -117,9 +117,10 @@ QVariant Settings::defaultValue(const QString &key)
return false;
}
if ((key == Core::RestartOnFailure) || (key == Gui::CloseToTray) || (key == Gui::LogExpanded) ||
(key == Gui::SymbolicTrayIcon) || (key == Gui::CloseReminder) || (key == Security::TlsEnabled) ||
(key == Security::CheckPeers) || (key == Client::LanguageSync) || (key == Gui::ShowGenericClientFailureDialog)) {
if ((key == Core::RestartOnFailure) || (key == Core::UseHooks) || (key == Gui::CloseToTray) ||
(key == Gui::LogExpanded) || (key == Gui::SymbolicTrayIcon) || (key == Gui::CloseReminder) ||
(key == Security::TlsEnabled) || (key == Security::CheckPeers) || (key == Client::LanguageSync) ||
(key == Gui::ShowGenericClientFailureDialog)) {
return true;
}

View File

@ -51,6 +51,7 @@ public:
inline static const auto UpdateUrl = QStringLiteral("core/updateUrl");
inline static const auto Display = QStringLiteral("core/display");
inline static const auto RestartOnFailure = QStringLiteral("core/restartOnFailure");
inline static const auto UseHooks = QStringLiteral("core/useHooks");
};
struct Daemon
{
@ -175,6 +176,7 @@ private:
, Settings::Core::UpdateUrl
, Settings::Core::Display
, Settings::Core::RestartOnFailure
, Settings::Core::UseHooks
, Settings::Daemon::Command
, Settings::Daemon::Elevate
, Settings::Daemon::LogFile

View File

@ -101,17 +101,11 @@ bool ArgParser::parseClientArgs(deskflow::ClientArgs &args, int argc, const char
bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) const
{
if (isArg(i, argc, argv, nullptr, "--no-hooks")) {
argsBase().m_noHooks = true;
} else if (isArg(i, argc, argv, "-h", "--help")) {
if (isArg(i, argc, argv, "-h", "--help")) {
if (m_app) {
m_app->help();
}
argsBase().m_shouldExitOk = true;
} else if (isArg(i, argc, argv, nullptr, "--server")) {
// 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 {
// option not supported here
return false;

View File

@ -32,9 +32,6 @@ public:
/// @brief Stores what type of object this is
ClassType m_classType = ClassType::Base;
/// @brief Should the app use hooks
bool m_noHooks = false;
/// @brief The filename of the running process
const char *m_pname = nullptr;

View File

@ -151,7 +151,8 @@ deskflow::Screen *ClientApp::createScreen()
#if WINAPI_MSWINDOWS
return new deskflow::Screen(
new MSWindowsScreen(
false, args().m_noHooks, getEvents(), args().m_enableLangSync, args().m_clientScrollDirection
false, Settings::value(Settings::Core::UseHooks).toBool(), getEvents(), args().m_enableLangSync,
args().m_clientScrollDirection
),
getEvents()
);

View File

@ -102,6 +102,13 @@ void CoreArgParser::parse()
(m_parser.value(CoreArgs::restartOption) == "1"));
Settings::setValue(Settings::Core::RestartOnFailure, value);
}
if (m_parser.isSet(CoreArgs::useHooksOption)) {
bool value =
((m_parser.value(CoreArgs::useHooksOption).toLower() == "true") ||
(m_parser.value(CoreArgs::useHooksOption) == "1"));
Settings::setValue(Settings::Core::UseHooks, value);
}
}
[[noreturn]] void CoreArgParser::showHelpText() const

View File

@ -55,6 +55,9 @@ struct CoreArgs
{"r", "restartOnFailure"}, "Set if the core should automatically restart if it fails", "value"
);
inline static const auto useHooksOption =
QCommandLineOption("useHooks", "Sets if hooks are used for windows desks", "value");
inline static const auto options = {
helpOption,
versionOption,
@ -68,6 +71,7 @@ struct CoreArgs
tlsCertOption,
preventSleepOption,
restartOption,
displayOption
displayOption,
useHooksOption
};
};

View File

@ -450,7 +450,9 @@ bool ServerApp::startServer()
deskflow::Screen *ServerApp::createScreen()
{
#if WINAPI_MSWINDOWS
return new deskflow::Screen(new MSWindowsScreen(true, args().m_noHooks, getEvents()), getEvents());
return new deskflow::Screen(
new MSWindowsScreen(true, Settings::value(Settings::Core::UseHooks).toBool(), getEvents()), getEvents()
);
#endif
#if defined(WINAPI_XWINDOWS) or defined(WINAPI_LIBEI)

View File

@ -285,16 +285,4 @@ void ArgParserTests::generic_unknown()
QVERIFY(!m_parser.parseGenericArgs(argc, kBackendCmd, i));
}
void ArgParserTests::generic_noHook()
{
int i = 1;
const int argc = 2;
const char *kNoHookCmd[argc] = {"stub", "--no-hooks"};
m_parser.parseGenericArgs(argc, kNoHookCmd, i);
QVERIFY(m_parser.argsBase().m_noHooks);
QCOMPARE(i, 1);
}
QTEST_MAIN(ArgParserTests)

View File

@ -33,7 +33,6 @@ private Q_SLOTS:
void deprecatedArg_crypoPass_true();
void deprecatedArg_crypoPass_false();
void generic_unknown();
void generic_noHook();
private:
Arch m_arch;

View File

@ -270,6 +270,26 @@ void CoreArgParserTests::restartShortOption_true()
QVERIFY(Settings::value(Settings::Core::RestartOnFailure).toBool());
}
void CoreArgParserTests::hookOptions_false()
{
QStringList args = {"stub", "client", "--useHooks", "false"};
CoreArgParser parser(args);
parser.parse();
QVERIFY(!Settings::value(Settings::Core::UseHooks).toBool());
}
void CoreArgParserTests::hookOptions_true()
{
QStringList args = {"stub", "client", "--useHooks", "true"};
CoreArgParser parser(args);
parser.parse();
QVERIFY(Settings::value(Settings::Core::UseHooks).toBool());
}
void CoreArgParserTests::preventSleep_true()
{
QStringList args = {"stub", "client", "--prevent-sleep", "true"};

View File

@ -40,6 +40,8 @@ private Q_SLOTS:
void restartShortOption_1();
void restartShortOption_false();
void restartShortOption_true();
void hookOptions_false();
void hookOptions_true();
private:
inline static const QString m_settingsPath = QStringLiteral("tmp/test");