Merge pull request #177 from atom/toast-app-name
Use AppUserModelID as app id
This commit is contained in:
commit
2468c7c34e
3 changed files with 19 additions and 6 deletions
|
@ -42,8 +42,7 @@ void NotificationPresenterWin::ShowNotification(
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
||||||
base::Closure* cancel_callback) {
|
base::Closure* cancel_callback) {
|
||||||
// This class manages itself.
|
// This class manages itself.
|
||||||
auto notification = new WindowsToastNotification(
|
auto notification = new WindowsToastNotification(delegate.Pass());
|
||||||
GetApplicationName(), delegate.Pass());
|
|
||||||
notification->ShowNotification(data.title, data.body, data.icon.spec());
|
notification->ShowNotification(data.title, data.body, data.icon.spec());
|
||||||
|
|
||||||
if (cancel_callback) {
|
if (cancel_callback) {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include "browser/win/windows_toast_notification.h"
|
#include "browser/win/windows_toast_notification.h"
|
||||||
|
|
||||||
|
#include <shlobj.h>
|
||||||
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "browser/win/scoped_hstring.h"
|
#include "browser/win/scoped_hstring.h"
|
||||||
#include "content/public/browser/desktop_notification_delegate.h"
|
#include "content/public/browser/desktop_notification_delegate.h"
|
||||||
|
@ -13,8 +15,21 @@ using namespace ABI::Windows::Data::Xml::Dom;
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool GetAppUserModelId(ScopedHString* app_id) {
|
||||||
|
PWSTR current_app_id;
|
||||||
|
if (FAILED(GetCurrentProcessExplicitAppUserModelID(¤t_app_id)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
app_id->Set(current_app_id);
|
||||||
|
CoTaskMemFree(current_app_id);
|
||||||
|
return app_id->success();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
WindowsToastNotification::WindowsToastNotification(
|
WindowsToastNotification::WindowsToastNotification(
|
||||||
const std::string& app_name,
|
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate)
|
scoped_ptr<content::DesktopNotificationDelegate> delegate)
|
||||||
: delegate_(delegate.Pass()),
|
: delegate_(delegate.Pass()),
|
||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
|
@ -30,8 +45,8 @@ WindowsToastNotification::WindowsToastNotification(
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ScopedHString app_id(base::UTF8ToUTF16(app_name).c_str());
|
ScopedHString app_id;
|
||||||
if (!app_id.success())
|
if (!GetAppUserModelId(&app_id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_);
|
toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_);
|
||||||
|
|
|
@ -34,7 +34,6 @@ using DesktopToastFailedEventHandler =
|
||||||
class WindowsToastNotification {
|
class WindowsToastNotification {
|
||||||
public:
|
public:
|
||||||
WindowsToastNotification(
|
WindowsToastNotification(
|
||||||
const std::string& app_name,
|
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate);
|
scoped_ptr<content::DesktopNotificationDelegate> delegate);
|
||||||
~WindowsToastNotification();
|
~WindowsToastNotification();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue