Status bar app popover always on top when mission control is launched OSX

317 Views Asked by At

I'm working on a status bar app for OSX and I'm trying to replicate the behaviour of the popover that Dropbox uses, so far I've managed to get all of the desired behaviour working except for the fact that when I open mission control the popover doesn't fade away, it simply stays on top covering part of mission control. I've searched quite hard the last few days and have yet to come up with a solution. The only thing I could think of perhaps doing would be to have a listener listening for an upwards 3 finger swipe? Getting the dropbox like popover behaviour has been a royal pain so I plan on uploading a sample app to GitHub once I get this all working to help save people some time trying to find workarounds! Has anyone encountered this issue? Cheers!

Here is the class with the logic for the popover "MenuBarController" #import "MenuBarController.h"

@implementation MenuBarController
@synthesize statusItem;
@synthesize popover;
@synthesize popoverTransiencyMonitor;
-(id)init{
    self.statusItem = [[NSStatusBar systemStatusBar]     statusItemWithLength:NSVariableStatusItemLength];
    self.popover = [NSPopover new];
    popover.behavior = NSPopoverBehaviorTransient;
    return self;
}

-(void)runMenuBarItem{
    // The text that will be shown in the menu bar
    statusItem.title = @"";

    // The image that will be shown in the menu bar, a 16x16 black png works best
    statusItem.image = [NSImage imageNamed:@"redicon"];

    [statusItem setEnabled:YES];
    [statusItem setHighlightMode:YES];
    [statusItem setTarget:self];
    [statusItem setAction:@selector(togglePopover:)];

}

- (void) showPopover:(id)sender {
    MenuBarPopOverViewController * viewController = [[MenuBarPopOverViewController alloc] initWithNibName:@"MenuBarPopOverViewController" bundle:nil];
    popover.contentViewController = viewController;
    [popover showRelativeToRect:NSZeroRect ofView:(NSView *)sender preferredEdge:NSMinYEdge];

}

- (void) closePopover:(id)sender {
    [popover performClose:sender];
}


-(void)togglePopover:(id)sender{
    if(popover.shown){
        [self closePopover:sender];
    }else{
        [self showPopover:sender];
    }
    if (self.popoverTransiencyMonitor == nil) {
        self.popoverTransiencyMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDownMask | NSRightMouseDownMask | NSKeyUpMask) handler:^(NSEvent* event) {
            [NSEvent removeMonitor:self.popoverTransiencyMonitor];
            self.popoverTransiencyMonitor = nil;
            [self.popover close];
        }];
    }
}
@end
0

There are 0 best solutions below