From e245d69bffd1a81b8fecd0e47b4c49ec702efa03 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 29 Jun 2021 16:58:17 +0200 Subject: Make multiple-instances-check execute sooner --- src/main.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2b1837a..f907e6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,25 @@ int main(int argc, char *argv[]) { qDebug() << "This app was built on: " << BUILD_TIME; + // We don't want users to have multiple instances of this app running + QString tmpDirPath = QDir::tempPath() + "/rwa.support.desktopapp"; + QString tmpFilePath = tmpDirPath + "/prevent-multiple-instances.lock"; + QDir tmpDir(tmpDirPath); + if (!tmpDir.exists()) { + // Ensure that the path exists + tmpDir.mkpath("."); + } + QLockFile lockFile(tmpFilePath); + qDebug() << "Checking for a lockfile at: " + tmpFilePath; + + if(!lockFile.tryLock(100)){ + qDebug() << QObject::tr("You already have this app running."); + qDebug() << QObject::tr("Only one instance is allowed."); + qDebug() << QObject::tr("Closing application now with an error."); + + return 1; + } + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); @@ -82,24 +101,5 @@ int main(int argc, char *argv[]) { engine.rootObjects().takeFirst(), SLOT(showWindow())); - // We don't want users to have multiple instances of this app running - QString tmpDirPath = QDir::tempPath() + "/rwa.support.desktopapp"; - QString tmpFilePath = tmpDirPath + "/prevent-multiple-instances.lock"; - QDir tmpDir(tmpDirPath); - if (!tmpDir.exists()) { - // Ensure that the path exists - tmpDir.mkpath("."); - } - QLockFile lockFile(tmpFilePath); - qDebug() << "Checking for a lockfile at: " + tmpFilePath; - - if(!lockFile.tryLock(100)){ - qDebug() << QObject::tr("You already have this app running."); - qDebug() << QObject::tr("Only one instance is allowed."); - qDebug() << QObject::tr("Closing application now with an error."); - - return 1; - } - return app.exec(); } -- cgit v1.2.3