From ee674acca4ff51de2f4fa26b101ce81fe76ab959 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 5 Aug 2019 17:52:47 +0200 Subject: [PATCH] feat: add tray.removeBalloon() (#19547) --- docs/api/tray.md | 4 ++++ shell/browser/api/atom_api_tray.cc | 5 +++++ shell/browser/api/atom_api_tray.h | 1 + shell/browser/ui/tray_icon.cc | 2 ++ shell/browser/ui/tray_icon.h | 3 +++ shell/browser/ui/win/notify_icon.cc | 10 ++++++++++ shell/browser/ui/win/notify_icon.h | 1 + 7 files changed, 26 insertions(+) diff --git a/docs/api/tray.md b/docs/api/tray.md index c299f086d96..f50dcccbf92 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -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) diff --git a/shell/browser/api/atom_api_tray.cc b/shell/browser/api/atom_api_tray.cc index 9ef5a2b3ce9..27b6ae7698e 100644 --- a/shell/browser/api/atom_api_tray.cc +++ b/shell/browser/api/atom_api_tray.cc @@ -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; args->GetNext(&menu); @@ -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); diff --git a/shell/browser/api/atom_api_tray.h b/shell/browser/api/atom_api_tray.h index eafb27bf1f3..66ed3792b5d 100644 --- a/shell/browser/api/atom_api_tray.h +++ b/shell/browser/api/atom_api_tray.h @@ -73,6 +73,7 @@ class Tray : public mate::TrackableObject, 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); gfx::Rect GetBounds(); diff --git a/shell/browser/ui/tray_icon.cc b/shell/browser/ui/tray_icon.cc index 70db482fb8c..21bb4c93922 100644 --- a/shell/browser/ui/tray_icon.cc +++ b/shell/browser/ui/tray_icon.cc @@ -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) {} diff --git a/shell/browser/ui/tray_icon.h b/shell/browser/ui/tray_icon.h index b062d70c2f0..beacde40776 100644 --- a/shell/browser/ui/tray_icon.h +++ b/shell/browser/ui/tray_icon.h @@ -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); diff --git a/shell/browser/ui/win/notify_icon.cc b/shell/browser/ui/win/notify_icon.cc index dd9d5f6891a..76987d5783a 100644 --- a/shell/browser/ui/win/notify_icon.cc +++ b/shell/browser/ui/win/notify_icon.cc @@ -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. diff --git a/shell/browser/ui/win/notify_icon.h b/shell/browser/ui/win/notify_icon.h index 6c71034f15e..bcc5b8138bf 100644 --- a/shell/browser/ui/win/notify_icon.h +++ b/shell/browser/ui/win/notify_icon.h @@ -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;