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

fix(client/cordova/apple/macos): fix popover click and location issues #1845

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/cordova/apple/xcode/macos/Outline/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,10 @@ - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
self.statusItem.button.action = @selector(togglePopover);
[self setAppIcon:@"StatusBarButtonImage"];
self.popover = [[NSPopover alloc] init];
self.popover.behavior = NSPopoverBehaviorTransient;
self.popover.contentViewController = [[NSViewController alloc] initWithNibName:@"MainViewController"
bundle:[NSBundle mainBundle]];
self.popover.contentViewController.view = self.window.contentView;
// Monitor clicks outside the popover in order to close it.
NSEventMask eventMask = NSEventMaskLeftMouseDown|NSEventMaskRightMouseDown;
self.eventMonitor = [[EventMonitor alloc] initWithMask:eventMask handler:^(NSEvent* event) {
if (self.popover.isShown) {
[self closePopover];
}
}];

if ([self wasStartedByLauncherApp]) {
[OutlineVpn.shared startLastSuccessfulTunnel:^(enum ErrorCode errorCode) {
Expand All @@ -103,7 +97,16 @@ - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
}
}];
} else {
[self showPopover];
// The rendering of the popover is relative to the app's status item in the status bar.
// Even though we've already created the status bar above, the popover is being created
// before the status item has been rendered in the UI. This causes the initial popover
// load to be "floating" and ends up aligned at the bottom of the screen. For this initial
// load we add a small artificial delay to prevent that from happening.
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self showPopover];
});
}
[self setAppLauncherEnabled:true]; // Enable app launcher to start on boot.
}
Expand Down
Loading