From c320b4e27d1a14c44dba6c248f4fbf0b85ab5de5 Mon Sep 17 00:00:00 2001 From: jdholtz Date: Wed, 23 Apr 2025 12:43:31 -0700 Subject: [PATCH] [Linux] Add CLI flag to hide the window on startup I like to start this program when connecting to my AirPods and it isn't necessary for me to have the window pop up. Therefore, using the --hide flag when starting the program will hide the window on startup. This could also be a configuration option (e.g. 'Start minimized') but I went with the CLI flag for simplicity for now. However, if this is a more viable option (and it may be better in the future), I can implement this as an option in the settings instead. --- linux/Main.qml | 2 +- linux/main.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/linux/Main.qml b/linux/Main.qml index f8c2c90..f4650b2 100644 --- a/linux/Main.qml +++ b/linux/Main.qml @@ -5,7 +5,7 @@ import QtQuick.Controls 2.15 ApplicationWindow { id: mainWindow - visible: true + visible: !airPodsTrayApp.hideOnStart width: 400 height: 300 title: "AirPods Settings" diff --git a/linux/main.cpp b/linux/main.cpp index 8247212..ae5a10f 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -35,15 +35,17 @@ class AirPodsTrayApp : public QObject { Q_PROPERTY(AutoStartManager *autoStartManager READ autoStartManager CONSTANT) Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged) Q_PROPERTY(int retryAttempts READ retryAttempts WRITE setRetryAttempts NOTIFY retryAttemptsChanged) + Q_PROPERTY(bool hideOnStart READ hideOnStart CONSTANT) public: - AirPodsTrayApp(bool debugMode, QObject *parent = nullptr) + AirPodsTrayApp(bool debugMode, bool hideOnStart, QObject *parent = nullptr) : QObject(parent) , debugMode(debugMode) , m_battery(new Battery(this)) , monitor(new BluetoothMonitor(this)) , m_settings(new QSettings("AirPodsTrayApp", "AirPodsTrayApp")) , m_autoStartManager(new AutoStartManager(this)) + , m_hideOnStart(hideOnStart) { if (debugMode) { QLoggingCategory::setFilterRules("airpodsApp.debug=true"); @@ -139,6 +141,7 @@ public: bool notificationsEnabled() const { return trayManager->notificationsEnabled(); } void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); } int retryAttempts() const { return m_retryAttempts; } + bool hideOnStart() const { return m_hideOnStart; } private: bool debugMode; @@ -897,6 +900,7 @@ private: QSettings *m_settings; AutoStartManager *m_autoStartManager; int m_retryAttempts = 3; + bool m_hideOnStart = false; QString m_batteryStatus; QString m_earDetectionStatus; @@ -917,16 +921,18 @@ int main(int argc, char *argv[]) { app.setQuitOnLastWindowClosed(false); bool debugMode = false; + bool hideOnStart = false; for (int i = 1; i < argc; ++i) { - if (QString(argv[i]) == "--debug") { + if (QString(argv[i]) == "--debug") debugMode = true; - break; - } + + if (QString(argv[i]) == "--hide") + hideOnStart = true; } QQmlApplicationEngine engine; qmlRegisterType("me.kavishdevar.Battery", 1, 0, "Battery"); - AirPodsTrayApp *trayApp = new AirPodsTrayApp(debugMode, &engine); + AirPodsTrayApp *trayApp = new AirPodsTrayApp(debugMode, hideOnStart, &engine); engine.rootContext()->setContextProperty("airPodsTrayApp", trayApp); engine.loadFromModule("linux", "Main"); return app.exec();