Skip to content

Commit

Permalink
added single instance lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne committed Nov 21, 2024
1 parent 7d71723 commit aba49b3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@
#include <QApplication>
#include <QTranslator>
#include <QLocale>
#include <QProcess>

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[])
{
QApplication a(argc, 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();
Expand Down

0 comments on commit aba49b3

Please sign in to comment.