feat: add help and version to gui,
move no-reset to the QCommandLineProcessor
This commit is contained in:
parent
5df333fae9
commit
1ace03d4b5
4 changed files with 31 additions and 36 deletions
|
|
@ -14,7 +14,7 @@ function(generate_app_man TARGET)
|
||||||
if(HELP2MAN)
|
if(HELP2MAN)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ${target} POST_BUILD
|
TARGET ${target} POST_BUILD
|
||||||
COMMAND ${HELP2MAN}
|
COMMAND QT_QPA_PLATFORM=minimal ${HELP2MAN}
|
||||||
--include ${CMAKE_SOURCE_DIR}/src/apps/res/manpage.txt
|
--include ${CMAKE_SOURCE_DIR}/src/apps/res/manpage.txt
|
||||||
--no-info
|
--no-info
|
||||||
$<TARGET_FILE:${target}>
|
$<TARGET_FILE:${target}>
|
||||||
|
|
|
||||||
|
|
@ -84,19 +84,5 @@ elseif(APPLE)
|
||||||
install(TARGETS ${target} BUNDLE DESTINATION .)
|
install(TARGETS ${target} BUNDLE DESTINATION .)
|
||||||
else()
|
else()
|
||||||
install(TARGETS ${target} DESTINATION bin)
|
install(TARGETS ${target} DESTINATION bin)
|
||||||
if(HELP2MAN)
|
generate_app_man(${target})
|
||||||
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()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#include "gui/StyleUtils.h"
|
#include "gui/StyleUtils.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCommandLineParser>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
@ -36,11 +37,6 @@ using namespace deskflow::gui;
|
||||||
bool checkMacAssistiveDevices();
|
bool checkMacAssistiveDevices();
|
||||||
#endif
|
#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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_UNIX) && defined(QT_DEBUG)
|
#if defined(Q_OS_UNIX) && defined(QT_DEBUG)
|
||||||
|
|
@ -50,13 +46,37 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QCoreApplication::setApplicationName(kAppName);
|
QCoreApplication::setApplicationName(kAppName);
|
||||||
QCoreApplication::setOrganizationName(kAppName);
|
QCoreApplication::setOrganizationName(kAppName);
|
||||||
|
QCoreApplication::setApplicationVersion(kVersion);
|
||||||
|
QCoreApplication::setOrganizationDomain(kOrgDomain); // used in prefix, can't be a url
|
||||||
QGuiApplication::setDesktopFileName(QStringLiteral("org.deskflow.deskflow"));
|
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);
|
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
|
// Create a shared memory segment with a unique key
|
||||||
// This is to prevent a new instance from running if one is already running
|
// This is to prevent a new instance from running if one is already running
|
||||||
QSharedMemory sharedMemory("deskflow-gui");
|
QSharedMemory sharedMemory("deskflow-gui");
|
||||||
|
|
@ -113,10 +133,8 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --no-reset
|
// --no-reset
|
||||||
QStringList arguments = QCoreApplication::arguments();
|
|
||||||
const auto noReset = hasArg("--no-reset", arguments);
|
|
||||||
const auto resetEnvVar = QVariant(qEnvironmentVariable("DESKFLOW_RESET_ALL")).toBool();
|
const auto resetEnvVar = QVariant(qEnvironmentVariable("DESKFLOW_RESET_ALL")).toBool();
|
||||||
if (resetEnvVar && !noReset) {
|
if (resetEnvVar && !parser.isSet(noResetOption)) {
|
||||||
diagnostic::clearSettings(false);
|
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
|
|
||||||
Loading…
Reference in a new issue