Compare commits
	
		
			9 Commits
		
	
	
		
			v1.8.1
			...
			94b27f5b6a
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 94b27f5b6a | ||
|  | 8a6f49b949 | ||
|  | 47fd620876 | ||
|  | c15250498b | ||
|  | 6f0303206e | ||
|  | 6e86647c95 | ||
|  | 798fb3d5e4 | ||
|  | 6c9b76ed90 | ||
|  | b582584c69 | 
| @@ -45,6 +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/localserver.cpp | ||||||
|   resources.qrc |   resources.qrc | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								src/localserver.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/localserver.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -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(); | ||||||
|  | } | ||||||
							
								
								
									
										9
									
								
								src/localserver.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/localserver.h
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||||
							
								
								
									
										19
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -1,3 +1,4 @@ | |||||||
|  | #include "localserver.h" | ||||||
| #include "mainwindow.h" | #include "mainwindow.h" | ||||||
| #include "virtmic.h" | #include "virtmic.h" | ||||||
|  |  | ||||||
| @@ -7,10 +8,14 @@ | |||||||
|  |  | ||||||
| #include <QApplication> | #include <QApplication> | ||||||
| #include <QCommandLineParser> | #include <QCommandLineParser> | ||||||
|  | #include <QLocalServer> | ||||||
|  | #include <QLocalSocket> | ||||||
| #include <QLoggingCategory> | #include <QLoggingCategory> | ||||||
|  | #include <QMessageBox> | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||||
|   QApplication app(argc, argv); |   QApplication app(argc, argv); | ||||||
|  |  | ||||||
|   QApplication::setApplicationName("discord-screenaudio"); |   QApplication::setApplicationName("discord-screenaudio"); | ||||||
|   QApplication::setWindowIcon( |   QApplication::setWindowIcon( | ||||||
|       QIcon(":assets/de.shorsh.discord-screenaudio.png")); |       QIcon(":assets/de.shorsh.discord-screenaudio.png")); | ||||||
| @@ -50,6 +55,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(); | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ | |||||||
| #include <QGridLayout> | #include <QGridLayout> | ||||||
| #include <QLabel> | #include <QLabel> | ||||||
| #include <QPushButton> | #include <QPushButton> | ||||||
|  | #include <QShortcut> | ||||||
| #include <QSpacerItem> | #include <QSpacerItem> | ||||||
| #include <QThread> | #include <QThread> | ||||||
| #include <QTimer> | #include <QTimer> | ||||||
| @@ -31,6 +32,8 @@ MainWindow::MainWindow(bool useNotifySend, QWidget *parent) | |||||||
|   setCentralWidget(m_centralWidget); |   setCentralWidget(m_centralWidget); | ||||||
|   setupTrayIcon(); |   setupTrayIcon(); | ||||||
|   setMinimumSize(800, 300); |   setMinimumSize(800, 300); | ||||||
|  |   connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this), | ||||||
|  |           &QShortcut::activated, this, &MainWindow::toggleOrCloseWindow); | ||||||
|   if (m_settings->contains("geometry")) { |   if (m_settings->contains("geometry")) { | ||||||
|     restoreGeometry(m_settings->value("geometry").toByteArray()); |     restoreGeometry(m_settings->value("geometry").toByteArray()); | ||||||
|   } else { |   } else { | ||||||
| @@ -79,12 +82,7 @@ void MainWindow::setupTrayIcon() { | |||||||
|  |  | ||||||
|   connect(m_trayIcon, &QSystemTrayIcon::activated, [this](auto reason) { |   connect(m_trayIcon, &QSystemTrayIcon::activated, [this](auto reason) { | ||||||
|     if (reason == QSystemTrayIcon::Trigger) { |     if (reason == QSystemTrayIcon::Trigger) { | ||||||
|       if (isVisible()) { |       toggleOrCloseWindow(); | ||||||
|         hide(); |  | ||||||
|       } else { |  | ||||||
|         show(); |  | ||||||
|         activateWindow(); |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
| @@ -131,3 +129,15 @@ MainWindow *MainWindow::instance() { return m_instance; } | |||||||
| CentralWidget *MainWindow::centralWidget() { | CentralWidget *MainWindow::centralWidget() { | ||||||
|   return instance()->m_centralWidget; |   return instance()->m_centralWidget; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | void MainWindow::toggleOrCloseWindow() { | ||||||
|  |   if (isVisible()) { | ||||||
|  |     if (m_trayIcon == nullptr) | ||||||
|  |       QApplication::quit(); | ||||||
|  |     else | ||||||
|  |       hide(); | ||||||
|  |   } else { | ||||||
|  |     show(); | ||||||
|  |     activateWindow(); | ||||||
|  |   } | ||||||
|  | } | ||||||
|   | |||||||
| @@ -36,4 +36,5 @@ private: | |||||||
| public Q_SLOTS: | public Q_SLOTS: | ||||||
|   void setTrayIcon(bool enabled); |   void setTrayIcon(bool enabled); | ||||||
|   void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); |   void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); | ||||||
|  |   void toggleOrCloseWindow(); | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user