mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
fix: icon in Windows toast notification (#48543)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user