diff options
author | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-06-29 16:58:17 +0200 |
---|---|---|
committer | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-06-29 16:58:39 +0200 |
commit | e245d69bffd1a81b8fecd0e47b4c49ec702efa03 (patch) | |
tree | 70a5899c7966e5675d921cd5fa58400890d28c4f /src | |
parent | 970f05d2006a45bee9c4e3d27040559721a0c326 (diff) | |
download | RWA.Support.DesktopApp-e245d69bffd1a81b8fecd0e47b4c49ec702efa03.tar.gz RWA.Support.DesktopApp-e245d69bffd1a81b8fecd0e47b4c49ec702efa03.tar.bz2 RWA.Support.DesktopApp-e245d69bffd1a81b8fecd0e47b4c49ec702efa03.zip |
Make multiple-instances-check execute sooner
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 38 |
1 files 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(); } |