Ensure that window is not hidden with no system tray after startup

Before in all cases we would wait for the system tray for a period
of time, this would block users who don't have autohide enabled
and don't have a system tray from seeing the window.

Instead flip this around to either hide the window at startup if
autohide is enabled and show if it isn't. Then if we have opened
hidden wait a period of time and check if system tray is available,
if it isn't then force the window to be shown.

This provides much better UX for the general cases.

Closes #1024
This commit is contained in:
Andrew Hayzen 2021-03-02 23:14:59 +00:00
parent 3e7e7b1af3
commit d0df871373
3 changed files with 41 additions and 7 deletions

View File

@ -52,6 +52,7 @@
#include <Windows.h>
#endif
static const int systemTrayWaitTime = 10000;
static const QString allFilesFilter(QObject::tr("All files (*.*)"));
#if defined(Q_OS_WIN)
static const char barrierConfigName[] = "barrier.sgc";
@ -156,6 +157,9 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_pComboServerList->hide();
m_pLabelPadlock->hide();
m_OpenHiddenTrayTimer.setSingleShot(true);
connect(&m_OpenHiddenTrayTimer, &QTimer::timeout, this, &MainWindow::on_m_OpenHiddenTrayTimer_triggered);
updateSSLFingerprint();
// resize window to smallest reasonable size
@ -190,6 +194,28 @@ void MainWindow::open()
if (appConfig().getAutoHide()) {
hide();
// If system tray is not available, start a timer to ensure we don't become
// stuck in a hidden state
//
// The previous solution for this would wait at the startup of the app to
// see if the system tray becomes available before showing any window - even
// if the user didn't have autohide enabled.
//
// This solution instead, hides the window if they have autohide enabled, or shows
// the window if they don't. Then if the user has selected to autohide the window
// it checks after a period of time if the system tray is not available - if it
// isn't then it forces the window to show.
//
// This provides a much better UX for the two main use cases (user starting app with
// autohide enabled with system tray available and user starting app with autohide
// disabled with no system tray available). And provides a workaround for the edge
// case of a user enabling autohide with no system tray available (this should now
// be harder to do as the option in settings will become disabled).
if (!QSystemTrayIcon::isSystemTrayAvailable())
{
m_OpenHiddenTrayTimer.start(systemTrayWaitTime);
}
} else {
showNormal();
}
@ -208,6 +234,18 @@ void MainWindow::open()
}
}
void MainWindow::on_m_OpenHiddenTrayTimer_triggered()
{
// If the system tray is still not available then force window to show
if (!QSystemTrayIcon::isSystemTrayAvailable())
{
fprintf(stdout, "System tray not available, force disabling auto hide!\n");
m_AppConfig->setAutoHide(false);
showNormal();
}
}
void MainWindow::setStatus(const QString &status)
{
m_pStatusLabel->setText(status);

View File

@ -25,6 +25,7 @@
#include <QSettings>
#include <QProcess>
#include <QThread>
#include <QTimer>
#include "ui_MainWindowBase.h"
@ -201,11 +202,13 @@ public slots:
SslCertificate* m_pSslCertificate;
QStringList m_PendingClientNames;
LogWindow *m_pLogWindow;
QTimer m_OpenHiddenTrayTimer;
private slots:
void on_m_pCheckBoxAutoConfig_toggled(bool checked);
void on_m_pComboServerList_currentIndexChanged(QString );
void on_m_pButtonReload_clicked();
void on_m_OpenHiddenTrayTimer_triggered();
void installBonjour();
};

View File

@ -91,13 +91,6 @@ int main(int argc, char* argv[])
QSettings settings;
AppConfig appConfig (&settings);
if (appConfig.getAutoHide() && !QSystemTrayIcon::isSystemTrayAvailable())
{
// force auto hide to false - otherwise there is no way to get the GUI back
fprintf(stdout, "System tray not available, force disabling auto hide!\n");
appConfig.setAutoHide(false);
}
app.switchTranslator(appConfig.language());
MainWindow mainWindow(settings, appConfig);