Skip to content

Commit

Permalink
Make default application handler asynchronous
Browse files Browse the repository at this point in the history
When the user selected a default application, the pop-up button selection was not always updated.
  • Loading branch information
Eitot committed Jul 26, 2024
1 parent 426dc36 commit fd89e43
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,14 @@ -(IBAction)selectDefaultLinksHandler:(id)sender
[self handleLinkSelector:self];
return;
}
[self setDefaultApplicationForFeedScheme:[appToPathMap valueForKey:selectedItem.title]];
typeof(self) __weak weakSelf = self;
[self setDefaultApplicationForFeedScheme:[appToPathMap valueForKey:selectedItem.title]
completionHandler:^{
[weakSelf refreshLinkHandler];
}];
} else {
[self refreshLinkHandler];
}
[self refreshLinkHandler];
}

/* handleLinkSelector
Expand All @@ -368,13 +373,19 @@ -(IBAction)handleLinkSelector:(id)sender
[prefPaneWindow makeKeyAndOrderFront:self];

if (returnCode == NSModalResponseOK) {
[self setDefaultApplicationForFeedScheme:panel.URL];
typeof(self) __weak weakSelf = self;
[self setDefaultApplicationForFeedScheme:panel.URL
completionHandler:^{
[weakSelf refreshLinkHandler];
}];
} else {
[self refreshLinkHandler];
}
[self refreshLinkHandler];
}];
}

- (void)setDefaultApplicationForFeedScheme:(NSURL *)applicationURL
completionHandler:(void (^)(void))completionHandler
{
NSString *feedURLScheme = @"feed";
if (@available(macOS 12, *)) {
Expand All @@ -395,12 +406,16 @@ - (void)setDefaultApplicationForFeedScheme:(NSURL *)applicationURL
} else {
os_log_debug(VNA_LOG, "Handler for the feed URL scheme changed to %@", applicationURL.lastPathComponent);
}
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler();
});
}];
} else {
CFStringRef scheme = (__bridge CFStringRef)feedURLScheme;
NSBundle *bundle = [NSBundle bundleWithURL:applicationURL];
CFStringRef bundleID = (__bridge CFStringRef)bundle.bundleIdentifier;
LSSetDefaultHandlerForURLScheme(scheme, bundleID);
completionHandler();
}
}

Expand Down

0 comments on commit fd89e43

Please sign in to comment.