3636#include " FileSystem.h"
3737#include " ui_TopBar.h"
3838
39+ #include < iostream>
40+
41+ static void notifyTrayStart (QSystemTrayIcon* tray) {
42+ if (qApp->property (" invokedAsTray" ).toBool ()) return ;
43+ uint count = gSettings ->getTrayInfoCount ();
44+ if (count >= 4 ) return ;
45+ if (gSettings ->getTopBarVisibility ()) return ;
46+
47+ tray->showMessage (" OpenBangla Keyboard" , " Currently running in the system tray.\n "
48+ " You can use the tray icon to change keyboard layouts and other "
49+ " settings and to show the TopBar again." );
50+ // Update the counter to show only the message for the first three times
51+ gSettings ->setTrayInfoCount (count + 1 );
52+ }
3953
4054TopBar::TopBar (bool darkIcon, QWidget *parent) :
4155 QMainWindow(parent),
@@ -74,17 +88,11 @@ TopBar::TopBar(bool darkIcon, QWidget *parent) :
7488 SetupPopupMenus ();
7589 SetupTrayIcon ();
7690 DataMigration ();
77-
78- uint count = gSettings ->getTrayInfoCount ();
79- if (count < 4 && !gSettings ->getTopBarVisibility ()) {
80- tray->showMessage (" OpenBangla Keyboard" , " Currently running in the system tray.\n "
81- " You can use the tray icon to change keyboard layouts and other "
82- " settings and to show the TopBar again." );
83- // Update the counter to show only the message for the first three times
84- gSettings ->setTrayInfoCount (count + 1 );
85- }
91+ notifyTrayStart (tray);
8692}
8793
94+
95+
8896TopBar::~TopBar () {
8997 /* Dialogs */
9098 delete layoutViewer;
@@ -140,7 +148,7 @@ void TopBar::SetupPopupMenus() {
140148 // Icon Button Popup Menu
141149 iconMenuHide = new QAction (" Hide this TopBar" , this );
142150 connect (iconMenuHide, &QAction::triggered, [&]() {
143- this ->setVisible ( false );
151+ this ->hide ( );
144152 trayTopBarVisibility->setText (" Show the TopBar" );
145153 });
146154
@@ -184,16 +192,18 @@ void TopBar::SetupTrayIcon() {
184192 connect (traySettings, &QAction::triggered, this , &TopBar::on_buttonSettings_clicked);
185193
186194 trayTopBarVisibility = new QAction (
187- gSettings ->getTopBarVisibility () ? " Hide the TopBar" : " Show the TopBar" ,
195+ (this ->isVisible ())
196+ ? " Hide the TopBar"
197+ : " Show the TopBar" ,
188198 this
189199 );
190200
191201 connect (trayTopBarVisibility, &QAction::triggered, [&]() {
192202 if (this ->isVisible ()) {
193- this ->setVisible ( false );
203+ this ->hide ( );
194204 trayTopBarVisibility->setText (" Show the TopBar" );
195205 } else {
196- this ->setVisible ( true );
206+ this ->show ( );
197207 trayTopBarVisibility->setText (" Hide the TopBar" );
198208 }
199209 });
@@ -211,7 +221,7 @@ void TopBar::SetupTrayIcon() {
211221 trayMenu->addAction (trayQuit);
212222
213223 tray->setContextMenu (trayMenu);
214- tray->setVisible ( true );
224+ tray->show ( );
215225}
216226
217227void TopBar::RefreshLayouts () {
@@ -335,7 +345,8 @@ void TopBar::on_buttonIcon_clicked() {
335345
336346void TopBar::closeEvent (QCloseEvent *event) {
337347 gSettings ->setTopBarWindowPosition (this ->pos ());
338- gSettings ->setTopBarVisibility (this ->isVisible ());
348+ if (! qApp->property (" invokedAsTray" ).toBool ())
349+ gSettings ->setTopBarVisibility (this ->isVisible ());
339350 event->accept ();
340351}
341352
@@ -377,7 +388,8 @@ void TopBar::on_buttonSetLayout_clicked() {
377388
378389void TopBar::on_buttonShutdown_clicked () {
379390 gSettings ->setTopBarWindowPosition (this ->pos ());
380- gSettings ->setTopBarVisibility (this ->isVisible ());
391+ if (! qApp->property (" invokedAsTray" ).toBool ())
392+ gSettings ->setTopBarVisibility (this ->isVisible ());
381393 QApplication::exit ();
382394}
383395
0 commit comments