Set NIF_GUID if we have a GUID

This commit is contained in:
Paul Betts 2015-07-24 08:02:14 -07:00
parent 70feb08f84
commit 5e61974c24
2 changed files with 13 additions and 8 deletions

View file

@ -40,13 +40,14 @@ NotifyIcon::NotifyIcon(NotifyIconHost* host,
base::MD5Sum(explicit_app_id, base::MD5Sum(explicit_app_id,
sizeof(wchar_t) * wcslen(explicit_app_id), sizeof(wchar_t) * wcslen(explicit_app_id),
(base::MD5Digest*)&tray_app_id_hash_); (base::MD5Digest*)&tray_app_id_hash_);
has_tray_app_id_hash_ = true;
CoTaskMemFree(explicit_app_id); CoTaskMemFree(explicit_app_id);
} }
NOTIFYICONDATA icon_data; NOTIFYICONDATA icon_data;
InitIconData(&icon_data); InitIconData(&icon_data);
icon_data.uFlags = NIF_MESSAGE; icon_data.uFlags |= NIF_MESSAGE;
icon_data.uCallbackMessage = message_id_; icon_data.uCallbackMessage = message_id_;
BOOL result = Shell_NotifyIcon(NIM_ADD, &icon_data); BOOL result = Shell_NotifyIcon(NIM_ADD, &icon_data);
// This can happen if the explorer process isn't running when we try to // This can happen if the explorer process isn't running when we try to
@ -89,7 +90,7 @@ void NotifyIcon::ResetIcon() {
// Delete any previously existing icon. // Delete any previously existing icon.
Shell_NotifyIcon(NIM_DELETE, &icon_data); Shell_NotifyIcon(NIM_DELETE, &icon_data);
InitIconData(&icon_data); InitIconData(&icon_data);
icon_data.uFlags = NIF_MESSAGE; icon_data.uFlags |= NIF_MESSAGE;
icon_data.uCallbackMessage = message_id_; icon_data.uCallbackMessage = message_id_;
icon_data.hIcon = icon_.Get(); icon_data.hIcon = icon_.Get();
// If we have an image, then set the NIF_ICON flag, which tells // If we have an image, then set the NIF_ICON flag, which tells
@ -106,7 +107,7 @@ void NotifyIcon::SetImage(const gfx::Image& image) {
// Create the icon. // Create the icon.
NOTIFYICONDATA icon_data; NOTIFYICONDATA icon_data;
InitIconData(&icon_data); InitIconData(&icon_data);
icon_data.uFlags = NIF_ICON; icon_data.uFlags |= NIF_ICON;
icon_.Set(IconUtil::CreateHICONFromSkBitmap(image.AsBitmap())); icon_.Set(IconUtil::CreateHICONFromSkBitmap(image.AsBitmap()));
icon_data.hIcon = icon_.Get(); icon_data.hIcon = icon_.Get();
BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
@ -123,7 +124,7 @@ void NotifyIcon::SetToolTip(const std::string& tool_tip) {
// Create the icon. // Create the icon.
NOTIFYICONDATA icon_data; NOTIFYICONDATA icon_data;
InitIconData(&icon_data); InitIconData(&icon_data);
icon_data.uFlags = NIF_TIP; icon_data.uFlags |= NIF_TIP;
wcscpy_s(icon_data.szTip, base::UTF8ToUTF16(tool_tip).c_str()); wcscpy_s(icon_data.szTip, base::UTF8ToUTF16(tool_tip).c_str());
BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data); BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
if (!result) if (!result)
@ -135,7 +136,7 @@ void NotifyIcon::DisplayBalloon(const gfx::Image& icon,
const base::string16& contents) { const base::string16& contents) {
NOTIFYICONDATA icon_data; NOTIFYICONDATA icon_data;
InitIconData(&icon_data); InitIconData(&icon_data);
icon_data.uFlags = NIF_INFO; icon_data.uFlags |= NIF_INFO;
icon_data.dwInfoFlags = NIIF_INFO; icon_data.dwInfoFlags = NIIF_INFO;
wcscpy_s(icon_data.szInfoTitle, title.c_str()); wcscpy_s(icon_data.szInfoTitle, title.c_str());
wcscpy_s(icon_data.szInfo, contents.c_str()); wcscpy_s(icon_data.szInfo, contents.c_str());
@ -180,9 +181,12 @@ void NotifyIcon::InitIconData(NOTIFYICONDATA* icon_data) {
icon_data->hWnd = window_; icon_data->hWnd = window_;
icon_data->uID = icon_id_; icon_data->uID = icon_id_;
if (has_tray_app_id_hash_) {
icon_data->uFlags |= NIF_GUID;
memcpy(reinterpret_cast<void*>(&icon_data->guidItem), memcpy(reinterpret_cast<void*>(&icon_data->guidItem),
&tray_app_id_hash_, &tray_app_id_hash_,
sizeof(GUID)); sizeof(GUID));
}
} }
} // namespace atom } // namespace atom

View file

@ -78,6 +78,7 @@ class NotifyIcon : public TrayIcon {
// A hash of the app model ID // A hash of the app model ID
GUID tray_app_id_hash_; GUID tray_app_id_hash_;
bool has_tray_app_id_hash_;
DISALLOW_COPY_AND_ASSIGN(NotifyIcon); DISALLOW_COPY_AND_ASSIGN(NotifyIcon);
}; };