Merge pull request #149 from Vitalya-code/master
Move two functions into separate file
This commit is contained in:
commit
8a6f49b949
|
@ -45,6 +45,7 @@ set(discord-screenaudio_SRC
|
|||
src/log.cpp
|
||||
src/userscript.cpp
|
||||
src/centralwidget.cpp
|
||||
src/localserver.cpp
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#include "localserver.h"
|
||||
|
||||
bool isProgramRunning(const QString &program_name) {
|
||||
QLocalSocket socket;
|
||||
socket.connectToServer(program_name);
|
||||
if (socket.waitForConnected()) {
|
||||
return true; // program is already running
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void showErrorMessage(const char *text) {
|
||||
QMessageBox msgBox;
|
||||
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(text);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.setWindowIcon(QIcon(":assets/de.shorsh.discord-screenaudio.png"));
|
||||
|
||||
msgBox.exec();
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
#include <QMessageBox>
|
||||
|
||||
bool isProgramRunning(const QString &program_name);
|
||||
void showErrorMessage(const char *text);
|
49
src/main.cpp
49
src/main.cpp
|
@ -1,3 +1,4 @@
|
|||
#include "localserver.h"
|
||||
#include "mainwindow.h"
|
||||
#include "virtmic.h"
|
||||
|
||||
|
@ -12,43 +13,9 @@
|
|||
#include <QLoggingCategory>
|
||||
#include <QMessageBox>
|
||||
|
||||
void showErrorMessage(const char *text) {
|
||||
QMessageBox msgBox;
|
||||
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(text);
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.setWindowIcon(QIcon(":assets/de.shorsh.discord-screenaudio.png"));
|
||||
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
bool isProgramRunning(const QString &program_name) {
|
||||
QLocalSocket socket;
|
||||
socket.connectToServer(program_name);
|
||||
if (socket.waitForConnected()) {
|
||||
return true; // program is already running
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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(
|
||||
QIcon(":assets/de.shorsh.discord-screenaudio.png"));
|
||||
|
@ -88,6 +55,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();
|
||||
|
|
Loading…
Reference in New Issue