diff options
author | Christian Kamm <mail@ckamm.de> | 2019-03-06 12:55:45 +0300 |
---|---|---|
committer | Markus Goetz <markus@woboq.com> | 2019-03-08 04:08:18 +0300 |
commit | e24c0f2f14a2b46d4099b4a34d52bb722d333c71 (patch) | |
tree | e44df7de35466ec19123ba1c17d24a7942fe6650 | |
parent | 69bde24c30a9d6b5f385b8200731811c6700e965 (diff) |
Tray: Try to establish tray after 10s if failed initially #6518
When owncloud is started during desktop startup the tray may not yet
be running when the client starts. This will make the client attempt
to create a tray icon again after 10 seconds if there's no tray
during initial startup.
-rw-r--r-- | src/gui/application.cpp | 7 | ||||
-rw-r--r-- | src/gui/application.h | 3 | ||||
-rw-r--r-- | src/gui/main.cpp | 26 | ||||
-rw-r--r-- | src/gui/owncloudgui.cpp | 6 | ||||
-rw-r--r-- | src/gui/owncloudgui.h | 2 |
5 files changed, 35 insertions, 9 deletions
diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 747f7aef6..33265af35 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -741,6 +741,13 @@ void Application::openVirtualFile(const QString &filename) }); } +void Application::tryTrayAgain() +{ + qCInfo(lcApplication) << "Trying tray icon, tray available:" << QSystemTrayIcon::isSystemTrayAvailable(); + if (!_gui->contextMenuVisible()) + _gui->hideAndShowTray(); +} + bool Application::event(QEvent *event) { #ifdef Q_OS_MAC diff --git a/src/gui/application.h b/src/gui/application.h index c29ca8b41..f4d46b04a 100644 --- a/src/gui/application.h +++ b/src/gui/application.h @@ -80,6 +80,9 @@ public slots: */ void openVirtualFile(const QString &filename); + /// Attempt to show() the tray icon again. Used if no systray was available initially. + void tryTrayAgain(); + protected: void parseOptions(const QStringList &); void setupTranslations(); diff --git a/src/gui/main.cpp b/src/gui/main.cpp index efe87a9d6..e1f7b4f40 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -127,6 +127,7 @@ int main(int argc, char **argv) } return 0; } + // We can't call isSystemTrayAvailable with appmenu-qt5 begause it hides the systemtray // (issue #4693) if (qgetenv("QT_QPA_PLATFORMTHEME") != "appmenu-qt5") @@ -135,27 +136,34 @@ int main(int argc, char **argv) // If the systemtray is not there, we will wait one second for it to maybe start // (eg boot time) then we show the settings dialog if there is still no systemtray. // On XFCE however, we show a message box with explainaition how to install a systemtray. + qCInfo(lcApplication) << "System tray is not available, waiting..."; Utility::sleep(1); + auto desktopSession = qgetenv("XDG_CURRENT_DESKTOP").toLower(); if (desktopSession.isEmpty()) { desktopSession = qgetenv("DESKTOP_SESSION").toLower(); } if (desktopSession == "xfce") { int attempts = 0; - forever { - if (!QSystemTrayIcon::isSystemTrayAvailable()) { - Utility::sleep(1); - attempts++; - if (attempts < 30) - continue; - } else { + while (!QSystemTrayIcon::isSystemTrayAvailable()) { + attempts++; + if (attempts >= 30) { + qCWarning(lcApplication) << "System tray unavailable (xfce)"; + warnSystray(); break; } - warnSystray(); + Utility::sleep(1); } } - if (!QSystemTrayIcon::isSystemTrayAvailable() && desktopSession != "ubuntu") { + + if (QSystemTrayIcon::isSystemTrayAvailable()) { + app.tryTrayAgain(); + } else if (desktopSession != "ubuntu") { + qCInfo(lcApplication) << "System tray still not available, showing window and trying again later"; app.showSettingsDialog(); + QTimer::singleShot(10000, &app, &Application::tryTrayAgain); + } else { + qCInfo(lcApplication) << "System tray still not available, but assuming it's fine on 'ubuntu' desktop"; } } } diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 8ba0ed3e2..9133e6392 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -426,6 +426,12 @@ bool ownCloudGui::contextMenuVisible() const return _contextMenu->isVisible(); } +void ownCloudGui::hideAndShowTray() +{ + _tray->hide(); + _tray->show(); +} + static bool minimalTrayMenu() { static QByteArray var = qgetenv("OWNCLOUD_MINIMAL_TRAY_MENU"); diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index b12fdf7b5..b76e4e06a 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -61,6 +61,8 @@ public: /// Whether the tray menu is visible bool contextMenuVisible() const; + void hideAndShowTray(); + signals: void setupProxy(); |