mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
Re-create QSystemTrayIcon on SNI watcher owner change
This commit is contained in:
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>();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "base/unique_qptr.h"
|
||||
|
||||
namespace base::Platform::DBus {
|
||||
class ServiceWatcher;
|
||||
} // namespace base::Platform::DBus
|
||||
|
||||
namespace Ui {
|
||||
class PopupMenu;
|
||||
} // namespace Ui
|
||||
|
@ -51,6 +55,7 @@ public:
|
|||
[[nodiscard]] rpl::lifetime &lifetime();
|
||||
|
||||
private:
|
||||
std::unique_ptr<base::Platform::DBus::ServiceWatcher> _sniWatcher;
|
||||
std::unique_ptr<IconGraphic> _iconGraphic;
|
||||
|
||||
base::unique_qptr<QSystemTrayIcon> _icon;
|
||||
|
|
Loading…
Add table
Reference in a new issue