From 08383a69cea60db3d87fbe9842d21ffe0c4ef753 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 24 Jul 2015 03:10:03 -0700 Subject: [PATCH] Propagate User App Model ID to Tray Icon This PR prevents dozens of items showing up in the notification area preferences when using Squirrel for Windows, by ensuring that notification tray items are tied to the User App Model ID. --- atom/browser/ui/win/notify_icon.cc | 16 ++++++++++++++++ atom/browser/ui/win/notify_icon.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index bc9ff46f939a..6f75bb311dae 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -4,7 +4,10 @@ #include "atom/browser/ui/win/notify_icon.h" +#include + #include "atom/browser/ui/win/notify_icon_host.h" +#include "base/md5.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/win/windows_version.h" @@ -26,6 +29,18 @@ NotifyIcon::NotifyIcon(NotifyIconHost* host, window_(window), message_id_(message), menu_model_(NULL) { + + // NB: If we have an App Model ID, we should propagate that to the tray. + // Doing this prevents duplicate items from showing up in the notification + // preferences (i.e. "Always Show / Show notifications only / etc") + PWSTR explicit_app_id; + + if (SUCCEEDED(GetCurrentProcessExplicitAppUserModelID(&explicit_app_id))) { + // GUIDs and MD5 hashes are the same length. So convenient! + MD5Sum(explicit_app_id, sizeof(wchar_t) * wcslen(explicit_app_id), (MD5Digest*)&tray_app_id_hash_); + CoTaskMemFree(explicit_app_id); + } + NOTIFYICONDATA icon_data; InitIconData(&icon_data); icon_data.uFlags = NIF_MESSAGE; @@ -161,6 +176,7 @@ void NotifyIcon::InitIconData(NOTIFYICONDATA* icon_data) { icon_data->cbSize = sizeof(NOTIFYICONDATA); icon_data->hWnd = window_; icon_data->uID = icon_id_; + memcpy(icon_data->guidItem, tray_app_id_hash_, sizeof(GUID)); } } // namespace atom diff --git a/atom/browser/ui/win/notify_icon.h b/atom/browser/ui/win/notify_icon.h index 8e00f1267920..56b4b4f09be8 100644 --- a/atom/browser/ui/win/notify_icon.h +++ b/atom/browser/ui/win/notify_icon.h @@ -75,6 +75,9 @@ class NotifyIcon : public TrayIcon { // The context menu. ui::SimpleMenuModel* menu_model_; + + // A hash of the app model ID + GUID tray_app_id_hash_; DISALLOW_COPY_AND_ASSIGN(NotifyIcon); };