Skip to content

Commit c320b4e

Browse files
jdholtztim-gromeyer
authored andcommitted
[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.
1 parent ed0de4d commit c320b4e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

linux/Main.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import QtQuick.Controls 2.15
55

66
ApplicationWindow {
77
id: mainWindow
8-
visible: true
8+
visible: !airPodsTrayApp.hideOnStart
99
width: 400
1010
height: 300
1111
title: "AirPods Settings"

linux/main.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ class AirPodsTrayApp : public QObject {
3535
Q_PROPERTY(AutoStartManager *autoStartManager READ autoStartManager CONSTANT)
3636
Q_PROPERTY(bool notificationsEnabled READ notificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
3737
Q_PROPERTY(int retryAttempts READ retryAttempts WRITE setRetryAttempts NOTIFY retryAttemptsChanged)
38+
Q_PROPERTY(bool hideOnStart READ hideOnStart CONSTANT)
3839

3940
public:
40-
AirPodsTrayApp(bool debugMode, QObject *parent = nullptr)
41+
AirPodsTrayApp(bool debugMode, bool hideOnStart, QObject *parent = nullptr)
4142
: QObject(parent)
4243
, debugMode(debugMode)
4344
, m_battery(new Battery(this))
4445
, monitor(new BluetoothMonitor(this))
4546
, m_settings(new QSettings("AirPodsTrayApp", "AirPodsTrayApp"))
4647
, m_autoStartManager(new AutoStartManager(this))
48+
, m_hideOnStart(hideOnStart)
4749
{
4850
if (debugMode) {
4951
QLoggingCategory::setFilterRules("airpodsApp.debug=true");
@@ -139,6 +141,7 @@ class AirPodsTrayApp : public QObject {
139141
bool notificationsEnabled() const { return trayManager->notificationsEnabled(); }
140142
void setNotificationsEnabled(bool enabled) { trayManager->setNotificationsEnabled(enabled); }
141143
int retryAttempts() const { return m_retryAttempts; }
144+
bool hideOnStart() const { return m_hideOnStart; }
142145

143146
private:
144147
bool debugMode;
@@ -897,6 +900,7 @@ private slots:
897900
QSettings *m_settings;
898901
AutoStartManager *m_autoStartManager;
899902
int m_retryAttempts = 3;
903+
bool m_hideOnStart = false;
900904

901905
QString m_batteryStatus;
902906
QString m_earDetectionStatus;
@@ -917,16 +921,18 @@ int main(int argc, char *argv[]) {
917921
app.setQuitOnLastWindowClosed(false);
918922

919923
bool debugMode = false;
924+
bool hideOnStart = false;
920925
for (int i = 1; i < argc; ++i) {
921-
if (QString(argv[i]) == "--debug") {
926+
if (QString(argv[i]) == "--debug")
922927
debugMode = true;
923-
break;
924-
}
928+
929+
if (QString(argv[i]) == "--hide")
930+
hideOnStart = true;
925931
}
926932

927933
QQmlApplicationEngine engine;
928934
qmlRegisterType<Battery>("me.kavishdevar.Battery", 1, 0, "Battery");
929-
AirPodsTrayApp *trayApp = new AirPodsTrayApp(debugMode, &engine);
935+
AirPodsTrayApp *trayApp = new AirPodsTrayApp(debugMode, hideOnStart, &engine);
930936
engine.rootContext()->setContextProperty("airPodsTrayApp", trayApp);
931937
engine.loadFromModule("linux", "Main");
932938
return app.exec();

0 commit comments

Comments
 (0)