- Readme + ToDo list
- Preferences: Browser list and config - Preferences: Default RSS reader application - Open and handle 'feed://' urls
This commit is contained in:
@@ -23,13 +23,42 @@
|
||||
#import "SettingsGeneral.h"
|
||||
#import "AppHook.h"
|
||||
#import "BarMenu.h"
|
||||
#import "UserPrefs.h"
|
||||
|
||||
|
||||
@interface SettingsGeneral()
|
||||
@property (weak) IBOutlet NSPopUpButton *popupHttpApplication;
|
||||
@property (weak) IBOutlet NSPopUpButton *popupDefaultRSSReader;
|
||||
@end
|
||||
|
||||
@implementation SettingsGeneral
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Default http application for opening the feed urls
|
||||
[self generateMenuForPopup:self.popupHttpApplication withScheme:@"https"];
|
||||
[self.popupHttpApplication insertItemWithTitle:NSLocalizedString(@"System Default", @"Default web browser application") atIndex:0];
|
||||
[self selectBundleID:[UserPrefs getHttpApplication] inPopup:self.popupHttpApplication];
|
||||
// Default RSS Reader application
|
||||
[self generateMenuForPopup:self.popupDefaultRSSReader withScheme:@"feed"];
|
||||
[self selectBundleID:[self defaultBundleIdForScheme:@"feed"] inPopup:self.popupDefaultRSSReader];
|
||||
}
|
||||
|
||||
#pragma mark - UI interaction with IBAction
|
||||
|
||||
- (IBAction)changeHttpApplication:(NSPopUpButton *)sender {
|
||||
[UserPrefs setHttpApplication:sender.selectedItem.representedObject];
|
||||
}
|
||||
|
||||
- (IBAction)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];
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add self to login items
|
||||
|
||||
- (IBAction)checkmarkClicked:(NSButton*)sender {
|
||||
// TODO: Could be optimized by updating only the relevant parts
|
||||
[[(AppHook*)NSApp barMenu] rebuildMenu];
|
||||
@@ -48,11 +77,111 @@
|
||||
[[(AppHook*)NSApp barMenu] updateMenuHeaders:recursive];
|
||||
}
|
||||
|
||||
- (IBAction)changeMenuItemUpdateAllHidden:(NSButton*)sender {
|
||||
- (IBAction)changeMenuItemUpdateAll:(NSButton*)sender {
|
||||
BOOL checked = (sender.state == NSControlStateValueOn);
|
||||
[[(AppHook*)NSApp barMenu] setItemUpdateAllHidden:!checked];
|
||||
}
|
||||
|
||||
// TODO: show list of installed browsers and make menu choosable
|
||||
#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 {
|
||||
CFStringRef bundleIDRef = CFBridgingRetain(bundleID);
|
||||
if (!bundleIDRef)
|
||||
return nil;
|
||||
CFArrayRef arr = LSCopyApplicationURLsForBundleIdentifier(bundleIDRef, NULL);
|
||||
CFRelease(bundleIDRef);
|
||||
if (!arr)
|
||||
return nil;
|
||||
CFDictionaryRef infoDict = NULL;
|
||||
if (CFArrayGetCount(arr) > 0)
|
||||
infoDict = CFBundleCopyInfoDictionaryForURL(CFArrayGetValueAtIndex(arr, 0));
|
||||
CFRelease(arr);
|
||||
if (!infoDict)
|
||||
return nil;
|
||||
NSString *name = CFDictionaryGetValue(infoDict, kCFBundleNameKey);
|
||||
CFRelease(infoDict);
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
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 {
|
||||
CFStringRef schemeRef = CFBridgingRetain(scheme);
|
||||
if (!schemeRef)
|
||||
return nil;
|
||||
CFArrayRef allHandlers = LSCopyAllHandlersForURLScheme(schemeRef);
|
||||
CFRelease(schemeRef);
|
||||
return (NSArray*)CFBridgingRelease(allHandlers);
|
||||
}
|
||||
|
||||
/**
|
||||
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 {
|
||||
CFStringRef schemeRef = CFBridgingRetain(scheme);
|
||||
if (!schemeRef)
|
||||
return nil;
|
||||
CFStringRef defaultHandler = LSCopyDefaultHandlerForURLScheme(schemeRef);
|
||||
CFRelease(schemeRef);
|
||||
return (NSString*)CFBridgingRelease(defaultHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
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 {
|
||||
CFStringRef bundleIDRef = CFBridgingRetain(bundleID);
|
||||
if (!bundleIDRef)
|
||||
return NO;
|
||||
CFStringRef schemeRef = CFBridgingRetain(@"feed");
|
||||
if (!schemeRef) {
|
||||
CFRelease(bundleIDRef);
|
||||
return NO;
|
||||
}
|
||||
OSStatus s = LSSetDefaultHandlerForURLScheme(schemeRef, bundleIDRef);
|
||||
CFRelease(schemeRef);
|
||||
CFRelease(bundleIDRef);
|
||||
return s == 0;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SettingsGeneral">
|
||||
<connections>
|
||||
<outlet property="popupDefaultRSSReader" destination="tJe-jL-nUu" id="DUq-ti-Drf"/>
|
||||
<outlet property="popupHttpApplication" destination="BcN-gW-jBg" id="X2r-Nn-igN"/>
|
||||
<outlet property="view" destination="mbb-wD-pDD" id="Syb-4w-ekh"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
@@ -42,7 +44,7 @@
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="changeMenuItemUpdateAllHidden:" target="-2" id="12D-ge-tzs"/>
|
||||
<action selector="changeMenuItemUpdateAll:" target="-2" id="Zb8-Oi-JVr"/>
|
||||
<binding destination="iU7-KA-nY5" name="value" keyPath="values.globalUpdateAll" id="FrQ-u0-lFo">
|
||||
<dictionary key="options">
|
||||
<bool key="NSAllowsEditingMultipleValuesSelection" value="NO"/>
|
||||
@@ -327,7 +329,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="36q-Dv-PLf">
|
||||
<rect key="frame" x="18" y="49" width="133" height="17"/>
|
||||
<rect key="frame" x="18" y="76" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Menu bar icon:" id="Mkr-3d-gmN">
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -336,33 +338,34 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<imageView focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="usG-bX-431">
|
||||
<rect key="frame" x="156" y="42" width="32" height="32"/>
|
||||
<rect key="frame" x="156" y="69" width="32" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" selectable="YES" editable="YES" focusRingType="none" alignment="left" imageScaling="proportionallyDown" imageFrameStyle="grayBezel" image="NSBookmarksTemplate" id="QxY-0c-aDo"/>
|
||||
</imageView>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2sG-NO-OJz">
|
||||
<rect key="frame" x="18" y="22" width="133" height="17"/>
|
||||
<rect key="frame" x="18" y="49" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Open URL in:" id="vNb-i3-dvE">
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Open URLs with:" id="vNb-i3-dvE">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BcN-gW-jBg">
|
||||
<rect key="frame" x="155" y="17" width="148" height="26"/>
|
||||
<rect key="frame" x="155" y="44" width="148" height="26"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<popUpButtonCell key="cell" type="push" title="Default" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="qW6-vv-pdE" id="R91-En-pHg">
|
||||
<popUpButtonCell key="cell" type="push" title="-- list --" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="qW6-vv-pdE" id="R91-En-pHg">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" id="M0i-AE-1LS">
|
||||
<items>
|
||||
<menuItem title="Default" state="on" id="qW6-vv-pdE"/>
|
||||
<menuItem title="Safari" id="RTt-ZJ-ZHv"/>
|
||||
<menuItem title="other …" id="hSc-D3-fq8"/>
|
||||
<menuItem title="-- list --" state="on" id="qW6-vv-pdE"/>
|
||||
</items>
|
||||
</menu>
|
||||
</popUpButtonCell>
|
||||
<connections>
|
||||
<action selector="changeHttpApplication:" target="-2" id="Cyb-ab-VNu"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
<customView toolTip="Show in menu bar" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="P4Y-i1-MGE" customClass="SettingsIconGlobal">
|
||||
<rect key="frame" x="20" y="260" width="18" height="18"/>
|
||||
@@ -401,7 +404,7 @@
|
||||
</userDefinedRuntimeAttributes>
|
||||
</customView>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Tec-F3-9cE">
|
||||
<rect key="frame" x="201" y="48" width="46" height="18"/>
|
||||
<rect key="frame" x="201" y="75" width="46" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Tint" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="19k-mc-RLe">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
@@ -417,6 +420,31 @@
|
||||
</binding>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TC5-cu-zUi">
|
||||
<rect key="frame" x="18" y="22" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Default RSS Reader:" id="wvK-Oz-Kk3">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tJe-jL-nUu">
|
||||
<rect key="frame" x="155" y="17" width="148" height="26"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<popUpButtonCell key="cell" type="push" title="-- list --" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="4Gg-hZ-mh4" id="saR-9h-TWE">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" id="8gY-aZ-fCb">
|
||||
<items>
|
||||
<menuItem title="-- list --" state="on" id="4Gg-hZ-mh4"/>
|
||||
</items>
|
||||
</menu>
|
||||
</popUpButtonCell>
|
||||
<connections>
|
||||
<action selector="changeDefaultRSSReader:" target="-2" id="ul1-1K-oJb"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
</subviews>
|
||||
<point key="canvasLocation" x="140" y="-155.5"/>
|
||||
</customView>
|
||||
|
||||
@@ -25,4 +25,6 @@
|
||||
@interface UserPrefs : NSObject
|
||||
+ (BOOL)defaultYES:(NSString*)key;
|
||||
+ (BOOL)defaultNO:(NSString*)key;
|
||||
+ (NSString*)getHttpApplication;
|
||||
+ (void)setHttpApplication:(NSString*)bundleID;
|
||||
@end
|
||||
|
||||
@@ -35,4 +35,12 @@
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
|
||||
}
|
||||
|
||||
+ (NSString*)getHttpApplication {
|
||||
return [[NSUserDefaults standardUserDefaults] stringForKey:@"defaultHttpApplication"];
|
||||
}
|
||||
|
||||
+ (void)setHttpApplication:(NSString*)bundleID {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:bundleID forKey:@"defaultHttpApplication"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user