fix: taskbar app icon change after unpinning

This commit is contained in:
AlexeyZavar
2026-04-27 02:56:45 +03:00
parent 10092ba792
commit 370140143d
4 changed files with 54 additions and 9 deletions
+5 -1
View File
@@ -19,7 +19,11 @@ static QImage LAST_LOADED_PAD;
namespace AyuAssets {
QString appIcoPath() {
return cWorkingDir() + u"tdata/AyuGram.ico"_q;
const auto &settings = AyuSettings::getInstance();
return cWorkingDir()
+ u"tdata/AyuGram-"_q
+ settings.appIcon()
+ u".ico"_q;
}
void loadAppIco() {
@@ -139,16 +139,21 @@ void processNewShortcuts(const QString &iconPath) {
return;
}
const auto shortcut = path + u"AyuGram Desktop/AyuGram.lnk"_q;
const auto native = QDir::toNativeSeparators(path).toStdWString();
const auto shortcuts = {
path + u"AyuGram Desktop/AyuGram.lnk"_q,
path + u"AyuGram/AyuGram.lnk"_q,
path + u"AyuGram.lnk"_q,
};
for (const auto &shortcut : shortcuts) {
const auto native = QDir::toNativeSeparators(shortcut).toStdWString();
DWORD attributes = GetFileAttributes(native.c_str());
if (attributes >= 0xFFFFFFF) {
return; // file does not exist
DWORD attributes = GetFileAttributes(native.c_str());
if (attributes >= 0xFFFFFFF) {
continue;
}
processIcon(QString::fromStdWString(native), iconPath);
}
const auto normalizedPath = QString::fromStdWString(native);
processIcon(normalizedPath, iconPath);
}
void reloadAppIconFromTaskBar() {
@@ -49,6 +49,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// AyuGram includes
#include "ayu/ayu_settings.h"
#include "ayu/ui/ayu_logo.h"
#include "platform/win/windows_app_user_model_id.h"
#include <QtCore/QDir>
#include <propkey.h>
#include <propvarutil.h>
// Taken from qtbase/src/gui/image/qpixmap_win.cpp
@@ -108,6 +113,35 @@ private:
return nullptr;
}
void UpdateTaskbarRelaunchIcon(HWND hWnd) {
auto propertyStore = ComPtr<IPropertyStore>();
auto hr = SHGetPropertyStoreForWindow(
hWnd,
IID_PPV_ARGS(&propertyStore));
if (!SUCCEEDED(hr)) {
return;
}
const auto setString = [&](
const PROPERTYKEY &key,
const std::wstring &value) {
auto prop = PROPVARIANT();
hr = InitPropVariantFromString(value.c_str(), &prop);
if (!SUCCEEDED(hr)) {
return;
}
hr = propertyStore->SetValue(key, prop);
PropVariantClear(&prop);
};
setString(AppUserModelId::Key(), AppUserModelId::Id());
setString(
PKEY_AppUserModel_RelaunchIconResource,
QDir::toNativeSeparators(AyuAssets::appIcoPath()).toStdWString()
+ L",0");
propertyStore->Commit();
}
struct RealSize {
QSize value;
bool maximized = false;
@@ -616,6 +650,7 @@ void MainWindow::updateTaskbarAndIconCounters() {
GetSystemMetrics(SM_CXICON),
GetSystemMetrics(SM_CYICON));
const auto supportMode = session && session->supportMode();
UpdateTaskbarRelaunchIcon(_hWnd);
auto iconSmallPixmap16 = Tray::IconWithCounter(
Tray::CounterLayerArgs(16, counter, muted),
@@ -135,6 +135,7 @@ bool DarkTasbarValueValid/* = false*/;
static auto lastUsedIcon = AyuAssets::currentAppLogoName();
if (lastUsedIcon != AyuAssets::currentAppLogoName()) {
lastUsedIcon = AyuAssets::currentAppLogoName();
ScaledLogo = base::flat_map<int, QImage>();
ScaledLogoNoMargin = base::flat_map<int, QImage>();
ScaledLogoDark = base::flat_map<int, QImage>();