Merge pull request #177 from atom/toast-app-name

Use AppUserModelID as app id
This commit is contained in:
Cheng Zhao 2015-11-20 13:32:22 +08:00
commit 2468c7c34e
3 changed files with 19 additions and 6 deletions

View file

@ -42,8 +42,7 @@ void NotificationPresenterWin::ShowNotification(
scoped_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) {
// This class manages itself.
auto notification = new WindowsToastNotification(
GetApplicationName(), delegate.Pass());
auto notification = new WindowsToastNotification(delegate.Pass());
notification->ShowNotification(data.title, data.body, data.icon.spec());
if (cancel_callback) {

View file

@ -5,6 +5,8 @@
#include "browser/win/windows_toast_notification.h"
#include <shlobj.h>
#include "base/strings/utf_string_conversions.h"
#include "browser/win/scoped_hstring.h"
#include "content/public/browser/desktop_notification_delegate.h"
@ -13,8 +15,21 @@ using namespace ABI::Windows::Data::Xml::Dom;
namespace brightray {
namespace {
bool GetAppUserModelId(ScopedHString* app_id) {
PWSTR current_app_id;
if (FAILED(GetCurrentProcessExplicitAppUserModelID(&current_app_id)))
return false;
app_id->Set(current_app_id);
CoTaskMemFree(current_app_id);
return app_id->success();
}
} // namespace
WindowsToastNotification::WindowsToastNotification(
const std::string& app_name,
scoped_ptr<content::DesktopNotificationDelegate> delegate)
: delegate_(delegate.Pass()),
weak_factory_(this) {
@ -30,8 +45,8 @@ WindowsToastNotification::WindowsToastNotification(
if (FAILED(hr))
return;
ScopedHString app_id(base::UTF8ToUTF16(app_name).c_str());
if (!app_id.success())
ScopedHString app_id;
if (!GetAppUserModelId(&app_id))
return;
toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_);

View file

@ -34,7 +34,6 @@ using DesktopToastFailedEventHandler =
class WindowsToastNotification {
public:
WindowsToastNotification(
const std::string& app_name,
scoped_ptr<content::DesktopNotificationDelegate> delegate);
~WindowsToastNotification();