Skip to content

Commit

Permalink
feat: add tray.removeBalloon() (#19547)
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak authored and codebytere committed Aug 5, 2019
1 parent 8f043bb commit ee674ac
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/api/tray.md
Expand Up @@ -228,6 +228,10 @@ Returns `Boolean` - Whether double click events will be ignored.

Displays a tray balloon.

#### `tray.removeBalloon()` _Windows_

Removes a tray balloon.

#### `tray.popUpContextMenu([menu, position])` _macOS_ _Windows_

* `menu` Menu (optional)
Expand Down
5 changes: 5 additions & 0 deletions shell/browser/api/atom_api_tray.cc
Expand Up @@ -175,6 +175,10 @@ void Tray::DisplayBalloon(mate::Arguments* args,
#endif
}

void Tray::RemoveBalloon() {
tray_icon_->RemoveBalloon();
}

void Tray::PopUpContextMenu(mate::Arguments* args) {
mate::Handle<Menu> menu;
args->GetNext(&menu);
Expand Down Expand Up @@ -208,6 +212,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
.SetMethod("getIgnoreDoubleClickEvents",
&Tray::GetIgnoreDoubleClickEvents)
.SetMethod("displayBalloon", &Tray::DisplayBalloon)
.SetMethod("removeBalloon", &Tray::RemoveBalloon)
.SetMethod("popUpContextMenu", &Tray::PopUpContextMenu)
.SetMethod("setContextMenu", &Tray::SetContextMenu)
.SetMethod("getBounds", &Tray::GetBounds);
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/atom_api_tray.h
Expand Up @@ -73,6 +73,7 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
void SetIgnoreDoubleClickEvents(bool ignore);
bool GetIgnoreDoubleClickEvents();
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
void RemoveBalloon();
void PopUpContextMenu(mate::Arguments* args);
void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu);
gfx::Rect GetBounds();
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/ui/tray_icon.cc
Expand Up @@ -16,6 +16,8 @@ void TrayIcon::DisplayBalloon(ImageType icon,
const base::string16& title,
const base::string16& contents) {}

void TrayIcon::RemoveBalloon() {}

void TrayIcon::PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) {}

Expand Down
3 changes: 3 additions & 0 deletions shell/browser/ui/tray_icon.h
Expand Up @@ -55,6 +55,9 @@ class TrayIcon {
const base::string16& title,
const base::string16& contents);

// Removes the notification balloon.
virtual void RemoveBalloon();

// Popups the menu.
virtual void PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model);
Expand Down
10 changes: 10 additions & 0 deletions shell/browser/ui/win/notify_icon.cc
Expand Up @@ -138,6 +138,16 @@ void NotifyIcon::DisplayBalloon(HICON icon,
LOG(WARNING) << "Unable to create status tray balloon.";
}

void NotifyIcon::RemoveBalloon() {
NOTIFYICONDATA icon_data;
InitIconData(&icon_data);
icon_data.uFlags |= NIF_INFO;

BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
if (!result)
LOG(WARNING) << "Unable to remove status tray balloon.";
}

void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) {
// Returns if context menu isn't set.
Expand Down
1 change: 1 addition & 0 deletions shell/browser/ui/win/notify_icon.h
Expand Up @@ -61,6 +61,7 @@ class NotifyIcon : public TrayIcon {
void DisplayBalloon(HICON icon,
const base::string16& title,
const base::string16& contents) override;
void RemoveBalloon() override;
void PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) override;
void SetContextMenu(AtomMenuModel* menu_model) override;
Expand Down

0 comments on commit ee674ac

Please sign in to comment.