Skip to content

Instantly share code, notes, and snippets.

@bibhas
Created November 29, 2020 06:16
Show Gist options
  • Save bibhas/a24dd2d61bbd7f3956ece3371d675a6e to your computer and use it in GitHub Desktop.
Save bibhas/a24dd2d61bbd7f3956ece3371d675a6e to your computer and use it in GitHub Desktop.
diff --git a/Mac/JMVisibilityManager.m b/Mac/JMVisibilityManager.m
index d311006..af67e8f 100644
--- a/Mac/JMVisibilityManager.m
+++ b/Mac/JMVisibilityManager.m
@@ -169,7 +169,6 @@ - (BOOL)visibleInMenubar
}
-
- (void)setDockIcon:(NSImage *)newDockIcon
{
_dockIcon = newDockIcon;
@@ -213,6 +212,13 @@ - (void)setMenubarIcon:(NSImage *)newMenubarIcon
[self hidePopover];
}];
self.statusItem.menu = nil;
+ if (self.statusItemPopover.isShown)
+ {
+ dispatch_after_main(0.25f, ^{
+ NSView *buttonView = (NSView *)self.statusItem.button;
+ [self.statusItemPopover showRelativeToRect:[buttonView bounds] ofView:buttonView preferredEdge:NSRectEdgeMaxY];
+ });
+ }
// If statusItem.button is clicked, show/hide popup.
// If some other part of the app is clicked, hide the popup.
if (!self.localEventMonitor)
@@ -327,7 +333,11 @@ - (void)showPopoverWithAnimation:(BOOL)shouldAnimate
[self.statusItem.button highlight:YES];
NSView *buttonView = (NSView *)self.statusItem.button;
self.statusItemPopover.animates = shouldAnimate;
- [self.statusItemPopover showRelativeToRect:NSZeroRect ofView:buttonView preferredEdge:NSRectEdgeMaxY];
+ // I'm getting a weird bug wherein, if the statusitem icon is changed more than once,
+ // the popover shows up and then slightly slides down a pixel when the user clicks on
+ // statusitem button. The second showRelativeToRect:ofView:preferredEdge: fixs it (!).
+ [self.statusItemPopover showRelativeToRect:[buttonView bounds] ofView:buttonView preferredEdge:NSRectEdgeMaxY];
+ [self.statusItemPopover showRelativeToRect:[buttonView bounds] ofView:buttonView preferredEdge:NSRectEdgeMaxY];
// Setup a global event monitor to detect outside clicks so we can dismiss this popup
if (self.globalEventMonitor)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment