Skip to content

Commit

Permalink
wip: get icon working... for png
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao committed Jul 24, 2019
1 parent c2d7888 commit d5fbbec
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions shell/browser/browser_win.cc
Expand Up @@ -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 {

Expand Down Expand Up @@ -374,18 +377,40 @@ void Browser::ShowAboutPanel() {
const auto& opts = about_panel_options_;
std::string aboutMessage = "";
const std::string* str;
std::vector<std::string> panelOptions = {
std::vector<std::string> 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<const unsigned char*>(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);
Expand Down

0 comments on commit d5fbbec

Please sign in to comment.