Don't check com.canonical.Unity for the counter
It seems there's a race condition when Telegram is auto-started on Plasma and it doesn't hurt to issue the signal always, so just remove the check
This commit is contained in:
parent
9c27271571
commit
577f4b6271
|
@ -33,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
||||||
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
@ -179,24 +178,6 @@ void ForceDisabled(QAction *action, bool disabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
bool UseUnityCounter() {
|
|
||||||
static const auto Result = [&] {
|
|
||||||
try {
|
|
||||||
const auto connection = Gio::DBus::Connection::get_sync(
|
|
||||||
Gio::DBus::BusType::SESSION);
|
|
||||||
|
|
||||||
return base::Platform::DBus::NameHasOwner(
|
|
||||||
connection,
|
|
||||||
"com.canonical.Unity");
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}();
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint djbStringHash(const std::string &string) {
|
uint djbStringHash(const std::string &string) {
|
||||||
uint hash = 5381;
|
uint hash = 5381;
|
||||||
for (const auto &curChar : string) {
|
for (const auto &curChar : string) {
|
||||||
|
@ -234,14 +215,6 @@ void MainWindow::initHook() {
|
||||||
return base::EventFilterResult::Continue;
|
return base::EventFilterResult::Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
if (UseUnityCounter()) {
|
|
||||||
LOG(("Using Unity launcher counter."));
|
|
||||||
} else {
|
|
||||||
LOG(("Not using Unity launcher counter."));
|
|
||||||
}
|
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
XCBSetDesktopFileName(windowHandle());
|
XCBSetDesktopFileName(windowHandle());
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
@ -263,42 +236,40 @@ void MainWindow::updateIconCounters() {
|
||||||
updateWindowIcon();
|
updateWindowIcon();
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
if (UseUnityCounter()) {
|
const auto launcherUrl = Glib::ustring(
|
||||||
const auto launcherUrl = Glib::ustring(
|
"application://"
|
||||||
"application://"
|
+ QGuiApplication::desktopFileName().toStdString());
|
||||||
+ QGuiApplication::desktopFileName().toStdString());
|
const auto counterSlice = std::min(Core::App().unreadBadge(), 9999);
|
||||||
const auto counterSlice = std::min(Core::App().unreadBadge(), 9999);
|
std::map<Glib::ustring, Glib::VariantBase> dbusUnityProperties;
|
||||||
std::map<Glib::ustring, Glib::VariantBase> dbusUnityProperties;
|
|
||||||
|
|
||||||
if (counterSlice > 0) {
|
if (counterSlice > 0) {
|
||||||
// According to the spec, it should be of 'x' D-Bus signature,
|
// According to the spec, it should be of 'x' D-Bus signature,
|
||||||
// which corresponds to signed 64-bit integer
|
// which corresponds to signed 64-bit integer
|
||||||
// https://wiki.ubuntu.com/Unity/LauncherAPI#Low_level_DBus_API:_com.canonical.Unity.LauncherEntry
|
// https://wiki.ubuntu.com/Unity/LauncherAPI#Low_level_DBus_API:_com.canonical.Unity.LauncherEntry
|
||||||
dbusUnityProperties["count"] = Glib::Variant<int64>::create(
|
dbusUnityProperties["count"] = Glib::Variant<int64>::create(
|
||||||
counterSlice);
|
counterSlice);
|
||||||
dbusUnityProperties["count-visible"] =
|
dbusUnityProperties["count-visible"] =
|
||||||
Glib::Variant<bool>::create(true);
|
Glib::Variant<bool>::create(true);
|
||||||
} else {
|
} else {
|
||||||
dbusUnityProperties["count-visible"] =
|
dbusUnityProperties["count-visible"] =
|
||||||
Glib::Variant<bool>::create(false);
|
Glib::Variant<bool>::create(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const auto connection = Gio::DBus::Connection::get_sync(
|
const auto connection = Gio::DBus::Connection::get_sync(
|
||||||
Gio::DBus::BusType::SESSION);
|
Gio::DBus::BusType::SESSION);
|
||||||
|
|
||||||
connection->emit_signal(
|
connection->emit_signal(
|
||||||
"/com/canonical/unity/launcherentry/"
|
"/com/canonical/unity/launcherentry/"
|
||||||
+ std::to_string(djbStringHash(launcherUrl)),
|
+ std::to_string(djbStringHash(launcherUrl)),
|
||||||
"com.canonical.Unity.LauncherEntry",
|
"com.canonical.Unity.LauncherEntry",
|
||||||
"Update",
|
"Update",
|
||||||
{},
|
{},
|
||||||
base::Platform::MakeGlibVariant(std::tuple{
|
base::Platform::MakeGlibVariant(std::tuple{
|
||||||
launcherUrl,
|
launcherUrl,
|
||||||
dbusUnityProperties,
|
dbusUnityProperties,
|
||||||
}));
|
}));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user