diff --git a/main.cpp b/main.cpp index c0a870d..d118f57 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,18 @@ #include #include #include +#include + +bool isAnotherInstanceRunning(const QString& processName) +{ + 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); + + return count > 1; +} int main(int argc, char *argv[]) { @@ -10,6 +22,12 @@ int main(int argc, char *argv[]) a.setStyle("fusion"); a.setQuitOnLastWindowClosed(false); + const QString processName = "QuickSoundSwitcher.exe"; + if (isAnotherInstanceRunning(processName)) { + qDebug() << "Another instance is already running. Exiting..."; + return 0; + } + QString mode = Utils::getTheme(); QString color; QPalette palette = QApplication::palette();