From fd89e43b4a0a9fa7a7999245e8986d2e11b96a08 Mon Sep 17 00:00:00 2001 From: Eitot Date: Fri, 26 Jul 2024 07:50:38 +0200 Subject: [PATCH 1/4] 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(); } } From aeb66f18014d26da9d86ff94bc1f5d57aa8b9db1 Mon Sep 17 00:00:00 2001 From: Eitot Date: Fri, 26 Jul 2024 08:17:05 +0200 Subject: [PATCH 2/4] Fix initial selection state of download folder -selectedItemAtIndex below will add a check mark to the menu item. --- .../Preferences window/GeneralPreferencesViewController.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m index ad782a10bf..b3d436f717 100644 --- a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m +++ b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m @@ -318,8 +318,7 @@ -(void)updateDownloadsPopUp:(NSString *)downloadFolderPath downloadPathItem.title = [[NSFileManager defaultManager] displayNameAtPath:downloadFolderPath]; downloadPathItem.image = pathImage; - downloadPathItem.state = NSControlStateValueOff; - + [downloadFolder selectItemAtIndex:0]; } From e095d5b2d9c0535111cb94386765f6ac1018b86a Mon Sep 17 00:00:00 2001 From: Eitot Date: Fri, 26 Jul 2024 08:17:37 +0200 Subject: [PATCH 3/4] Change button label of default application selection --- .../Preferences window/GeneralPreferencesViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m index b3d436f717..a4f7386af6 100644 --- a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m +++ b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m @@ -367,6 +367,7 @@ -(IBAction)handleLinkSelector:(id)sender } else { panel.allowedFileTypes = @[NSFileTypeForHFSTypeCode('APPL')]; } + panel.prompt = NSLocalizedString(@"Select", @"Label of a button on an open panel"); [panel beginSheetModalForWindow:prefPaneWindow completionHandler:^(NSInteger returnCode) { [panel orderOut:self]; [prefPaneWindow makeKeyAndOrderFront:self]; From 951c65f20c8b4d4cf2d572ea1ac693ec55eb5c23 Mon Sep 17 00:00:00 2001 From: Eitot Date: Fri, 26 Jul 2024 08:24:14 +0200 Subject: [PATCH 4/4] Remove argument from -handleLinkSelector: --- .../Preferences window/GeneralPreferencesViewController.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m index a4f7386af6..56edb999e2 100644 --- a/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m +++ b/Vienna/Sources/Preferences window/GeneralPreferencesViewController.m @@ -36,7 +36,6 @@ -(void)initializePreferences; // -(void)selectUserDefaultFont:(NSString *)name size:(int)size control:(NSPopUpButton *)control sizeControl:(NSComboBox *)sizeControl; // -(void)controlTextDidEndEditing:(NSNotification *)notification; -(void)refreshLinkHandler; --(IBAction)handleLinkSelector:(id)sender; -(void)updateDownloadsPopUp:(NSString *)downloadFolderPath; @end @@ -338,7 +337,7 @@ -(IBAction)selectDefaultLinksHandler:(id)sender NSMenuItem * selectedItem = linksHandler.selectedItem; if (selectedItem != nil) { if (selectedItem.tag == -1) { - [self handleLinkSelector:self]; + [self handleLinkSelector]; return; } typeof(self) __weak weakSelf = self; @@ -356,7 +355,7 @@ -(IBAction)selectDefaultLinksHandler:(id)sender * file browser in the Applications folder and use that to add a new application to the * list. */ --(IBAction)handleLinkSelector:(id)sender +- (void)handleLinkSelector { NSOpenPanel * panel = [NSOpenPanel openPanel]; NSWindow * prefPaneWindow = linksHandler.window;