Re-create QSystemTrayIcon on SNI watcher owner change

This commit is contained in:
Ilya Fedin
2024-06-19 02:47:37 +04:00
committed by John Preston
parent 750ad600be
commit 8a5797e1bd
2 changed files with 29 additions and 1 deletions
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/invoke_queued.h"
#include "base/qt_signal_producer.h"
#include "base/platform/linux/base_linux_dbus_utilities.h"
#include "core/application.h"
#include "core/sandbox.h"
#include "platform/platform_specific.h"
@@ -21,9 +22,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QMenu>
#include <QtWidgets/QSystemTrayIcon>
#include <gio/gio.hpp>
namespace Platform {
namespace {
using namespace gi::repository;
[[nodiscard]] QString PanelIconName(int counter, bool muted) {
return (counter > 0)
? (muted
@@ -282,11 +287,29 @@ rpl::producer<> TrayEventFilter::contextMenuFilters() const {
}
Tray::Tray() {
LOG(("System tray available: %1").arg(Logs::b(TrayIconSupported())));
auto connection = Gio::bus_get_sync(Gio::BusType::SESSION_, nullptr);
if (connection) {
_sniWatcher = std::make_unique<base::Platform::DBus::ServiceWatcher>(
connection.gobj_(),
"org.kde.StatusNotifierWatcher",
[=](
const std::string &service,
const std::string &oldOwner,
const std::string &newOwner) {
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
if (hasIcon()) {
destroyIcon();
createIcon();
}
});
});
}
}
void Tray::createIcon() {
if (!_icon) {
LOG(("System tray available: %1").arg(Logs::b(TrayIconSupported())));
if (!_iconGraphic) {
_iconGraphic = std::make_unique<IconGraphic>();
}