Skip to content

Commit

Permalink
Replace RunGuard with SingleApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Aug 23, 2024
1 parent 5e82cdb commit b583f0f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 151 deletions.
11 changes: 7 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ if(ANDROID)

target_include_directories(QGC PUBLIC ${CMAKE_SOURCE_DIR}/android/src)
else()
target_sources(QGC
PRIVATE
RunGuard.cc
RunGuard.h
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication" FORCE)
FetchContent_Declare(SingleApplication
GIT_REPOSITORY https://github.com/itay-grudev/SingleApplication
GIT_TAG v3.5.1
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(SingleApplication)
target_link_libraries(QGC PUBLIC SingleApplication::SingleApplication)
endif()

target_precompile_headers(QGC PRIVATE ${CMAKE_SOURCE_DIR}/src/pch.h)
2 changes: 1 addition & 1 deletion src/QGCApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static QObject* shapeFileHelperSingletonFactory(QQmlEngine*, QJSEngine*)
}

QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
: QApplication(argc, argv)
: QGCAPPLICATION_CLASS(argc, argv)
, _runningUnitTests(unitTesting)
{
_msecsElapsedTime.start();
Expand Down
9 changes: 8 additions & 1 deletion src/QGCApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#include <QtCore/private/qthread_p.h>
#include <QtCore/private/qobject_p.h>

#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#define QGCAPPLICATION_CLASS QApplication
#else
#include <SingleApplication>
#define QGCAPPLICATION_CLASS SingleApplication
#endif

// Work around circular header includes
class QQmlApplicationEngine;
class QGCToolbox;
Expand Down Expand Up @@ -56,7 +63,7 @@ class QGCApplication;
**/

// TODO: Use QtGraphs to convert to QGuiApplication
class QGCApplication : public QApplication
class QGCApplication : public QGCAPPLICATION_CLASS
{
Q_OBJECT
public:
Expand Down
87 changes: 0 additions & 87 deletions src/RunGuard.cc

This file was deleted.

36 changes: 0 additions & 36 deletions src/RunGuard.h

This file was deleted.

22 changes: 0 additions & 22 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include "QGC.h"
#include "AppMessages.h"

#ifndef __mobile__
#include "RunGuard.h"
#endif

#ifdef Q_OS_ANDROID
#include "AndroidInterface.h"
#endif
Expand Down Expand Up @@ -82,24 +78,6 @@ void sigHandler(int s)

int main(int argc, char *argv[])
{
#ifndef __mobile__
// We make the runguard key different for custom and non custom
// builds, so they can be executed together in the same device.
// Stable and Daily have same QGC_APP_NAME so they would
// not be able to run at the same time
const QString runguardString = QString("%1 RunGuardKey").arg(QGC_APP_NAME);

RunGuard guard(runguardString);
if (!guard.tryToRun()) {
// QApplication is necessary to use QMessageBox
QApplication errorApp(argc, argv);
QMessageBox::critical(nullptr, QObject::tr("Error"),
QObject::tr("A second instance of %1 is already running. Please close the other instance and try again.").arg(QGC_APP_NAME)
);
return -1;
}
#endif

#ifdef Q_OS_LINUX
#ifndef Q_OS_ANDROID
if (getuid() == 0) {
Expand Down

0 comments on commit b583f0f

Please sign in to comment.