2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-05-30 02:31:27 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/tray_icon_cocoa.h"
|
2014-05-30 02:31:27 +00:00
|
|
|
|
2019-05-02 12:05:37 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-08-24 01:14:23 +00:00
|
|
|
#include "base/message_loop/message_loop_current.h"
|
2019-07-31 17:52:50 +00:00
|
|
|
#include "base/message_loop/message_pump_mac.h"
|
2014-05-30 06:37:53 +00:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2019-06-25 02:30:26 +00:00
|
|
|
#include "base/task/post_task.h"
|
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/cocoa/NSString+ANSI.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/ui/cocoa/electron_menu_controller.h"
|
2015-07-29 04:01:27 +00:00
|
|
|
#include "ui/events/cocoa/cocoa_event_utils.h"
|
2016-06-21 06:40:30 +00:00
|
|
|
#include "ui/gfx/mac/coordinate_conversion.h"
|
2019-07-17 00:06:32 +00:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
2014-05-30 06:37:53 +00:00
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
@interface StatusItemView : NSView {
|
2020-02-04 20:19:40 +00:00
|
|
|
electron::TrayIconCocoa* trayIcon_; // weak
|
|
|
|
ElectronMenuController* menuController_; // weak
|
2018-04-02 01:07:26 +00:00
|
|
|
BOOL ignoreDoubleClickEvents_;
|
2015-07-15 10:26:39 +00:00
|
|
|
base::scoped_nsobject<NSStatusItem> statusItem_;
|
2017-11-29 07:10:43 +00:00
|
|
|
base::scoped_nsobject<NSTrackingArea> trackingArea_;
|
2014-06-02 03:28:23 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
@end // @interface StatusItemView
|
2014-06-02 03:28:23 +00:00
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
@implementation StatusItemView
|
2014-06-02 03:28:23 +00:00
|
|
|
|
2018-08-28 17:45:24 +00:00
|
|
|
- (void)dealloc {
|
|
|
|
trayIcon_ = nil;
|
|
|
|
menuController_ = nil;
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
- (id)initWithIcon:(electron::TrayIconCocoa*)icon {
|
2014-06-02 03:28:23 +00:00
|
|
|
trayIcon_ = icon;
|
2018-08-28 17:45:24 +00:00
|
|
|
menuController_ = nil;
|
2018-04-02 01:07:26 +00:00
|
|
|
ignoreDoubleClickEvents_ = NO;
|
2015-07-30 03:57:34 +00:00
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
if ((self = [super initWithFrame:CGRectZero])) {
|
|
|
|
[self registerForDraggedTypes:@[
|
2016-07-14 17:21:39 +00:00
|
|
|
NSFilenamesPboardType,
|
|
|
|
NSStringPboardType,
|
|
|
|
]];
|
2015-07-30 03:57:34 +00:00
|
|
|
|
|
|
|
// Create the status item.
|
2018-04-20 18:47:04 +00:00
|
|
|
NSStatusItem* item = [[NSStatusBar systemStatusBar]
|
|
|
|
statusItemWithLength:NSVariableStatusItemLength];
|
2015-11-17 21:43:55 +00:00
|
|
|
statusItem_.reset([item retain]);
|
2019-07-31 17:52:50 +00:00
|
|
|
[[statusItem_ button] addSubview:self]; // inject custom view
|
2015-11-17 21:43:55 +00:00
|
|
|
[self updateDimensions];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
2014-06-02 03:28:23 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-11-17 21:43:55 +00:00
|
|
|
- (void)updateDimensions {
|
2019-07-31 17:52:50 +00:00
|
|
|
[self setFrame:[statusItem_ button].frame];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateTrackingAreas {
|
|
|
|
// Use NSTrackingArea for listening to mouseEnter, mouseExit, and mouseMove
|
|
|
|
// events.
|
|
|
|
[self removeTrackingArea:trackingArea_];
|
|
|
|
trackingArea_.reset([[NSTrackingArea alloc]
|
|
|
|
initWithRect:[self bounds]
|
|
|
|
options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
|
|
|
|
NSTrackingActiveAlways
|
|
|
|
owner:self
|
|
|
|
userInfo:nil]);
|
|
|
|
[self addTrackingArea:trackingArea_];
|
2015-11-17 21:43:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 10:26:39 +00:00
|
|
|
- (void)removeItem {
|
2019-07-31 17:52:50 +00:00
|
|
|
// Turn off tracking events to prevent crash.
|
2017-11-29 07:10:43 +00:00
|
|
|
if (trackingArea_) {
|
|
|
|
[self removeTrackingArea:trackingArea_];
|
|
|
|
trackingArea_.reset();
|
|
|
|
}
|
2015-07-15 10:26:39 +00:00
|
|
|
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem_];
|
2019-07-31 17:52:50 +00:00
|
|
|
[self removeFromSuperview];
|
2015-07-15 10:26:39 +00:00
|
|
|
statusItem_.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setImage:(NSImage*)image {
|
2019-11-02 22:14:44 +00:00
|
|
|
[[statusItem_ button] setImage:image];
|
2015-11-17 21:43:55 +00:00
|
|
|
[self updateDimensions];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlternateImage:(NSImage*)image {
|
2019-11-02 22:14:44 +00:00
|
|
|
[[statusItem_ button] setAlternateImage:image];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
2018-05-03 07:43:46 +00:00
|
|
|
- (void)setIgnoreDoubleClickEvents:(BOOL)ignore {
|
2018-04-02 01:07:26 +00:00
|
|
|
ignoreDoubleClickEvents_ = ignore;
|
|
|
|
}
|
|
|
|
|
2018-05-03 07:43:46 +00:00
|
|
|
- (BOOL)getIgnoreDoubleClickEvents {
|
|
|
|
return ignoreDoubleClickEvents_;
|
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (void)setTitle:(NSString*)title {
|
2019-07-31 17:52:50 +00:00
|
|
|
if ([title containsANSICodes]) {
|
|
|
|
[[statusItem_ button]
|
|
|
|
setAttributedTitle:[title attributedStringParsingANSICodes]];
|
|
|
|
} else {
|
2019-11-02 22:14:44 +00:00
|
|
|
[[statusItem_ button] setTitle:title];
|
2019-07-31 17:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fix icon margins.
|
2015-11-17 21:43:55 +00:00
|
|
|
if (title.length > 0) {
|
2019-07-31 17:52:50 +00:00
|
|
|
[[statusItem_ button] setImagePosition:NSImageLeft];
|
2015-11-17 21:43:55 +00:00
|
|
|
} else {
|
2019-07-31 17:52:50 +00:00
|
|
|
[[statusItem_ button] setImagePosition:NSImageOnly];
|
2015-11-17 21:43:55 +00:00
|
|
|
}
|
2019-07-31 17:52:50 +00:00
|
|
|
|
2015-11-17 21:43:55 +00:00
|
|
|
[self updateDimensions];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 19:40:34 +00:00
|
|
|
- (NSString*)title {
|
2019-07-31 17:52:50 +00:00
|
|
|
return [statusItem_ button].title;
|
2017-11-09 22:21:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
- (void)setMenuController:(ElectronMenuController*)menu {
|
2015-07-16 02:49:55 +00:00
|
|
|
menuController_ = menu;
|
2019-07-31 17:52:50 +00:00
|
|
|
[statusItem_ setMenu:[menuController_ menu]];
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (void)mouseDown:(NSEvent*)event {
|
2020-01-17 16:28:34 +00:00
|
|
|
trayIcon_->NotifyMouseDown(
|
|
|
|
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
|
|
|
|
2019-07-31 17:52:50 +00:00
|
|
|
// Pass click to superclass to show menu. Custom mouseUp handler won't be
|
|
|
|
// invoked.
|
|
|
|
if (menuController_) {
|
|
|
|
[super mouseDown:event];
|
|
|
|
} else {
|
|
|
|
[[statusItem_ button] highlight:YES];
|
|
|
|
}
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 10:36:45 +00:00
|
|
|
- (void)mouseUp:(NSEvent*)event {
|
2019-07-31 17:52:50 +00:00
|
|
|
[[statusItem_ button] highlight:NO];
|
2015-07-15 10:26:39 +00:00
|
|
|
|
2020-01-17 16:28:34 +00:00
|
|
|
trayIcon_->NotifyMouseUp(
|
|
|
|
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
|
|
|
|
2018-04-02 01:07:26 +00:00
|
|
|
// If we are ignoring double click events, we should ignore the `clickCount`
|
|
|
|
// value and immediately emit a click event.
|
2018-05-21 22:18:38 +00:00
|
|
|
BOOL shouldBeHandledAsASingleClick =
|
|
|
|
(event.clickCount == 1) || ignoreDoubleClickEvents_;
|
2018-04-29 03:07:32 +00:00
|
|
|
if (shouldBeHandledAsASingleClick)
|
2015-07-29 04:01:27 +00:00
|
|
|
trayIcon_->NotifyClicked(
|
2016-06-21 06:40:30 +00:00
|
|
|
gfx::ScreenRectFromNSRect(event.window.frame),
|
2017-10-05 02:49:26 +00:00
|
|
|
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
2015-07-29 04:01:27 +00:00
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2015-07-15 10:26:39 +00:00
|
|
|
|
2015-08-10 04:18:00 +00:00
|
|
|
// Double click event.
|
2018-05-21 22:18:38 +00:00
|
|
|
BOOL shouldBeHandledAsADoubleClick =
|
|
|
|
(event.clickCount == 2) && !ignoreDoubleClickEvents_;
|
2018-04-29 03:07:32 +00:00
|
|
|
if (shouldBeHandledAsADoubleClick)
|
2015-07-29 04:01:27 +00:00
|
|
|
trayIcon_->NotifyDoubleClicked(
|
2016-06-21 06:40:30 +00:00
|
|
|
gfx::ScreenRectFromNSRect(event.window.frame),
|
2015-07-29 04:01:27 +00:00
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2015-07-15 10:26:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
- (void)popUpContextMenu:(electron::ElectronMenuModel*)menu_model {
|
2019-06-26 17:18:53 +00:00
|
|
|
// Make sure events can be pumped while the menu is up.
|
2019-06-25 02:30:26 +00:00
|
|
|
base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
|
2019-06-26 17:18:53 +00:00
|
|
|
|
2015-12-02 11:05:22 +00:00
|
|
|
// Show a custom menu.
|
|
|
|
if (menu_model) {
|
2020-02-04 20:19:40 +00:00
|
|
|
base::scoped_nsobject<ElectronMenuController> menuController(
|
|
|
|
[[ElectronMenuController alloc] initWithModel:menu_model
|
|
|
|
useDefaultAccelerator:NO]);
|
2019-07-31 17:52:50 +00:00
|
|
|
// Hacky way to mimic design of ordinary tray menu.
|
|
|
|
[statusItem_ setMenu:[menuController menu]];
|
2020-03-27 01:30:21 +00:00
|
|
|
// -performClick: is a blocking call, which will run the task loop inside
|
|
|
|
// itself. This can potentially include running JS, which can result in
|
|
|
|
// this object being released. We take a temporary reference here to make
|
|
|
|
// sure we stay alive long enough to successfully return from this
|
|
|
|
// function.
|
|
|
|
// TODO(nornagon/codebytere): Avoid nesting task loops here.
|
|
|
|
[self retain];
|
2019-07-31 17:52:50 +00:00
|
|
|
[[statusItem_ button] performClick:self];
|
|
|
|
[statusItem_ setMenu:[menuController_ menu]];
|
2020-03-27 01:30:21 +00:00
|
|
|
[self release];
|
2015-12-02 11:05:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-16 02:50:53 +00:00
|
|
|
if (menuController_ && ![menuController_ isMenuOpen]) {
|
2019-06-28 15:24:54 +00:00
|
|
|
// Ensure the UI can update while the menu is fading out.
|
|
|
|
base::ScopedPumpMessagesInPrivateModes pump_private;
|
|
|
|
|
2019-07-31 17:52:50 +00:00
|
|
|
[[statusItem_ button] performClick:self];
|
2015-07-16 02:50:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:25:17 +00:00
|
|
|
- (void)closeContextMenu {
|
|
|
|
if (menuController_) {
|
|
|
|
[menuController_ cancel];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:23:12 +00:00
|
|
|
- (void)rightMouseUp:(NSEvent*)event {
|
2015-07-29 04:01:27 +00:00
|
|
|
trayIcon_->NotifyRightClicked(
|
2016-06-21 06:40:30 +00:00
|
|
|
gfx::ScreenRectFromNSRect(event.window.frame),
|
2015-07-29 04:01:27 +00:00
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2015-07-15 11:23:12 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
2015-11-06 00:45:43 +00:00
|
|
|
trayIcon_->NotifyDragEntered();
|
2015-07-19 04:12:28 +00:00
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
|
2017-06-14 22:00:29 +00:00
|
|
|
- (void)mouseExited:(NSEvent*)event {
|
2017-06-28 19:09:12 +00:00
|
|
|
trayIcon_->NotifyMouseExited(
|
|
|
|
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2017-06-14 22:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent*)event {
|
2017-06-28 19:09:12 +00:00
|
|
|
trayIcon_->NotifyMouseEntered(
|
|
|
|
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
2017-06-14 22:00:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-26 18:04:58 +00:00
|
|
|
- (void)mouseMoved:(NSEvent*)event {
|
|
|
|
trayIcon_->NotifyMouseMoved(
|
|
|
|
gfx::ScreenPointFromNSPoint([event locationInWindow]),
|
|
|
|
ui::EventFlagsFromModifiers([event modifierFlags]));
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
- (void)draggingExited:(id<NSDraggingInfo>)sender {
|
2015-11-06 00:45:43 +00:00
|
|
|
trayIcon_->NotifyDragExited();
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
- (void)draggingEnded:(id<NSDraggingInfo>)sender {
|
2015-11-10 16:02:50 +00:00
|
|
|
trayIcon_->NotifyDragEnded();
|
|
|
|
|
2015-12-29 09:25:21 +00:00
|
|
|
if (NSPointInRect([sender draggingLocation], self.frame)) {
|
|
|
|
trayIcon_->NotifyDrop();
|
|
|
|
}
|
2015-11-10 16:02:50 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
- (BOOL)handleDrop:(id<NSDraggingInfo>)sender {
|
2015-07-19 04:12:28 +00:00
|
|
|
NSPasteboard* pboard = [sender draggingPasteboard];
|
|
|
|
|
|
|
|
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
|
|
|
|
std::vector<std::string> dropFiles;
|
|
|
|
NSArray* files = [pboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
for (NSString* file in files)
|
|
|
|
dropFiles.push_back(base::SysNSStringToUTF8(file));
|
2015-10-18 05:32:13 +00:00
|
|
|
trayIcon_->NotifyDropFiles(dropFiles);
|
2015-07-19 04:12:28 +00:00
|
|
|
return YES;
|
2016-07-14 17:21:39 +00:00
|
|
|
} else if ([[pboard types] containsObject:NSStringPboardType]) {
|
|
|
|
NSString* dropText = [pboard stringForType:NSStringPboardType];
|
|
|
|
trayIcon_->NotifyDropText(base::SysNSStringToUTF8(dropText));
|
|
|
|
return YES;
|
2015-07-19 04:12:28 +00:00
|
|
|
}
|
2016-07-14 17:21:39 +00:00
|
|
|
|
2015-07-19 04:12:28 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
|
2015-12-29 09:25:21 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:47:04 +00:00
|
|
|
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
|
2016-11-20 05:18:24 +00:00
|
|
|
[self handleDrop:sender];
|
2015-12-29 09:25:21 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2014-06-02 03:28:23 +00:00
|
|
|
@end
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2014-05-30 02:31:27 +00:00
|
|
|
|
2019-06-26 17:18:53 +00:00
|
|
|
TrayIconCocoa::TrayIconCocoa() : weak_factory_(this) {
|
2018-08-30 09:16:56 +00:00
|
|
|
status_item_view_.reset([[StatusItemView alloc] initWithIcon:this]);
|
|
|
|
}
|
2014-05-30 02:31:27 +00:00
|
|
|
|
|
|
|
TrayIconCocoa::~TrayIconCocoa() {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ removeItem];
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:43:56 +00:00
|
|
|
void TrayIconCocoa::SetImage(const gfx::Image& image) {
|
2019-07-31 17:52:50 +00:00
|
|
|
[status_item_view_ setImage:image.AsNSImage()];
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:43:56 +00:00
|
|
|
void TrayIconCocoa::SetPressedImage(const gfx::Image& image) {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setAlternateImage:image.AsNSImage()];
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrayIconCocoa::SetToolTip(const std::string& tool_tip) {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setToolTip:base::SysUTF8ToNSString(tool_tip)];
|
2014-05-30 06:37:53 +00:00
|
|
|
}
|
|
|
|
|
2014-09-09 11:33:58 +00:00
|
|
|
void TrayIconCocoa::SetTitle(const std::string& title) {
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setTitle:base::SysUTF8ToNSString(title)];
|
2014-09-09 11:33:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 19:40:34 +00:00
|
|
|
std::string TrayIconCocoa::GetTitle() {
|
|
|
|
return base::SysNSStringToUTF8([status_item_view_ title]);
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:07:26 +00:00
|
|
|
void TrayIconCocoa::SetIgnoreDoubleClickEvents(bool ignore) {
|
|
|
|
[status_item_view_ setIgnoreDoubleClickEvents:ignore];
|
|
|
|
}
|
|
|
|
|
2018-05-03 07:43:46 +00:00
|
|
|
bool TrayIconCocoa::GetIgnoreDoubleClickEvents() {
|
|
|
|
return [status_item_view_ getIgnoreDoubleClickEvents];
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void TrayIconCocoa::PopUpOnUI(ElectronMenuModel* menu_model) {
|
2019-06-26 17:18:53 +00:00
|
|
|
[status_item_view_ popUpContextMenu:menu_model];
|
2019-06-25 02:30:26 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 10:43:11 +00:00
|
|
|
void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronMenuModel* menu_model) {
|
2019-09-18 19:58:00 +00:00
|
|
|
base::PostTask(
|
2019-06-25 02:30:26 +00:00
|
|
|
FROM_HERE, {content::BrowserThread::UI},
|
2019-06-26 17:18:53 +00:00
|
|
|
base::BindOnce(&TrayIconCocoa::PopUpOnUI, weak_factory_.GetWeakPtr(),
|
|
|
|
base::Unretained(menu_model)));
|
2015-07-16 02:50:53 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 23:25:17 +00:00
|
|
|
void TrayIconCocoa::CloseContextMenu() {
|
|
|
|
[status_item_view_ closeContextMenu];
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void TrayIconCocoa::SetContextMenu(ElectronMenuModel* menu_model) {
|
2018-08-27 16:58:47 +00:00
|
|
|
if (menu_model) {
|
|
|
|
// Create native menu.
|
2020-02-04 20:19:40 +00:00
|
|
|
menu_.reset([[ElectronMenuController alloc] initWithModel:menu_model
|
|
|
|
useDefaultAccelerator:NO]);
|
2018-08-27 16:58:47 +00:00
|
|
|
} else {
|
|
|
|
menu_.reset();
|
|
|
|
}
|
2015-07-15 10:26:39 +00:00
|
|
|
[status_item_view_ setMenuController:menu_.get()];
|
2014-05-30 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 06:40:30 +00:00
|
|
|
gfx::Rect TrayIconCocoa::GetBounds() {
|
2019-07-31 17:52:50 +00:00
|
|
|
return gfx::ScreenRectFromNSRect([status_item_view_ window].frame);
|
2015-08-10 04:48:22 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 15:57:54 +00:00
|
|
|
// static
|
2020-01-31 05:37:03 +00:00
|
|
|
TrayIcon* TrayIcon::Create(base::Optional<UUID> guid) {
|
2014-05-30 15:57:54 +00:00
|
|
|
return new TrayIconCocoa;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|