Skip to content

Commit 92c35d3

Browse files
committed
[Notification][Win] fix for missing windows events, notification manager should be initialize by UI thread
1 parent 87186d8 commit 92c35d3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/nw_notification_manager_win.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ class TrayObserver : public StatusIconObserver {
7373
NotificationManagerWin* tray_;
7474
};
7575

76-
NotificationManagerWin::NotificationManagerWin() : status_icon_(NULL) {
76+
NotificationManagerWin::NotificationManagerWin() : status_icon_(NULL), status_tray_(NULL) {
77+
Init();
78+
}
79+
80+
bool NotificationManagerWin::Init() {
81+
if (!content::BrowserThread::CurrentlyOn(BrowserThread::UI))
82+
return false;
83+
7784
status_tray_ = static_cast<StatusTrayWin*>(StatusTray::GetSingleton());
7885

7986
// check if status icon is already created
@@ -85,6 +92,7 @@ NotificationManagerWin::NotificationManagerWin() : status_icon_(NULL) {
8592
status_observer_ = new TrayObserver(this);
8693
status_icon->AddObserver(status_observer_);
8794
}
95+
return true;
8896
}
8997

9098
bool NotificationManagerWin::ReleaseNotification() {
@@ -123,6 +131,8 @@ NotificationManagerWin::~NotificationManagerWin() {
123131

124132
bool NotificationManagerWin::AddDesktopNotification(const content::PlatformNotificationData& params,
125133
const int render_process_id, const int notification_id, const SkBitmap& bitmap_icon) {
134+
135+
if (status_tray_ == NULL) Init();
126136

127137
content::Shell* shell = content::Shell::windows()[0];
128138

src/nw_notification_manager_win.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class NotificationManagerWin : public NotificationManager {
4545
// variable to store the latest notification data, windows can only show 1 notification
4646
int render_process_id_, notification_id_;
4747

48+
bool Init();
49+
4850
// dispatch the events from the latest notification
4951
bool DesktopNotificationPostClick() {
5052
return NotificationManager::DesktopNotificationPostClick(render_process_id_, notification_id_);

0 commit comments

Comments
 (0)