Skip to content

Commit

Permalink
[menu-bar] Add context menu (#36)
Browse files Browse the repository at this point in the history
* [menu-bar] Add context menu

* Add changelog entry
  • Loading branch information
gabrieldonadel authored Aug 11, 2023
1 parent 63f248a commit 66e548f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### 🎉 New features

- Added a context menu when right clicking on the menu bar icon. ([#36](https://github.com/expo/orbit/pull/36) by [@gabrieldonadel](https://github.com/gabrieldonadel))

### 🐛 Bug fixes

### 💡 Others
Expand Down
29 changes: 29 additions & 0 deletions apps/menu-bar/macos/ExpoMenuBar-macOS/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import <React/RCTLinkingManager.h>

#import "DevViewController.h"
#import "WindowNavigator.h"

@interface AppDelegate () <RCTBridgeDelegate>
#if RCT_DEV
Expand All @@ -28,6 +29,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[image setTemplate:YES];
statusItem.button.image = image;
[statusItem.button setTarget:self];
[statusItem.button sendActionOn:NSEventMaskRightMouseUp | NSEventMaskLeftMouseUp];
[statusItem.button setAction:@selector(onPressStatusItem:)];

RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:_bridge
Expand Down Expand Up @@ -58,6 +60,26 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSApp activateIgnoringOtherApps:YES];
}

- (NSMenu *)createContextMenu {
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"My Menu"];

[menu addItemWithTitle:@"Settings..." action:@selector(settingsAction:) keyEquivalent:@""];
[menu addItemWithTitle:@"Quit" action:@selector(quitAction:) keyEquivalent:@"q"];

return menu;
}


- (void)quitAction:(id)sender {
exit(0);
}


- (void)settingsAction:(id)sender {
WindowNavigator *windowNavigator = [WindowNavigator shared];
[windowNavigator openWindow:@"Settings" options:@{}];
}

- (void)openPopover {
[popover showRelativeToRect:statusItem.button.bounds
ofView:statusItem.button
Expand All @@ -68,6 +90,13 @@ - (void)openPopover {
}

- (void)onPressStatusItem:(id)sender {
NSEvent *event = [NSApp currentEvent];
if (event.type == NSEventTypeRightMouseUp) {
NSMenu *contextMenu = [self createContextMenu];
[statusItem popUpStatusItemMenu:contextMenu];
return;
}

if (popover.isShown) {
[popover close];
} else {
Expand Down

0 comments on commit 66e548f

Please sign in to comment.