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

Make default application handler asynchronous #1780

Merged
merged 4 commits into from
Jul 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -318,8 +317,7 @@ -(void)updateDownloadsPopUp:(NSString *)downloadFolderPath

downloadPathItem.title = [[NSFileManager defaultManager] displayNameAtPath:downloadFolderPath];
downloadPathItem.image = pathImage;
downloadPathItem.state = NSControlStateValueOff;


[downloadFolder selectItemAtIndex:0];
}

Expand All @@ -339,20 +337,25 @@ -(IBAction)selectDefaultLinksHandler:(id)sender
NSMenuItem * selectedItem = linksHandler.selectedItem;
if (selectedItem != nil) {
if (selectedItem.tag == -1) {
[self handleLinkSelector:self];
[self handleLinkSelector];
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
* Handle the 'Select...' command on the popup list of registered applications. Display the
* 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;
Expand All @@ -363,18 +366,25 @@ -(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];

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 +405,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