Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tray.focus() #19548

Merged
merged 1 commit into from Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api/tray.md
Expand Up @@ -232,6 +232,13 @@ Displays a tray balloon.

Removes a tray balloon.

#### `tray.focus()` _Windows_

Returns focus to the taskbar notification area.
Notification area icons should use this message when they have completed their UI operation.
For example, if the icon displays a shortcut menu, but the user presses ESC to cancel it,
use `tray.focus()` to return focus to the notification area.

#### `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 @@ -179,6 +179,10 @@ void Tray::RemoveBalloon() {
tray_icon_->RemoveBalloon();
}

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

void Tray::PopUpContextMenu(mate::Arguments* args) {
mate::Handle<Menu> menu;
args->GetNext(&menu);
Expand Down Expand Up @@ -213,6 +217,7 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
&Tray::GetIgnoreDoubleClickEvents)
.SetMethod("displayBalloon", &Tray::DisplayBalloon)
.SetMethod("removeBalloon", &Tray::RemoveBalloon)
.SetMethod("focus", &Tray::Focus)
.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 @@ -74,6 +74,7 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
bool GetIgnoreDoubleClickEvents();
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
void RemoveBalloon();
void Focus();
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 @@ -18,6 +18,8 @@ void TrayIcon::DisplayBalloon(ImageType icon,

void TrayIcon::RemoveBalloon() {}

void TrayIcon::Focus() {}

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 @@ -58,6 +58,9 @@ class TrayIcon {
// Removes the notification balloon.
virtual void RemoveBalloon();

// Returns focus to the taskbar notification area.
virtual void Focus();

// Popups the menu.
virtual void PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model);
Expand Down
9 changes: 9 additions & 0 deletions shell/browser/ui/win/notify_icon.cc
Expand Up @@ -148,6 +148,15 @@ void NotifyIcon::RemoveBalloon() {
LOG(WARNING) << "Unable to remove status tray balloon.";
}

void NotifyIcon::Focus() {
NOTIFYICONDATA icon_data;
InitIconData(&icon_data);

BOOL result = Shell_NotifyIcon(NIM_SETFOCUS, &icon_data);
if (!result)
LOG(WARNING) << "Unable to focus tray icon.";
}

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 @@ -62,6 +62,7 @@ class NotifyIcon : public TrayIcon {
const base::string16& title,
const base::string16& contents) override;
void RemoveBalloon() override;
void Focus() override;
void PopUpContextMenu(const gfx::Point& pos,
AtomMenuModel* menu_model) override;
void SetContextMenu(AtomMenuModel* menu_model) override;
Expand Down