barss: URL scheme + remove 'Fix cache' button

This commit is contained in:
relikd
2019-08-16 18:36:19 +02:00
parent e1bf7cac33
commit 571aac4533
16 changed files with 164 additions and 132 deletions

View File

@@ -60,7 +60,7 @@
[mas beginEditing];
[self str:mas add:@"Programming\n" bold:YES];
[self str:mas add:@"Oleg Geier\n\n" bold:NO];
[self str:mas add:@"Source Code available\n" bold:YES];
[self str:mas add:@"Source Code Available\n" bold:YES];
[self str:mas add:@"github.com" link:@"https://github.com/relikd/baRSS"];
[self str:mas add:@" (MIT License)\nor " bold:NO];
[self str:mas add:@"gitlab.com" link:@"https://gitlab.com/relikd/baRSS"];
@@ -68,6 +68,8 @@
[self str:mas add:@"3rd-Party Libraries\n" bold:YES];
[self str:mas add:@"RSXML" link:@"https://github.com/relikd/RSXML"];
[self str:mas add:@" (MIT License)" bold:NO];
[self str:mas add:@"\n\n\n\nOptions\n" bold:YES];
[self str:mas add:@"Fix Cache" link:@"barss:config/fixcache"];
[mas endEditing];
return mas;
}

View File

@@ -142,7 +142,7 @@
// NSInteger ins = [[[moc.insertedObjects filteredSetUsingPredicate:pred] valueForKeyPath:@"@sum.unread"] integerValue];
// NSLog(@"%ld, %ld", del, ins);
[StoreCoordinator saveContext:self.dataStore.managedObjectContext andParent:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountReset object:nil];
PostNotification(kNotificationTotalUnreadCountReset, nil);
[self.dataStore rearrangeObjects]; // update ordering
[UpdateScheduler scheduleNextFeed];
}
@@ -228,7 +228,7 @@
[self restoreOrderingAndIndexPathStr:parentNodes];
[self endCoreDataChangeUndoEmpty:NO forceUndo:NO];
[UpdateScheduler scheduleNextFeed];
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountReset object:nil];
PostNotification(kNotificationTotalUnreadCountReset, nil);
}
- (void)openImportDialog {

View File

@@ -23,7 +23,6 @@
@import Cocoa;
@interface SettingsGeneral : NSViewController
- (void)fixCache:(NSButton *)sender;
- (void)changeHttpApplication:(NSPopUpButton *)sender;
- (void)changeDefaultRSSReader:(NSPopUpButton *)sender;
@end

View File

@@ -46,17 +46,6 @@
#pragma mark - UI interaction with IBAction
- (void)fixCache:(NSButton *)sender {
NSUInteger deleted = [StoreCoordinator deleteUnreferenced];
[StoreCoordinator restoreFeedIndexPaths];
PostNotification(kNotificationTotalUnreadCountReset, nil);
// show only if >0, but hey, this button will vanish anyway ...
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = [NSString stringWithFormat:@"Removed %lu unreferenced core data entries.", deleted];
alert.alertStyle = NSAlertStyleInformational;
[alert runModal];
}
- (void)changeHttpApplication:(NSPopUpButton *)sender {
[UserPrefs setHttpApplication:sender.selectedItem.representedObject];
}
@@ -101,22 +90,12 @@
@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;
NSArray<NSURL*> *urls = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier((__bridge CFStringRef)bundleID, NULL));
if (urls.count > 0) {
NSDictionary *info = CFBridgingRelease(CFBundleCopyInfoDictionaryForURL((CFURLRef)urls.firstObject));
return info[(NSString*)kCFBundleNameKey];
}
return nil;
}
/**
@@ -126,12 +105,7 @@
@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);
return CFBridgingRelease(LSCopyAllHandlersForURLScheme((__bridge CFStringRef _Nonnull)(scheme)));
}
/**
@@ -141,12 +115,7 @@
@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);
return CFBridgingRelease(LSCopyDefaultHandlerForURLScheme((__bridge CFStringRef _Nonnull)(scheme)));
}
/**
@@ -157,18 +126,12 @@
*/
- (BOOL)setDefaultRSSApplication:(NSString*)bundleID {
// TODO: Does not work with sandboxing.
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);
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

View File

@@ -36,10 +36,6 @@
self.popupHttpApplication = [[self createPopup:x top: PAD_WIN + 1] action:@selector(changeHttpApplication:) target:controller];
self.popupDefaultRSSReader = [[self createPopup:x top: YFromTop(self.popupHttpApplication) + PAD_M] action:@selector(changeDefaultRSSReader:) target:controller];
// Add fix cache button
[[[[NSView button:NSLocalizedString(@"Fix Cache", nil)] action:@selector(fixCache:) target:controller]
tooltip:NSLocalizedString(@"Will remove unreferenced feed entries", nil)] placeIn:self xRight:PAD_WIN y:PAD_WIN];
return self;
}

View File

@@ -26,6 +26,7 @@
// User Preferences Plist
+ (BOOL)defaultYES:(NSString*)key;
+ (BOOL)defaultNO:(NSString*)key;
+ (NSUInteger)defaultUInt:(NSUInteger)defaultInt forKey:(NSString*)key;
+ (NSString*)getHttpApplication;
+ (void)setHttpApplication:(NSString*)bundleID;

View File

@@ -41,9 +41,9 @@
}
/// @return Return @c defaultInt if key is not set. Otherwise, return user defaults property from plist.
+ (NSInteger)defaultInt:(NSInteger)defaultInt forKey:(NSString*)key {
+ (NSUInteger)defaultUInt:(NSUInteger)defaultInt forKey:(NSString*)key {
NSInteger ret = [[NSUserDefaults standardUserDefaults] integerForKey:key];
if (ret > 0) return ret;
if (ret > 0) return (NSUInteger)ret;
return defaultInt;
}
@@ -74,21 +74,15 @@
/// @return The limit on how many links should be opened at the same time, if user holds the option key.
/// Default: @c 10
+ (NSUInteger)openFewLinksLimit {
return (NSUInteger)[self defaultInt:10 forKey:@"openFewLinksLimit"];
}
+ (NSUInteger)openFewLinksLimit { return [self defaultUInt:10 forKey:@"openFewLinksLimit"]; }
/// @return The limit on when to truncate article titles (Short names setting must be active).
/// Default: @c 60
+ (NSUInteger)shortArticleNamesLimit {
return (NSUInteger)[self defaultInt:60 forKey:@"shortArticleNamesLimit"];
}
+ (NSUInteger)shortArticleNamesLimit { return [self defaultUInt:60 forKey:@"shortArticleNamesLimit"]; }
/// @return The maximum number of articles displayed per feed (Limit articles setting must be active).
/// Default: @c 40
+ (NSUInteger)articlesInMenuLimit {
return (NSUInteger)[self defaultInt:40 forKey:@"articlesInMenuLimit"];
}
+ (NSUInteger)articlesInMenuLimit { return [self defaultUInt:40 forKey:@"articlesInMenuLimit"]; }
#pragma mark - Application Info Plist

View File

@@ -25,5 +25,5 @@
@interface Preferences : NSWindow <NSWindowDelegate>
+ (instancetype)window;
- (SettingsFeeds*)selectFeedsTab;
- (__kindof NSViewController*)selectTab:(NSUInteger)index;
@end

View File

@@ -25,6 +25,7 @@
#import "SettingsFeeds.h"
#import "SettingsAppearance.h"
#import "SettingsAbout.h"
#import "UserPrefs.h"
/// Managing individual tabs in application preferences
@interface PrefTabs : NSTabViewController
@@ -48,8 +49,7 @@
flexibleWidth,
TabItem(NSImageNameInfo, NSLocalizedString(@"About", nil), [SettingsAbout class]),
];
[self switchToTab:[[NSUserDefaults standardUserDefaults] integerForKey:@"preferencesTab"]];
[self switchToTab:[UserPrefs defaultUInt:0 forKey:@"preferencesTab"]];
}
return self;
}
@@ -63,9 +63,14 @@ NS_INLINE NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Class cl
}
/// Safely set selected index without out of bounds exception
- (void)switchToTab:(NSInteger)index {
if (index > 0 || (NSUInteger)index < self.tabViewItems.count)
self.selectedTabViewItemIndex = index;
- (__kindof NSViewController*)switchToTab:(NSUInteger)index {
if (index < 0 || index >= self.tabViewItems.count)
return nil;
NSTabViewItem *tab = self.tabViewItems[index];
if (tab.identifier == NSToolbarFlexibleSpaceItemIdentifier)
return nil;
self.selectedTabViewItemIndex = (NSInteger)index;
return [tab viewController];
}
/// Delegate method, store last selected tab to user preferences
@@ -100,10 +105,9 @@ NS_INLINE NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Class cl
return w;
}
- (SettingsFeeds*)selectFeedsTab {
PrefTabs *pref = (PrefTabs*)self.contentViewController;
[pref switchToTab:1];
return (SettingsFeeds*)[pref.tabViewItems[1] viewController];
/// Selects tab (if not flexible space or out of bounds) and returns associated view controller
- (__kindof NSViewController*)selectTab:(NSUInteger)index {
return [(PrefTabs*)self.contentViewController switchToTab:index];
}
- (void)windowWillClose:(NSNotification *)notification {