From d5fbbecc03bc6e203117fee0ce458d13b783c832 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Wed, 24 Jul 2019 10:58:48 -0700 Subject: [PATCH] wip: get icon working... for png --- shell/browser/browser_win.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/shell/browser/browser_win.cc b/shell/browser/browser_win.cc index 399f7a60f6265..fb8ad7056236b 100644 --- a/shell/browser/browser_win.cc +++ b/shell/browser/browser_win.cc @@ -25,8 +25,11 @@ #include "shell/browser/ui/message_box.h" #include "shell/browser/ui/win/jump_list.h" #include "shell/common/application_info.h" +#include "shell/common/asar/asar_util.h" #include "shell/common/native_mate_converters/string16_converter.h" #include "ui/events/keycodes/keyboard_code_conversion_win.h" +#include "ui/gfx/codec/png_codec.h" +#include "ui/gfx/image/image_skia.h" namespace electron { @@ -374,18 +377,40 @@ void Browser::ShowAboutPanel() { const auto& opts = about_panel_options_; std::string aboutMessage = ""; const std::string* str; - std::vector panelOptions = { + std::vector stringOptions = { "applicationName", "applicationVersion", "copyright", "credits"}; - for (std::string opt : panelOptions) { + for (std::string opt : stringOptions) { if ((str = opts.FindStringKey(opt))) { aboutMessage.append(*str).append("\r\n"); } } + gfx::ImageSkia image; + if ((str = opts.FindStringKey("iconPath"))) { + base::FilePath path = base::FilePath::FromUTF8Unsafe(*str); + std::string file_contents; + double scale_factor = 1.0; + { + base::ThreadRestrictions::ScopedAllowIO allow_io; + if (!asar::ReadFileToString(path, &file_contents)) + return; + } + const unsigned char* data = + reinterpret_cast(file_contents.data()); + size_t size = file_contents.size(); + SkBitmap bitmap; + if (!gfx::PNGCodec::Decode(data, size, &bitmap)) + return; + gfx::ImageSkiaRep rep(bitmap, scale_factor); + image.AddRepresentation(rep); + } + electron::MessageBoxSettings settings = {}; settings.title = "About"; settings.message = aboutMessage; + settings.icon = image; + settings.type = electron::MessageBoxType::kInformation; // TODO(erickzhao): make asynchronous to avoid blocking js code // TODO(erickzhao): add icon (?) electron::ShowMessageBoxSync(settings);