From fd89e43b4a0a9fa7a7999245e8986d2e11b96a08 Mon Sep 17 00:00:00 2001 From: Eitot Date: Fri, 26 Jul 2024 07:50:38 +0200 Subject: [PATCH] Make default application handler asynchronous When the user selected a default application, the pop-up button selection was not always updated. --- .../GeneralPreferencesViewController.m | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m index 69e9762d84..ad782a10bf 100644 --- a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m +++ b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m @@ -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 @@ -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, *)) { @@ -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(); } }