|
|
|
|
@@ -36,102 +36,51 @@
|
|
|
|
|
- (void)loadView {
|
|
|
|
|
self.view = [[SettingsGeneralView alloc] initWithController:self];
|
|
|
|
|
// Default http application for opening the feed urls
|
|
|
|
|
[self generateMenuForPopup:self.view.popupHttpApplication withScheme:@"https"];
|
|
|
|
|
[self.view.popupHttpApplication insertItemWithTitle:NSLocalizedString(@"System Default", @"Default web browser application") atIndex:0];
|
|
|
|
|
[self selectBundleID:[UserPrefs getHttpApplication] inPopup:self.view.popupHttpApplication];
|
|
|
|
|
NSPopUpButton *pop = self.view.popupHttpApplication;
|
|
|
|
|
[pop removeAllItems];
|
|
|
|
|
[pop addItemWithTitle:NSLocalizedString(@"System Default", @"Default web browser application")];
|
|
|
|
|
NSArray<NSString*> *browsers = CFBridgingRelease(LSCopyAllHandlersForURLScheme(CFSTR("https")));
|
|
|
|
|
for (NSString *bundleID in browsers) {
|
|
|
|
|
[pop addItemWithTitle: [self applicationNameForBundleId:bundleID]];
|
|
|
|
|
pop.lastItem.representedObject = bundleID;
|
|
|
|
|
}
|
|
|
|
|
[pop selectItemAtIndex:[pop indexOfItemWithRepresentedObject:[UserPrefs getHttpApplication]]];
|
|
|
|
|
// Default RSS Reader application
|
|
|
|
|
[self generateMenuForPopup:self.view.popupDefaultRSSReader withScheme:@"feed"];
|
|
|
|
|
[self selectBundleID:[self defaultBundleIdForScheme:@"feed"] inPopup:self.view.popupDefaultRSSReader];
|
|
|
|
|
NSString *feedBundleId = CFBridgingRelease(LSCopyDefaultHandlerForURLScheme(CFSTR("feed")));
|
|
|
|
|
self.view.defaultReader.objectValue = [self applicationNameForBundleId:feedBundleId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - UI interaction with IBAction
|
|
|
|
|
/// Get human readable application name such as 'Safari' or 'baRSS'
|
|
|
|
|
- (nonnull NSString*)applicationNameForBundleId:(nonnull NSString*)bundleID {
|
|
|
|
|
NSString *name;
|
|
|
|
|
NSArray<NSURL*> *urls = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier((__bridge CFStringRef)bundleID, NULL));
|
|
|
|
|
if (urls.count > 0) {
|
|
|
|
|
NSDictionary *info = CFBridgingRelease(CFBundleCopyInfoDictionaryForURL((CFURLRef)urls.firstObject));
|
|
|
|
|
name = info[(NSString*)kCFBundleExecutableKey];
|
|
|
|
|
}
|
|
|
|
|
return name ? name : bundleID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - User interaction
|
|
|
|
|
|
|
|
|
|
// Callback method fired when user selects a different item from popup list
|
|
|
|
|
- (void)changeHttpApplication:(NSPopUpButton *)sender {
|
|
|
|
|
[UserPrefs setHttpApplication:sender.selectedItem.representedObject];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)changeDefaultRSSReader:(NSPopUpButton *)sender {
|
|
|
|
|
if ([self setDefaultRSSApplication:sender.selectedItem.representedObject] == NO) {
|
|
|
|
|
// in case anything went wrong, restore previous selection
|
|
|
|
|
[self selectBundleID:[self defaultBundleIdForScheme:@"feed"] inPopup:sender];
|
|
|
|
|
}
|
|
|
|
|
// Callback method from round help button right of default feed reader text
|
|
|
|
|
- (void)clickHowToDefaults:(NSButton *)sender {
|
|
|
|
|
NSAlert *alert = [[NSAlert alloc] init];
|
|
|
|
|
alert.alertStyle = NSAlertStyleInformational;
|
|
|
|
|
alert.messageText = NSLocalizedString(@"How to change default feed reader", nil);
|
|
|
|
|
alert.informativeText = NSLocalizedString(@"Unfortunately sandboxed applications are not allowed to change the default application. However, there is an auxiliary application.\n\nFollow the instructions to change the 'feed:' scheme.", nil);
|
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Close", nil)];
|
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"Go to download page", nil)].toolTip = auxiliaryAppURL;
|
|
|
|
|
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {
|
|
|
|
|
if (returnCode == NSAlertSecondButtonReturn) {
|
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:auxiliaryAppURL]];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Helper methods
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Populate @c NSPopUpButton menu with all available application for that scheme.
|
|
|
|
|
|
|
|
|
|
@param scheme URL scheme like @c 'feed' or @c 'https'
|
|
|
|
|
*/
|
|
|
|
|
- (void)generateMenuForPopup:(NSPopUpButton*)popup withScheme:(NSString*)scheme {
|
|
|
|
|
[popup removeAllItems];
|
|
|
|
|
NSArray<NSString*> *apps = [self listOfBundleIdsForScheme:scheme];
|
|
|
|
|
for (NSString *bundleID in apps) {
|
|
|
|
|
NSString *appName = [self applicationNameForBundleId:bundleID];
|
|
|
|
|
if (!appName)
|
|
|
|
|
appName = bundleID;
|
|
|
|
|
[popup addItemWithTitle:appName];
|
|
|
|
|
popup.lastItem.representedObject = bundleID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
For a given @c NSPopUpButton select the item which represents the @c bundleID.
|
|
|
|
|
*/
|
|
|
|
|
- (void)selectBundleID:(NSString*)bundleID inPopup:(NSPopUpButton*)popup {
|
|
|
|
|
[popup selectItemAtIndex:[popup indexOfItemWithRepresentedObject:bundleID]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Get human readable, application name from @c bundleID.
|
|
|
|
|
|
|
|
|
|
@param bundleID as defined in @c Info.plist
|
|
|
|
|
@return Application name such as 'Safari' or 'baRSS'
|
|
|
|
|
*/
|
|
|
|
|
- (NSString*)applicationNameForBundleId:(NSString*)bundleID {
|
|
|
|
|
NSArray<NSURL*> *urls = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier((__bridge CFStringRef)bundleID, NULL));
|
|
|
|
|
if (urls.count > 0) {
|
|
|
|
|
NSDictionary *info = CFBridgingRelease(CFBundleCopyInfoDictionaryForURL((CFURLRef)urls.firstObject));
|
|
|
|
|
return info[(NSString*)kCFBundleExecutableKey];
|
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Get a list of all installed applications supporting that URL scheme.
|
|
|
|
|
|
|
|
|
|
@param scheme URL scheme like @c 'feed' or @c 'https'
|
|
|
|
|
@return Array of @c bundleIDs of installed applications supporting that url scheme.
|
|
|
|
|
*/
|
|
|
|
|
- (NSArray<NSString*>*)listOfBundleIdsForScheme:(NSString*)scheme {
|
|
|
|
|
return CFBridgingRelease(LSCopyAllHandlersForURLScheme((__bridge CFStringRef _Nonnull)(scheme)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Get current default application for provided URL scheme. (e.g., )
|
|
|
|
|
|
|
|
|
|
@param scheme URL scheme like @c 'feed' or @c 'https'
|
|
|
|
|
@return @c bundleID of default application
|
|
|
|
|
*/
|
|
|
|
|
- (NSString*)defaultBundleIdForScheme:(NSString*)scheme {
|
|
|
|
|
return CFBridgingRelease(LSCopyDefaultHandlerForURLScheme((__bridge CFStringRef _Nonnull)(scheme)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Sets the default application for @c feed:// urls. (system wide)
|
|
|
|
|
|
|
|
|
|
@param bundleID as defined in @c Info.plist
|
|
|
|
|
@return Return @c YES if operation was successfull. @c NO otherwise.
|
|
|
|
|
*/
|
|
|
|
|
- (BOOL)setDefaultRSSApplication:(NSString*)bundleID {
|
|
|
|
|
// TODO: Does not work with sandboxing.
|
|
|
|
|
OSStatus s = LSSetDefaultHandlerForURLScheme(CFSTR("feed"), (__bridge CFStringRef _Nonnull)(bundleID));
|
|
|
|
|
return s == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rebuild Launch Services cache
|
|
|
|
|
// https://eclecticlight.co/2017/08/11/launch-services-database-problems-correcting-and-rebuilding/
|
|
|
|
|
// /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -v -apps u
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|