Skip to content

Commit eef671b

Browse files
committed
Set default window icon and set icon for nw.exe. Fix nwjs#221.
1 parent 3cbe8ce commit eef671b

6 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/browser/native_window.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "content/nw/src/common/shell_switches.h"
2525
#include "content/nw/src/nw_package.h"
2626
#include "content/nw/src/nw_shell.h"
27+
#include "grit/nw_resources.h"
28+
#include "ui/base/resource/resource_bundle.h"
2729
#include "ui/gfx/rect.h"
2830

2931
#if defined(OS_MACOSX)
@@ -67,7 +69,7 @@ NativeWindow::NativeWindow(content::Shell* shell,
6769
has_frame_(true) {
6870
manifest->GetBoolean(switches::kmFrame, &has_frame_);
6971

70-
LoadAppIconFromPackage();
72+
LoadAppIconFromPackage(manifest);
7173
}
7274

7375
NativeWindow::~NativeWindow() {
@@ -132,12 +134,17 @@ void NativeWindow::InitFromManifest(base::DictionaryValue* manifest) {
132134
Show();
133135
}
134136

135-
void NativeWindow::LoadAppIconFromPackage() {
136-
nw::Package* package = shell_->GetPackage();
137+
void NativeWindow::LoadAppIconFromPackage(base::DictionaryValue* manifest) {
137138
std::string path_string;
138-
if (package->window()->GetString(switches::kmIcon, &path_string))
139-
package->GetImage(FilePath::FromUTF8Unsafe(path_string),
140-
&app_icon_);
139+
if (manifest->GetString(switches::kmIcon, &path_string)) {
140+
// Read icon from "icon" field.
141+
shell_->GetPackage()->GetImage(FilePath::FromUTF8Unsafe(path_string),
142+
&app_icon_);
143+
} else {
144+
// Set default icon.
145+
app_icon_ = ui::ResourceBundle::GetSharedInstance().
146+
GetNativeImageNamed(IDR_NW_DEFAULT_ICON);
147+
}
141148
}
142149

143150
} // namespace nw

src/browser/native_window.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class NativeWindow {
120120
gfx::Image app_icon_;
121121

122122
private:
123-
void LoadAppIconFromPackage();
123+
void LoadAppIconFromPackage(base::DictionaryValue* manifest);
124124

125125
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
126126
};
22.1 KB
Loading

src/resources/nw.ico

9.44 KB
Binary file not shown.

src/resources/nw_resources.grd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<translations />
1212
<release seq="1">
1313
<structures fallback_to_low_resolution="true">
14+
<structure type="chrome_scaled_image" name="IDR_NW_DEFAULT_ICON" file="nw.png" />
1415
<structure type="chrome_scaled_image" name="IDR_NW_BACK" file="browser_back_normal.png" />
1516
<structure type="chrome_scaled_image" name="IDR_NW_BACK_D" file="browser_back_disabled.png" />
1617
<structure type="chrome_scaled_image" name="IDR_NW_BACK_H" file="browser_back_hover.png" />

src/shell.rc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,11 @@ END
124124

125125
/////////////////////////////////////////////////////////////////////////////
126126
#endif // not APSTUDIO_INVOKED
127+
128+
/////////////////////////////////////////////////////////////////////////////
129+
//
130+
// Icon
131+
//
132+
133+
IDR_MAINFRAME ICON "resources\\nw.ico"
134+
/////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)