From c15250498b7368d151bdf71404946c743769d140 Mon Sep 17 00:00:00 2001 From: Vitalya Date: Thu, 27 Apr 2023 19:52:28 +0300 Subject: [PATCH] Move server function to the bottom and change "utils" file name to "localserver" --- CMakeLists.txt | 2 +- src/{utils.cpp => localserver.cpp} | 2 +- src/{utils.h => localserver.h} | 1 - src/main.cpp | 27 +++++++++++++++------------ 4 files changed, 17 insertions(+), 15 deletions(-) rename src/{utils.cpp => localserver.cpp} (95%) rename src/{utils.h => localserver.h} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49ae026..5d36013 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ set(discord-screenaudio_SRC src/log.cpp src/userscript.cpp src/centralwidget.cpp - src/utils.cpp + src/localserver.cpp resources.qrc ) diff --git a/src/utils.cpp b/src/localserver.cpp similarity index 95% rename from src/utils.cpp rename to src/localserver.cpp index 3efa9ad..3081794 100644 --- a/src/utils.cpp +++ b/src/localserver.cpp @@ -1,4 +1,4 @@ -#include "utils.h" +#include "localserver.h" bool isProgramRunning(const QString &program_name) { QLocalSocket socket; diff --git a/src/utils.h b/src/localserver.h similarity index 99% rename from src/utils.h rename to src/localserver.h index 40e3568..71eaf5f 100644 --- a/src/utils.h +++ b/src/localserver.h @@ -5,6 +5,5 @@ #include #include - bool isProgramRunning(const QString &program_name); void showErrorMessage(const char *text); diff --git a/src/main.cpp b/src/main.cpp index 9cd4914..ba2b8b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "virtmic.h" -#include "utils.h" +#include "localserver.h" #ifdef KXMLGUI #include @@ -16,18 +16,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - // Check if discord is already running - QString program_name = "discord-screenaudio"; - if (isProgramRunning(program_name)) { - // if running show error message - showErrorMessage("discord-screenaudio is already running"); - return 1; - } - // open server so we can check if discord is running - QLocalServer server; - server.listen(program_name); - QObject::connect(&server, &QLocalServer::newConnection, []() {}); QApplication::setApplicationName("discord-screenaudio"); QApplication::setWindowIcon( @@ -68,6 +57,20 @@ int main(int argc, char *argv[]) { qgetenv("QTWEBENGINE_CHROMIUM_FLAGS")); MainWindow w(parser.isSet(notifySendOption)); + + // Check if discord is already running + QString program_name = "discord-screenaudio"; + if (isProgramRunning(program_name)) { + // if running show error message + showErrorMessage("discord-screenaudio is already running"); + return 1; + } + + // open server so we can check if discord is running + QLocalServer server; + server.listen(program_name); + QObject::connect(&server, &QLocalServer::newConnection, []() {}); + w.show(); return app.exec();