feat: add help and version to gui,
move no-reset to the QCommandLineProcessor
This commit is contained in:
committed by
Chris Rizzitello
parent
5df333fae9
commit
1ace03d4b5
@ -14,7 +14,7 @@ function(generate_app_man TARGET)
|
||||
if(HELP2MAN)
|
||||
add_custom_command(
|
||||
TARGET ${target} POST_BUILD
|
||||
COMMAND ${HELP2MAN}
|
||||
COMMAND QT_QPA_PLATFORM=minimal ${HELP2MAN}
|
||||
--include ${CMAKE_SOURCE_DIR}/src/apps/res/manpage.txt
|
||||
--no-info
|
||||
$<TARGET_FILE:${target}>
|
||||
|
||||
@ -84,19 +84,5 @@ elseif(APPLE)
|
||||
install(TARGETS ${target} BUNDLE DESTINATION .)
|
||||
else()
|
||||
install(TARGETS ${target} DESTINATION bin)
|
||||
if(HELP2MAN)
|
||||
configure_file(deskflow.man.template.in ${CMAKE_CURRENT_BINARY_DIR}/${target})
|
||||
add_custom_command(
|
||||
TARGET ${target} POST_BUILD
|
||||
COMMAND ${HELP2MAN}
|
||||
--version-string "${CMAKE_PROJECT_VERSION}"
|
||||
--include ${CMAKE_SOURCE_DIR}/src/apps/res/manpage.txt
|
||||
--no-info ${CMAKE_CURRENT_BINARY_DIR}/${target}
|
||||
-o ${CMAKE_CURRENT_BINARY_DIR}/${target}.1
|
||||
)
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/${target}.1
|
||||
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
|
||||
)
|
||||
endif()
|
||||
generate_app_man(${target})
|
||||
endif()
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "gui/StyleUtils.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QGuiApplication>
|
||||
#include <QLocalSocket>
|
||||
#include <QMessageBox>
|
||||
@ -36,11 +37,6 @@ using namespace deskflow::gui;
|
||||
bool checkMacAssistiveDevices();
|
||||
#endif
|
||||
|
||||
bool hasArg(const QString &arg, const QStringList &args)
|
||||
{
|
||||
return std::ranges::any_of(args, [&arg](const QString &a) { return a == arg; });
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#if defined(Q_OS_UNIX) && defined(QT_DEBUG)
|
||||
@ -50,13 +46,37 @@ int main(int argc, char *argv[])
|
||||
|
||||
QCoreApplication::setApplicationName(kAppName);
|
||||
QCoreApplication::setOrganizationName(kAppName);
|
||||
QCoreApplication::setApplicationVersion(kVersion);
|
||||
QCoreApplication::setOrganizationDomain(kOrgDomain); // used in prefix, can't be a url
|
||||
QGuiApplication::setDesktopFileName(QStringLiteral("org.deskflow.deskflow"));
|
||||
|
||||
// used as a prefix for settings paths, and must not be a url.
|
||||
QCoreApplication::setOrganizationDomain(kOrgDomain);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// Add Command Line Options
|
||||
QCommandLineOption helpOption = QCommandLineOption("help", "Display Help on the command line");
|
||||
QCommandLineOption versionOption = QCommandLineOption("version", "Display version information");
|
||||
QCommandLineOption noResetOption =
|
||||
QCommandLineOption("no-reset", "Prevent settings reset if DESKFLOW_RESET_ALL is set");
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
||||
parser.addOption(helpOption);
|
||||
parser.addOption(versionOption);
|
||||
parser.addOption(noResetOption);
|
||||
parser.parse(QCoreApplication::arguments());
|
||||
|
||||
const auto header = QStringLiteral("%1: %2\n").arg(kAppName, kDisplayVersion);
|
||||
if (parser.isSet(helpOption) || !parser.unknownOptionNames().isEmpty() || !parser.errorText().isEmpty()) {
|
||||
QTextStream(stdout) << header << QStringLiteral(" %1\n\n").arg(kAppDescription)
|
||||
<< parser.helpText().replace(QApplication::applicationFilePath(), kAppId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (parser.isSet(versionOption)) {
|
||||
QTextStream(stdout) << header << kCopyright << Qt::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create a shared memory segment with a unique key
|
||||
// This is to prevent a new instance from running if one is already running
|
||||
QSharedMemory sharedMemory("deskflow-gui");
|
||||
@ -113,10 +133,8 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
// --no-reset
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
const auto noReset = hasArg("--no-reset", arguments);
|
||||
const auto resetEnvVar = QVariant(qEnvironmentVariable("DESKFLOW_RESET_ALL")).toBool();
|
||||
if (resetEnvVar && !noReset) {
|
||||
if (resetEnvVar && !parser.isSet(noResetOption)) {
|
||||
diagnostic::clearSettings(false);
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
# SPDX-FileCopyrightText: Deskflow Developers
|
||||
# SPDX-License-Identifier: MIT
|
||||
#!/bin/sh -eu
|
||||
|
||||
if [ "$1" = '--help' ]; then
|
||||
cat << EOM
|
||||
@CMAKE_PROJECT_DESCRIPTION@. This is the GUI. It takes no arguments or options.
|
||||
EOM
|
||||
fi
|
||||
Reference in New Issue
Block a user