fix: icon in Windows toast notification (#48630)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-10-22 13:55:41 +02:00 committed by GitHub
commit c9c048196a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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

@ -302,6 +302,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));