From 85cc12f34a4f1ed7edd95dee9b8a852887327521 Mon Sep 17 00:00:00 2001 From: relikd Date: Tue, 23 Jul 2019 15:49:45 +0200 Subject: [PATCH] Fix: keep unread state if open unread articles failed --- CHANGELOG.md | 1 + baRSS/Core Data/FeedArticle+Ext.m | 9 +++--- .../Preferences/Feeds Tab/ModalFeedEditView.m | 2 +- baRSS/Preferences/Helper/UserPrefs.h | 2 +- baRSS/Preferences/Helper/UserPrefs.m | 7 +++-- baRSS/Status Bar Menu/NSMenu+Ext.m | 31 +++++++++++-------- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6ba10f..c47596e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project does NOT adhere to [Semantic Versioning](https://semver.org/spe - Changed error message text when user cancels creation of new feed item - Comparing existing articles with nonexistent guid and link - Adding feed: If URLs can't be resolved in the first run (5xx error), try a second time. E.g., 'Done' click (issue: #5) +- Don't mark articles read if opening URLs failed ### Changed - Interface builder files replaced with code equivalent diff --git a/baRSS/Core Data/FeedArticle+Ext.m b/baRSS/Core Data/FeedArticle+Ext.m index 75624ee..b1ff939 100644 --- a/baRSS/Core Data/FeedArticle+Ext.m +++ b/baRSS/Core Data/FeedArticle+Ext.m @@ -80,15 +80,16 @@ NSManagedObjectContext *moc = [StoreCoordinator createChildContext]; FeedArticle *fa = [moc objectWithID:sender.representedObject]; NSString *url = fa.link; - if (flipUnread || fa.unread) { + BOOL success = NO; + if (url && url.length > 0 && !flipUnread) // flipUnread == change unread state + success = [UserPrefs openURLsWithPreferredBrowser:@[[NSURL URLWithString:url]]]; + if (flipUnread || (success && fa.unread)) { fa.unread = !fa.unread; - NSNumber *num = (fa.unread ? @+1 : @-1); [StoreCoordinator saveContext:moc andParent:YES]; + NSNumber *num = (fa.unread ? @+1 : @-1); [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:num]; } [moc reset]; - if (url && url.length > 0 && !flipUnread) // flipUnread == change unread state - [UserPrefs openURLsWithPreferredBrowser:@[[NSURL URLWithString:url]]]; } @end diff --git a/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m b/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m index 7b69d86..5bb1563 100644 --- a/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m +++ b/baRSS/Preferences/Feeds Tab/ModalFeedEditView.m @@ -89,7 +89,7 @@ self.warningText = txt; // Reload button is only visible on 5xx server error (right of ––––) self.warningReload = [[[[NSView buttonIcon:NSImageNameRefreshTemplate size:16] placeIn:content x:35 yTop:21] - tooltip:NSLocalizedString(@"Retry download (Cmd+R)", nil)] + tooltip:NSLocalizedString(@"Retry download (⌘R)", nil)] action:@selector(reloadData) target:nil]; // up the responder chain } diff --git a/baRSS/Preferences/Helper/UserPrefs.h b/baRSS/Preferences/Helper/UserPrefs.h index 42ae594..df58ae0 100644 --- a/baRSS/Preferences/Helper/UserPrefs.h +++ b/baRSS/Preferences/Helper/UserPrefs.h @@ -28,7 +28,7 @@ + (NSString*)getHttpApplication; + (void)setHttpApplication:(NSString*)bundleID; -+ (void)openURLsWithPreferredBrowser:(NSArray*)urls; ++ (BOOL)openURLsWithPreferredBrowser:(NSArray*)urls; + (NSUInteger)openFewLinksLimit; // Change with: 'defaults write de.relikd.baRSS openFewLinksLimit -int 10' + (NSUInteger)shortArticleNamesLimit; // Change with: 'defaults write de.relikd.baRSS shortArticleNamesLimit -int 50' diff --git a/baRSS/Preferences/Helper/UserPrefs.m b/baRSS/Preferences/Helper/UserPrefs.m index c429863..0dc5a6d 100644 --- a/baRSS/Preferences/Helper/UserPrefs.m +++ b/baRSS/Preferences/Helper/UserPrefs.m @@ -59,10 +59,11 @@ Open web links in default browser or a browser the user selected in the preferences. @param urls A list of @c NSURL objects that will be opened immediatelly in bulk. + @return @c YES if @c urls are opened successfully. @c NO on error. */ -+ (void)openURLsWithPreferredBrowser:(NSArray*)urls { - if (urls.count == 0) return; - [[NSWorkspace sharedWorkspace] openURLs:urls withAppBundleIdentifier:[self getHttpApplication] options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifiers:nil]; ++ (BOOL)openURLsWithPreferredBrowser:(NSArray*)urls { + if (urls.count == 0) return NO; + return [[NSWorkspace sharedWorkspace] openURLs:urls withAppBundleIdentifier:[self getHttpApplication] options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifiers:nil]; } #pragma mark - Hidden Plist Properties - diff --git a/baRSS/Status Bar Menu/NSMenu+Ext.m b/baRSS/Status Bar Menu/NSMenu+Ext.m index 9dedd0b..be65202 100644 --- a/baRSS/Status Bar Menu/NSMenu+Ext.m +++ b/baRSS/Status Bar Menu/NSMenu+Ext.m @@ -193,20 +193,25 @@ typedef NS_ENUM(NSInteger, MenuItemTag) { NSManagedObjectContext *moc = [StoreCoordinator createChildContext]; NSArray *list = [StoreCoordinator articlesAtPath:path isFeed:isFeedMenu sorted:openLinks unread:markRead inContext:moc limit:limit]; - NSNumber *countDiff = [NSNumber numberWithUnsignedInteger:list.count]; - if (markRead) countDiff = [NSNumber numberWithInteger: -1 * countDiff.integerValue]; - - NSMutableArray *urls = [NSMutableArray arrayWithCapacity:list.count]; - for (FeedArticle *fa in list) { - fa.unread = !markRead; - if (openLinks && fa.link.length > 0) - [urls addObject:[NSURL URLWithString:fa.link]]; + BOOL success = NO; + if (openLinks) { + NSMutableArray *urls = [NSMutableArray arrayWithCapacity:list.count]; + for (FeedArticle *fa in list) { + if (fa.link.length > 0) + [urls addObject:[NSURL URLWithString:fa.link]]; + } + success = [UserPrefs openURLsWithPreferredBrowser:urls]; + } + // if success == NO, do not modify unread state + if (!openLinks || success) { + for (FeedArticle *fa in list) { + fa.unread = !markRead; + } + [StoreCoordinator saveContext:moc andParent:YES]; + [moc reset]; + NSNumber *num = [NSNumber numberWithInteger: (markRead ? -1 : +1) * (NSInteger)list.count ]; + [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:num]; } - [StoreCoordinator saveContext:moc andParent:YES]; - [moc reset]; - if (openLinks) - [UserPrefs openURLsWithPreferredBrowser:urls]; - [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTotalUnreadCountChanged object:countDiff]; } @end