refactor: move all exit codes to new ExitCodes

add new exitcode s_exitDuplicate for when exiting because of already running instance
This commit is contained in:
sithlord48 2025-08-19 09:55:31 -04:00 committed by Nick Bolton
parent 2b3e7adc0b
commit d3c0ce8895
11 changed files with 32 additions and 13 deletions

View file

@ -9,6 +9,7 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "base/EventQueue.h" #include "base/EventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "common/ExitCodes.h"
#include "deskflow/ClientApp.h" #include "deskflow/ClientApp.h"
#include "deskflow/ServerApp.h" #include "deskflow/ServerApp.h"
@ -61,7 +62,7 @@ int main(int argc, char **argv)
if (isHelp(argc, argv)) { if (isHelp(argc, argv)) {
showHelp(); showHelp();
return 0; return s_exitSuccess;
} }
// Create a shared memory segment with a unique key // Create a shared memory segment with a unique key
@ -76,7 +77,7 @@ int main(int argc, char **argv)
// If we can create 1 byte of SHM we are the only instance // If we can create 1 byte of SHM we are the only instance
if (!sharedMemory.create(1)) { if (!sharedMemory.create(1)) {
LOG_WARN("an instance of deskflow core (server or client) is already running"); LOG_WARN("an instance of deskflow core (server or client) is already running");
return 0; return s_exitDuplicate;
} }
#if SYSAPI_WIN32 #if SYSAPI_WIN32
// HACK to make sure settings gets the correct qApp path // HACK to make sure settings gets the correct qApp path
@ -98,5 +99,5 @@ int main(int argc, char **argv)
showHelp(); showHelp();
} }
return 0; return s_exitSuccess;
} }

View file

@ -9,6 +9,7 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "base/EventQueue.h" #include "base/EventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "common/ExitCodes.h"
#include "common/Settings.h" #include "common/Settings.h"
#include "deskflow/DaemonApp.h" #include "deskflow/DaemonApp.h"
#include "deskflow/ipc/DaemonIpcServer.h" #include "deskflow/ipc/DaemonIpcServer.h"

View file

@ -8,6 +8,7 @@
#include "VersionInfo.h" #include "VersionInfo.h"
#include "common/Constants.h" #include "common/Constants.h"
#include "common/ExitCodes.h"
#include "common/UrlConstants.h" #include "common/UrlConstants.h"
#include "gui/Diagnostic.h" #include "gui/Diagnostic.h"
#include "gui/DotEnv.h" #include "gui/DotEnv.h"
@ -68,18 +69,18 @@ int main(int argc, char *argv[])
if (!parser.errorText().isEmpty()) { if (!parser.errorText().isEmpty()) {
qCritical().noquote() << parser.errorText() << "\nUse --help for more information."; qCritical().noquote() << parser.errorText() << "\nUse --help for more information.";
return 1; return s_exitArgs;
} }
if (parser.isSet(helpOption)) { if (parser.isSet(helpOption)) {
QTextStream(stdout) << kHeader << QStringLiteral(" %1\n\n").arg(kAppDescription) QTextStream(stdout) << kHeader << QStringLiteral(" %1\n\n").arg(kAppDescription)
<< parser.helpText().replace(QApplication::applicationFilePath(), kAppId); << parser.helpText().replace(QApplication::applicationFilePath(), kAppId);
return 0; return s_exitSuccess;
} }
if (parser.isSet(versionOption)) { if (parser.isSet(versionOption)) {
QTextStream(stdout) << kHeader << kCopyright << Qt::endl; QTextStream(stdout) << kHeader << kCopyright << Qt::endl;
return 0; return s_exitSuccess;
} }
// Create a shared memory segment with a unique key // Create a shared memory segment with a unique key
@ -102,7 +103,7 @@ int main(int argc, char *argv[])
QMessageBox::information(nullptr, QObject::tr("Deskflow"), QObject::tr("Deskflow is already running")); QMessageBox::information(nullptr, QObject::tr("Deskflow"), QObject::tr("Deskflow is already running"));
} }
socket.disconnectFromServer(); socket.disconnectFromServer();
return 0; return s_exitDuplicate;
} }
#if !defined(Q_OS_MAC) #if !defined(Q_OS_MAC)

View file

@ -13,6 +13,7 @@ unset(SERVER_BINARY)
add_library(common STATIC add_library(common STATIC
Common.h Common.h
ExitCodes.h
Settings.h Settings.h
Settings.cpp Settings.cpp
QSettingsProxy.cpp QSettingsProxy.cpp

View file

@ -32,9 +32,3 @@
#else #else
#endif #endif
#endif #endif
static const int s_exitSuccess = 0; //!< App successfully completed
static const int s_exitFailed = 1; //!< App had a general failure
static const int s_exitTerminated = 2; //!< App was kill by a signal
static const int s_exitArgs = 3; //!< App was unable to run due to bad arguments being passed
static const int s_exitConfig = 4; //!< App was unable to read the configuration

View file

@ -0,0 +1,16 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2010 - 2018, 2024 - 2025 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 - 2007 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#pragma once
static const int s_exitSuccess = 0; //!< App successfully completed
static const int s_exitFailed = 1; //!< App had a general failure
static const int s_exitTerminated = 2; //!< App was kill by a signal
static const int s_exitArgs = 3; //!< App was unable to run due to bad arguments being passed
static const int s_exitConfig = 4; //!< App was unable to read the configuration
static const int s_exitDuplicate = 5; //!< An instance of the app (or core app) is already running

View file

@ -13,6 +13,7 @@
#include "base/Log.h" #include "base/Log.h"
#include "base/LogOutputters.h" #include "base/LogOutputters.h"
#include "common/Constants.h" #include "common/Constants.h"
#include "common/ExitCodes.h"
#include "deskflow/ArgsBase.h" #include "deskflow/ArgsBase.h"
#include "deskflow/Config.h" #include "deskflow/Config.h"
#include "deskflow/DeskflowException.h" #include "deskflow/DeskflowException.h"

View file

@ -14,6 +14,7 @@
#include "base/Log.h" #include "base/Log.h"
#include "client/Client.h" #include "client/Client.h"
#include "common/Constants.h" #include "common/Constants.h"
#include "common/ExitCodes.h"
#include "deskflow/ArgParser.h" #include "deskflow/ArgParser.h"
#include "deskflow/ClientArgs.h" #include "deskflow/ClientArgs.h"
#include "deskflow/ProtocolTypes.h" #include "deskflow/ProtocolTypes.h"

View file

@ -9,6 +9,7 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/LogOutputters.h" #include "base/LogOutputters.h"
#include "common/ExitCodes.h"
#include "common/Settings.h" #include "common/Settings.h"
#include "deskflow/App.h" #include "deskflow/App.h"
#include "deskflow/ipc/DaemonIpcServer.h" #include "deskflow/ipc/DaemonIpcServer.h"

View file

@ -12,6 +12,7 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/Path.h" #include "base/Path.h"
#include "common/ExitCodes.h"
#include "deskflow/App.h" #include "deskflow/App.h"
#include "deskflow/ArgParser.h" #include "deskflow/ArgParser.h"
#include "deskflow/Screen.h" #include "deskflow/Screen.h"

View file

@ -11,6 +11,7 @@
#include "base/Log.h" #include "base/Log.h"
#include "common/Common.h" #include "common/Common.h"
#include "common/Constants.h" #include "common/Constants.h"
#include "common/ExitCodes.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>