Move server function to the bottom and change "utils" file name to "localserver"

This commit is contained in:
Vitalya 2023-04-27 19:52:28 +03:00
parent 6f0303206e
commit c15250498b
4 changed files with 17 additions and 15 deletions

View File

@ -45,7 +45,7 @@ set(discord-screenaudio_SRC
src/log.cpp src/log.cpp
src/userscript.cpp src/userscript.cpp
src/centralwidget.cpp src/centralwidget.cpp
src/utils.cpp src/localserver.cpp
resources.qrc resources.qrc
) )

View File

@ -1,4 +1,4 @@
#include "utils.h" #include "localserver.h"
bool isProgramRunning(const QString &program_name) { bool isProgramRunning(const QString &program_name) {
QLocalSocket socket; QLocalSocket socket;

View File

@ -5,6 +5,5 @@
#include <QLocalSocket> #include <QLocalSocket>
#include <QMessageBox> #include <QMessageBox>
bool isProgramRunning(const QString &program_name); bool isProgramRunning(const QString &program_name);
void showErrorMessage(const char *text); void showErrorMessage(const char *text);

View File

@ -1,6 +1,6 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "virtmic.h" #include "virtmic.h"
#include "utils.h" #include "localserver.h"
#ifdef KXMLGUI #ifdef KXMLGUI
#include <KAboutData> #include <KAboutData>
@ -16,18 +16,7 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication app(argc, 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::setApplicationName("discord-screenaudio");
QApplication::setWindowIcon( QApplication::setWindowIcon(
@ -68,6 +57,20 @@ int main(int argc, char *argv[]) {
qgetenv("QTWEBENGINE_CHROMIUM_FLAGS")); qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
MainWindow w(parser.isSet(notifySendOption)); 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(); w.show();
return app.exec(); return app.exec();