fix: icon in Windows toast notification (#48543)

This commit is contained in:
Shelley Vohr
2025-10-21 21:12:26 +02:00
committed by GitHub
parent 7ec0ebc50a
commit f784ea6f4f
2 changed files with 10 additions and 8 deletions

View File

@@ -30,9 +30,8 @@ namespace {
bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
std::optional<std::vector<uint8_t>> png_data =
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false);
if (!png_data.has_value())
if (!png_data.has_value() || !png_data.value().size())
return false;
return base::WriteFile(path, png_data.value());
}
@@ -64,8 +63,10 @@ bool NotificationPresenterWin::Init() {
std::wstring NotificationPresenterWin::SaveIconToFilesystem(
const SkBitmap& icon,
const GURL& origin) {
std::string filename;
if (icon.drawsNothing())
return L"";
std::string filename;
if (origin.is_valid()) {
filename = base::MD5String(origin.spec()) + ".png";
} else {
@@ -75,11 +76,11 @@ std::wstring NotificationPresenterWin::SaveIconToFilesystem(
ScopedAllowBlockingForElectron allow_blocking;
base::FilePath path = temp_dir_.GetPath().Append(base::UTF8ToWide(filename));
if (base::PathExists(path))
return path.value();
if (SaveIconToPath(icon, path))
return path.value();
return base::UTF8ToWide(origin.spec());
if (!SaveIconToPath(icon, path))
return L"";
return path.value();
}
Notification* NotificationPresenterWin::CreateNotificationObject(

View File

@@ -353,6 +353,7 @@ std::u16string WindowsToastNotification::GetToastXml(
// Optional icon as app logo override (small icon).
if (!icon_path.empty()) {
xml_writer.StartElement(kImage);
xml_writer.AddAttribute(kID, "1");
xml_writer.AddAttribute(kPlacement, kAppLogoOverride);
xml_writer.AddAttribute(kHintCrop, kHintCropNone);
xml_writer.AddAttribute(kSrc, base::WideToUTF8(icon_path));