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:
parent
955afdd92b
commit
c9c048196a
2 changed files with 10 additions and 8 deletions
|
|
@ -30,9 +30,8 @@ namespace {
|
||||||
bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
|
bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) {
|
||||||
std::optional<std::vector<uint8_t>> png_data =
|
std::optional<std::vector<uint8_t>> png_data =
|
||||||
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false);
|
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false);
|
||||||
if (!png_data.has_value())
|
if (!png_data.has_value() || !png_data.value().size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return base::WriteFile(path, png_data.value());
|
return base::WriteFile(path, png_data.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,8 +63,10 @@ bool NotificationPresenterWin::Init() {
|
||||||
std::wstring NotificationPresenterWin::SaveIconToFilesystem(
|
std::wstring NotificationPresenterWin::SaveIconToFilesystem(
|
||||||
const SkBitmap& icon,
|
const SkBitmap& icon,
|
||||||
const GURL& origin) {
|
const GURL& origin) {
|
||||||
std::string filename;
|
if (icon.drawsNothing())
|
||||||
|
return L"";
|
||||||
|
|
||||||
|
std::string filename;
|
||||||
if (origin.is_valid()) {
|
if (origin.is_valid()) {
|
||||||
filename = base::MD5String(origin.spec()) + ".png";
|
filename = base::MD5String(origin.spec()) + ".png";
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -75,11 +76,11 @@ std::wstring NotificationPresenterWin::SaveIconToFilesystem(
|
||||||
|
|
||||||
ScopedAllowBlockingForElectron allow_blocking;
|
ScopedAllowBlockingForElectron allow_blocking;
|
||||||
base::FilePath path = temp_dir_.GetPath().Append(base::UTF8ToWide(filename));
|
base::FilePath path = temp_dir_.GetPath().Append(base::UTF8ToWide(filename));
|
||||||
if (base::PathExists(path))
|
|
||||||
return path.value();
|
if (!SaveIconToPath(icon, path))
|
||||||
if (SaveIconToPath(icon, path))
|
return L"";
|
||||||
return path.value();
|
|
||||||
return base::UTF8ToWide(origin.spec());
|
return path.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification* NotificationPresenterWin::CreateNotificationObject(
|
Notification* NotificationPresenterWin::CreateNotificationObject(
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,7 @@ std::u16string WindowsToastNotification::GetToastXml(
|
||||||
// Optional icon as app logo override (small icon).
|
// Optional icon as app logo override (small icon).
|
||||||
if (!icon_path.empty()) {
|
if (!icon_path.empty()) {
|
||||||
xml_writer.StartElement(kImage);
|
xml_writer.StartElement(kImage);
|
||||||
|
xml_writer.AddAttribute(kID, "1");
|
||||||
xml_writer.AddAttribute(kPlacement, kAppLogoOverride);
|
xml_writer.AddAttribute(kPlacement, kAppLogoOverride);
|
||||||
xml_writer.AddAttribute(kHintCrop, kHintCropNone);
|
xml_writer.AddAttribute(kHintCrop, kHintCropNone);
|
||||||
xml_writer.AddAttribute(kSrc, base::WideToUTF8(icon_path));
|
xml_writer.AddAttribute(kSrc, base::WideToUTF8(icon_path));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue