-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove localsocket, check if process is already running with tasklist…
… instead
- Loading branch information
Showing
3 changed files
with
21 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
QT += core gui network | ||
QT += core gui | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "Utils.h" | ||
#include <QTranslator> | ||
#include <QApplication> | ||
#include <QScreen> | ||
#include <QDebug> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,45 @@ | ||
#include <QApplication> | ||
#include <QDebug> | ||
#include <QLocale> | ||
#include <QMessageBox> | ||
#include <QLocalServer> | ||
#include <QLocalSocket> | ||
#include <QString> | ||
#include <QTranslator> | ||
#include <QProcess> | ||
#include "BigPictureTV.h" | ||
#include "Utils.h" | ||
|
||
int main(int argc, char *argv[]) | ||
bool isAnotherInstanceRunning(const QString& processName) | ||
{ | ||
QApplication a(argc, argv); | ||
|
||
QString serverName = "BigPictureTVUniqueIdentifier"; | ||
QLocalServer localServer; | ||
QLocalSocket localSocket; | ||
QProcess process; | ||
process.start("tasklist", QStringList() << "/FI" << QString("IMAGENAME eq %1").arg(processName)); | ||
process.waitForFinished(); | ||
QString output = process.readAllStandardOutput(); | ||
int count = output.count(processName, Qt::CaseInsensitive); | ||
|
||
localSocket.connectToServer(serverName); | ||
return count > 1; | ||
} | ||
|
||
if (localSocket.waitForConnected(500)) { | ||
qDebug() << "Another instance is already running."; | ||
return 0; | ||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
a.setQuitOnLastWindowClosed(false); | ||
if (Utils::isWindows10()) { | ||
a.setStyle("fusion"); | ||
} | ||
|
||
if (!localServer.listen(serverName)) { | ||
qDebug() << "Unable to start the local server:" << localServer.errorString(); | ||
return 1; | ||
const QString processName = "BigPictureTV.exe"; | ||
if (isAnotherInstanceRunning(processName)) { | ||
qDebug() << "Another instance is already running. Exiting..."; | ||
return 0; | ||
} | ||
|
||
QLocale locale; | ||
QString languageCode = locale.name().section('_', 0, 0); | ||
QTranslator translator; | ||
|
||
if (translator.load(":/translations/BigPictureTV_" + languageCode + ".qm")) { | ||
a.installTranslator(&translator); | ||
} | ||
|
||
if (Utils::isWindows10()) { | ||
a.setStyle("fusion"); | ||
} | ||
a.setQuitOnLastWindowClosed(false); | ||
|
||
BigPictureTV w; | ||
|
||
QObject::connect(&a, &QApplication::aboutToQuit, [&localServer]() { | ||
localServer.close(); | ||
}); | ||
|
||
return a.exec(); | ||
} |