Skip to content

Commit ee674ac

Browse files
miniakcodebytere
authored andcommitted
feat: add tray.removeBalloon() (electron#19547)
1 parent 8f043bb commit ee674ac

File tree

7 files changed

+26
-0
lines changed

7 files changed

+26
-0
lines changed

docs/api/tray.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ Returns `Boolean` - Whether double click events will be ignored.
228228

229229
Displays a tray balloon.
230230

231+
#### `tray.removeBalloon()` _Windows_
232+
233+
Removes a tray balloon.
234+
231235
#### `tray.popUpContextMenu([menu, position])` _macOS_ _Windows_
232236

233237
* `menu` Menu (optional)

shell/browser/api/atom_api_tray.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ void Tray::DisplayBalloon(mate::Arguments* args,
175175
#endif
176176
}
177177

178+
void Tray::RemoveBalloon() {
179+
tray_icon_->RemoveBalloon();
180+
}
181+
178182
void Tray::PopUpContextMenu(mate::Arguments* args) {
179183
mate::Handle<Menu> menu;
180184
args->GetNext(&menu);
@@ -208,6 +212,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
208212
.SetMethod("getIgnoreDoubleClickEvents",
209213
&Tray::GetIgnoreDoubleClickEvents)
210214
.SetMethod("displayBalloon", &Tray::DisplayBalloon)
215+
.SetMethod("removeBalloon", &Tray::RemoveBalloon)
211216
.SetMethod("popUpContextMenu", &Tray::PopUpContextMenu)
212217
.SetMethod("setContextMenu", &Tray::SetContextMenu)
213218
.SetMethod("getBounds", &Tray::GetBounds);

shell/browser/api/atom_api_tray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
7373
void SetIgnoreDoubleClickEvents(bool ignore);
7474
bool GetIgnoreDoubleClickEvents();
7575
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
76+
void RemoveBalloon();
7677
void PopUpContextMenu(mate::Arguments* args);
7778
void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu);
7879
gfx::Rect GetBounds();

shell/browser/ui/tray_icon.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ void TrayIcon::DisplayBalloon(ImageType icon,
1616
const base::string16& title,
1717
const base::string16& contents) {}
1818

19+
void TrayIcon::RemoveBalloon() {}
20+
1921
void TrayIcon::PopUpContextMenu(const gfx::Point& pos,
2022
AtomMenuModel* menu_model) {}
2123

shell/browser/ui/tray_icon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class TrayIcon {
5555
const base::string16& title,
5656
const base::string16& contents);
5757

58+
// Removes the notification balloon.
59+
virtual void RemoveBalloon();
60+
5861
// Popups the menu.
5962
virtual void PopUpContextMenu(const gfx::Point& pos,
6063
AtomMenuModel* menu_model);

shell/browser/ui/win/notify_icon.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ void NotifyIcon::DisplayBalloon(HICON icon,
138138
LOG(WARNING) << "Unable to create status tray balloon.";
139139
}
140140

141+
void NotifyIcon::RemoveBalloon() {
142+
NOTIFYICONDATA icon_data;
143+
InitIconData(&icon_data);
144+
icon_data.uFlags |= NIF_INFO;
145+
146+
BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
147+
if (!result)
148+
LOG(WARNING) << "Unable to remove status tray balloon.";
149+
}
150+
141151
void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
142152
AtomMenuModel* menu_model) {
143153
// Returns if context menu isn't set.

shell/browser/ui/win/notify_icon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class NotifyIcon : public TrayIcon {
6161
void DisplayBalloon(HICON icon,
6262
const base::string16& title,
6363
const base::string16& contents) override;
64+
void RemoveBalloon() override;
6465
void PopUpContextMenu(const gfx::Point& pos,
6566
AtomMenuModel* menu_model) override;
6667
void SetContextMenu(AtomMenuModel* menu_model) override;

0 commit comments

Comments
 (0)