mirror of https://github.com/procxx/kepka.git
Generalize backward compatibility of linux launcher
This commit is contained in:
parent
ca1623f34a
commit
5bdc0db9e2
|
@ -44,12 +44,6 @@ int32 _trayIconCount = 0;
|
||||||
QImage _trayIconImageBack, _trayIconImage;
|
QImage _trayIconImageBack, _trayIconImage;
|
||||||
QString _trayIconThemeName, _trayIconName;
|
QString _trayIconThemeName, _trayIconName;
|
||||||
|
|
||||||
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
||||||
bool UseUnityCount = false;
|
|
||||||
QString UnityCountDesktopFile;
|
|
||||||
QString UnityCountDBusPath = "/";
|
|
||||||
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
QString GetTrayIconName() {
|
QString GetTrayIconName() {
|
||||||
const auto counter = Core::App().unreadBadge();
|
const auto counter = Core::App().unreadBadge();
|
||||||
const auto muted = Core::App().unreadBadgeMuted();
|
const auto muted = Core::App().unreadBadgeMuted();
|
||||||
|
@ -222,6 +216,18 @@ bool IsSNIAvailable() {
|
||||||
return SNIAvailable;
|
return SNIAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UseUnityCounter() {
|
||||||
|
#ifdef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||||
|
static const auto UnityCounter = false;
|
||||||
|
#else // TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||||
|
static const auto UnityCounter = QDBusInterface(
|
||||||
|
"com.canonical.Unity",
|
||||||
|
"/").isValid();
|
||||||
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
|
return UnityCounter;
|
||||||
|
}
|
||||||
|
|
||||||
quint32 djbStringHash(QString string) {
|
quint32 djbStringHash(QString string) {
|
||||||
quint32 hash = 5381;
|
quint32 hash = 5381;
|
||||||
QByteArray chars = string.toLatin1();
|
QByteArray chars = string.toLatin1();
|
||||||
|
@ -375,8 +381,9 @@ void MainWindow::updateIconCounters() {
|
||||||
updateWindowIcon();
|
updateWindowIcon();
|
||||||
|
|
||||||
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||||
if (UseUnityCount) {
|
if (UseUnityCounter()) {
|
||||||
const auto counter = Core::App().unreadBadge();
|
const auto counter = Core::App().unreadBadge();
|
||||||
|
const auto launcherUrl = "application://" + GetLauncherFilename();
|
||||||
QVariantMap dbusUnityProperties;
|
QVariantMap dbusUnityProperties;
|
||||||
if (counter > 0) {
|
if (counter > 0) {
|
||||||
// Gnome requires that count is a 64bit integer
|
// Gnome requires that count is a 64bit integer
|
||||||
|
@ -384,16 +391,17 @@ void MainWindow::updateIconCounters() {
|
||||||
"count",
|
"count",
|
||||||
(qint64) ((counter > 9999)
|
(qint64) ((counter > 9999)
|
||||||
? 9999
|
? 9999
|
||||||
: (counter)));
|
: counter));
|
||||||
dbusUnityProperties.insert("count-visible", true);
|
dbusUnityProperties.insert("count-visible", true);
|
||||||
} else {
|
} else {
|
||||||
dbusUnityProperties.insert("count-visible", false);
|
dbusUnityProperties.insert("count-visible", false);
|
||||||
}
|
}
|
||||||
QDBusMessage signal = QDBusMessage::createSignal(
|
QDBusMessage signal = QDBusMessage::createSignal(
|
||||||
UnityCountDBusPath,
|
"/com/canonical/unity/launcherentry/"
|
||||||
|
+ QString::number(djbStringHash(launcherUrl)),
|
||||||
"com.canonical.Unity.LauncherEntry",
|
"com.canonical.Unity.LauncherEntry",
|
||||||
"Update");
|
"Update");
|
||||||
signal << "application://" + UnityCountDesktopFile;
|
signal << launcherUrl;
|
||||||
signal << dbusUnityProperties;
|
signal << dbusUnityProperties;
|
||||||
QDBusConnection::sessionBus().send(signal);
|
QDBusConnection::sessionBus().send(signal);
|
||||||
}
|
}
|
||||||
|
@ -432,34 +440,11 @@ void MainWindow::initTrayMenuHook() {
|
||||||
LOG(("System tray available: %1").arg(Logs::b(trayAvailable)));
|
LOG(("System tray available: %1").arg(Logs::b(trayAvailable)));
|
||||||
cSetSupportTray(trayAvailable);
|
cSetSupportTray(trayAvailable);
|
||||||
|
|
||||||
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
if (UseUnityCounter()) {
|
||||||
if (QDBusInterface("com.canonical.Unity", "/").isValid()) {
|
LOG(("Using Unity launcher counter."));
|
||||||
const std::vector<QString> possibleDesktopFiles = {
|
|
||||||
GetLauncherFilename(),
|
|
||||||
"Telegram.desktop"
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto it = possibleDesktopFiles.begin();
|
|
||||||
it != possibleDesktopFiles.end(); it++) {
|
|
||||||
if (!QStandardPaths::locate(
|
|
||||||
QStandardPaths::ApplicationsLocation, *it).isEmpty()) {
|
|
||||||
UnityCountDesktopFile = *it;
|
|
||||||
LOG(("Found Unity Launcher entry %1!")
|
|
||||||
.arg(UnityCountDesktopFile));
|
|
||||||
UseUnityCount = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!UseUnityCount) {
|
|
||||||
LOG(("Could not get Unity Launcher entry!"));
|
|
||||||
}
|
|
||||||
UnityCountDBusPath = "/com/canonical/unity/launcherentry/"
|
|
||||||
+ QString::number(
|
|
||||||
djbStringHash("application://" + UnityCountDesktopFile));
|
|
||||||
} else {
|
} else {
|
||||||
LOG(("Not using Unity Launcher count."));
|
LOG(("Not using Unity launcher counter."));
|
||||||
}
|
}
|
||||||
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
|
|
|
@ -282,25 +282,34 @@ QString SingleInstanceLocalServerName(const QString &hash) {
|
||||||
|
|
||||||
QString GetLauncherBasename() {
|
QString GetLauncherBasename() {
|
||||||
static const auto LauncherBasename = [&] {
|
static const auto LauncherBasename = [&] {
|
||||||
if (!InSnap()) {
|
if (InSnap()) {
|
||||||
return qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME));
|
const auto snapNameKey =
|
||||||
|
qEnvironmentVariableIsSet("SNAP_INSTANCE_NAME")
|
||||||
|
? "SNAP_INSTANCE_NAME"
|
||||||
|
: "SNAP_NAME";
|
||||||
|
|
||||||
|
return qsl("%1_%2")
|
||||||
|
.arg(QString::fromLatin1(qgetenv(snapNameKey)))
|
||||||
|
.arg(cExeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto snapNameKey =
|
const auto possibleBasenames = std::vector<QString>{
|
||||||
qEnvironmentVariableIsSet("SNAP_INSTANCE_NAME")
|
qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)),
|
||||||
? "SNAP_INSTANCE_NAME"
|
qsl("Telegram")
|
||||||
: "SNAP_NAME";
|
};
|
||||||
|
|
||||||
const auto result = qsl("%1_%2")
|
for (const auto &it : possibleBasenames) {
|
||||||
.arg(QString::fromLatin1(qgetenv(snapNameKey)))
|
if (!QStandardPaths::locate(
|
||||||
.arg(cExeName());
|
QStandardPaths::ApplicationsLocation,
|
||||||
|
it + qsl(".desktop")).isEmpty()) {
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LOG(("SNAP Environment detected, launcher filename is %1.desktop")
|
return possibleBasenames[0];
|
||||||
.arg(result));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
LOG(("Launcher filename is %1.desktop").arg(LauncherBasename));
|
||||||
return LauncherBasename;
|
return LauncherBasename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue