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 "base/EventQueue.h"
#include "base/Log.h"
#include "common/ExitCodes.h"
#include "deskflow/ClientApp.h"
#include "deskflow/ServerApp.h"
@ -61,7 +62,7 @@ int main(int argc, char **argv)
if (isHelp(argc, argv)) {
showHelp();
return 0;
return s_exitSuccess;
}
// 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 (!sharedMemory.create(1)) {
LOG_WARN("an instance of deskflow core (server or client) is already running");
return 0;
return s_exitDuplicate;
}
#if SYSAPI_WIN32
// HACK to make sure settings gets the correct qApp path
@ -98,5 +99,5 @@ int main(int argc, char **argv)
showHelp();
}
return 0;
return s_exitSuccess;
}

View File

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

View File

@ -8,6 +8,7 @@
#include "VersionInfo.h"
#include "common/Constants.h"
#include "common/ExitCodes.h"
#include "common/UrlConstants.h"
#include "gui/Diagnostic.h"
#include "gui/DotEnv.h"
@ -68,18 +69,18 @@ int main(int argc, char *argv[])
if (!parser.errorText().isEmpty()) {
qCritical().noquote() << parser.errorText() << "\nUse --help for more information.";
return 1;
return s_exitArgs;
}
if (parser.isSet(helpOption)) {
QTextStream(stdout) << kHeader << QStringLiteral(" %1\n\n").arg(kAppDescription)
<< parser.helpText().replace(QApplication::applicationFilePath(), kAppId);
return 0;
return s_exitSuccess;
}
if (parser.isSet(versionOption)) {
QTextStream(stdout) << kHeader << kCopyright << Qt::endl;
return 0;
return s_exitSuccess;
}
// 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"));
}
socket.disconnectFromServer();
return 0;
return s_exitDuplicate;
}
#if !defined(Q_OS_MAC)

View File

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

View File

@ -32,9 +32,3 @@
#else
#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/LogOutputters.h"
#include "common/Constants.h"
#include "common/ExitCodes.h"
#include "deskflow/ArgsBase.h"
#include "deskflow/Config.h"
#include "deskflow/DeskflowException.h"

View File

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

View File

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

View File

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

View File

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