Unified function to detect icon name on Linux

This commit is contained in:
Ilya Fedin 2020-02-26 15:38:31 +04:00 committed by John Preston
parent 3b300f23e1
commit 7bd0598555
5 changed files with 17 additions and 13 deletions

View File

@ -31,7 +31,6 @@ namespace Platform {
namespace {
constexpr auto kDisableTrayCounter = "TDESKTOP_DISABLE_TRAY_COUNTER"_cs;
constexpr auto kTrayIconName = "telegram"_cs;
constexpr auto kPanelTrayIconName = "telegram-panel"_cs;
constexpr auto kMutePanelTrayIconName = "telegram-mute-panel"_cs;
constexpr auto kAttentionPanelTrayIconName = "telegram-attention-panel"_cs;
@ -56,18 +55,13 @@ QString GetPanelIconName() {
}
QString GetTrayIconName() {
const auto iconName = GetIconName();
const auto panelIconName = GetPanelIconName();
if (QIcon::hasThemeIcon(panelIconName)) {
return panelIconName;
} else if (InSandbox()) {
const auto launcherBasename = GetLauncherBasename();
if (QIcon::hasThemeIcon(launcherBasename)) {
return launcherBasename;
}
} else if (QIcon::hasThemeIcon(kTrayIconName.utf16())) {
return kTrayIconName.utf16();
} else if (QIcon::hasThemeIcon(iconName)) {
return iconName;
}
return QString();

View File

@ -200,7 +200,7 @@ NotificationData::NotificationData(
bool NotificationData::show() {
const auto iconName = _imageKey.isEmpty() || !_hints.contains(_imageKey)
? qsl("telegram")
? GetIconName()
: QString();
const QDBusReply<uint> notifyReply = _notificationInterface->call(

View File

@ -44,6 +44,7 @@ namespace {
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
constexpr auto kSnapLauncherDir = "/var/lib/snapd/desktop/applications/"_cs;
constexpr auto kIconName = "telegram"_cs;
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
void SandboxAutostart(bool autostart, bool silent = false) {
@ -333,6 +334,13 @@ QString GetLauncherFilename() {
return LauncherFilename;
}
QString GetIconName() {
static const auto IconName = InSandbox()
? GetLauncherBasename()
: kIconName.utf16();
return IconName;
}
} // namespace Platform
namespace {

View File

@ -35,6 +35,8 @@ QString SingleInstanceLocalServerName(const QString &hash);
QString GetLauncherBasename();
QString GetLauncherFilename();
QString GetIconName();
inline std::optional<crl::time> LastUserInputTime() {
return std::nullopt;
}

View File

@ -117,9 +117,9 @@ QIcon CreateOfficialIcon(Main::Account *account) {
QIcon CreateIcon(Main::Account *account) {
auto result = CreateOfficialIcon(account);
if (Platform::IsLinux()) {
return QIcon::fromTheme("telegram", result);
}
#ifdef Q_OS_LINUX
return QIcon::fromTheme(Platform::GetIconName(), result);
#endif
return result;
}