From dc5f4879be0461535017780ec639875325de3f01 Mon Sep 17 00:00:00 2001 From: Hartmnt Date: Thu, 13 Jun 2024 17:06:19 +0000 Subject: [PATCH] FEAT(client): Add --hidden cli option to start Mumble hidden in tray This commit introduces the "--hidden" cli option which prevents Mumble and the ConnectDialog to show up on startup. This is especially useful for users who want to automate the startup process without human interaction. Fixes #3879 --- src/mumble/main.cpp | 20 +++++++++++++++++--- src/mumble/widgets/TrayIcon.cpp | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/mumble/main.cpp b/src/mumble/main.cpp index 73d90ccfee8..d22b51d38b0 100644 --- a/src/mumble/main.cpp +++ b/src/mumble/main.cpp @@ -55,6 +55,7 @@ #include #include +#include #include #include #include @@ -212,6 +213,7 @@ int main(int argc, char **argv) { bool customJackClientName = false; bool bRpcMode = false; bool printTranslationDirs = false; + bool startHiddenInTray = false; QString rpcCommand; QUrl url; QDir qdCert(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); @@ -288,7 +290,9 @@ int main(int argc, char **argv) { " locale that corresponds to the given locale string.\n" " If the format is invalid, Mumble will error.\n" " Otherwise the locale will be permanently saved to\n" - " Mumble's settings." + " Mumble's settings.\n" + " --hidden\n" + " Start Mumble hidden in the system tray." "\n"); QString rpcHelpBanner = MainWindow::tr("Remote controlling Mumble:\n" "\n"); @@ -415,6 +419,9 @@ int main(int argc, char **argv) { qCritical("Missing argument for --locale!"); return 1; } + } else if (args.at(i) == "--hidden") { + startHiddenInTray = true; + qInfo("Starting hidden in system tray"); } else if (args.at(i) == "--version") { // Print version and exit (print to regular std::cout to avoid adding any useless meta-information from // using e.g. qWarning @@ -684,9 +691,16 @@ int main(int argc, char **argv) { // Main Window Global::get().mw = new MainWindow(nullptr); - Global::get().mw->show(); + if (!startHiddenInTray) { + Global::get().mw->showRaiseWindow(); + } Global::get().trayIcon = new TrayIcon(); +#ifdef Q_OS_MAC + if (startHiddenInTray) { + QTimer::singleShot(0, []() { emit Global::get().trayIcon->on_hideAction_triggered(); }); + } +#endif Global::get().talkingUI = new TalkingUI(); @@ -799,7 +813,7 @@ int main(int argc, char **argv) { OpenURLEvent *oue = new OpenURLEvent(a.quLaunchURL); qApp->postEvent(Global::get().mw, oue); #endif - } else { + } else if (!startHiddenInTray || Global::get().s.bAutoConnect) { Global::get().mw->on_qaServerConnect_triggered(true); } diff --git a/src/mumble/widgets/TrayIcon.cpp b/src/mumble/widgets/TrayIcon.cpp index f3d63407e3b..a88a3e5e1bb 100644 --- a/src/mumble/widgets/TrayIcon.cpp +++ b/src/mumble/widgets/TrayIcon.cpp @@ -160,6 +160,7 @@ void TrayIcon::on_showAction_triggered() { } void TrayIcon::on_hideAction_triggered() { +#ifndef Q_OS_MAC if (!QSystemTrayIcon::isSystemTrayAvailable()) { qDebug() << "Tray: Not available. Hide prevented..."; // The system reports that no system tray is available. @@ -176,7 +177,6 @@ void TrayIcon::on_hideAction_triggered() { return; } -#ifndef Q_OS_MAC qDebug() << "Tray: Hide window!"; Global::get().mw->hide(); #else