From a1f191789db8b97083c77d22f362a0ddb8dd2b76 Mon Sep 17 00:00:00 2001 From: relikd Date: Sun, 11 Aug 2019 15:31:35 +0200 Subject: [PATCH] If database empty, add releases feed --- CHANGELOG.md | 3 ++- baRSS/AppHook.m | 7 ++++--- baRSS/Constants.h | 2 ++ baRSS/Helper/FeedDownload.h | 3 ++- baRSS/Helper/FeedDownload.m | 18 ++++++++++++++---- baRSS/Info.plist | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4c13d3..0499618 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project does adhere to [Semantic Versioning](https://semver.org/spec/v2 - *Settings, Feeds:* OPML export with selected items only - *UI:* Accessibility hints for most UI elements - *UI*: Show welcome message upon first usage (empty db) -- *DB*: Table for options. E.g., with what version was the db last used +- Welcome message also adds Github releases feed - Associate OPML files (double click and right click actions in Finder) - Quick Look preview for OPML files @@ -37,6 +37,7 @@ and this project does adhere to [Semantic Versioning](https://semver.org/spec/v2 - *Settings, Feeds:* Always append new items at the end - *Adding feed:* Display error reason if user cancels the creation of a new feed item - *Adding feed:* Refresh interval hotkeys set to: `⌘1` … `⌘6` +- *DB*: New table for options. E.g., what app version modified the database ## [0.9.4] - 2019-04-02 diff --git a/baRSS/AppHook.m b/baRSS/AppHook.m index a101479..b92494f 100644 --- a/baRSS/AppHook.m +++ b/baRSS/AppHook.m @@ -51,11 +51,12 @@ } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + [_statusItem asyncReloadUnreadCount]; + [FeedDownload registerNetworkChangeNotification]; // will call update scheduler if ([StoreCoordinator isEmpty]) { [_statusItem showWelcomeMessage]; + [FeedDownload autoDownloadAndParseUpdateURL]; } - [FeedDownload registerNetworkChangeNotification]; // will call update scheduler - [_statusItem asyncReloadUnreadCount]; } - (void)applicationWillTerminate:(NSNotification *)aNotification { @@ -71,7 +72,7 @@ url = [url substringFromIndex:2]; } if ([scheme isEqualToString:@"feed"]) { - [FeedDownload autoDownloadAndParseURL:url successBlock:nil]; + [FeedDownload autoDownloadAndParseURL:url addAnyway:NO modify:nil]; } } diff --git a/baRSS/Constants.h b/baRSS/Constants.h index b517b36..b64ed82 100644 --- a/baRSS/Constants.h +++ b/baRSS/Constants.h @@ -30,6 +30,8 @@ /// UTI type used for opml files static NSPasteboardType const UTI_OPML = @"org.opml"; +/// URL with newest baRSS releases. Automatically added when user starts baRSS for the first time. +static NSString* const versionUpdateURL = @"https://github.com/relikd/baRSS/releases.atom"; #pragma mark - NSImageName constants diff --git a/baRSS/Helper/FeedDownload.h b/baRSS/Helper/FeedDownload.h index dcc7db2..a2a3348 100644 --- a/baRSS/Helper/FeedDownload.h +++ b/baRSS/Helper/FeedDownload.h @@ -39,7 +39,8 @@ + (void)forceUpdateAllFeeds; // Downloading + (void)newFeed:(NSString *)urlStr askUser:(nonnull NSString*(^)(RSHTMLMetadata *meta))askUser block:(nonnull void(^)(RSParsedFeed *parsed, NSError *error, NSHTTPURLResponse *response))block; -+ (void)autoDownloadAndParseURL:(NSString*)urlStr successBlock:(nullable os_block_t)block; ++ (void)autoDownloadAndParseURL:(NSString*)urlStr addAnyway:(BOOL)flag modify:(nullable void(^)(Feed *feed))block; ++ (void)autoDownloadAndParseUpdateURL; + (void)batchDownloadFeeds:(NSArray *)list favicons:(BOOL)fav showErrorAlert:(BOOL)alert finally:(nullable os_block_t)block; // Favicon image download + (void)downloadFavicon:(NSString*)urlStr finished:(void(^)(NSImage * _Nullable img))block; diff --git a/baRSS/Helper/FeedDownload.m b/baRSS/Helper/FeedDownload.m index 292c329..d77915b 100644 --- a/baRSS/Helper/FeedDownload.m +++ b/baRSS/Helper/FeedDownload.m @@ -26,6 +26,7 @@ #import "Feed+Ext.h" #import "FeedMeta+Ext.h" #import "FeedGroup+Ext.h" +#import "NSDate+Ext.h" #import @@ -342,24 +343,33 @@ static BOOL _nextUpdateIsForced = NO; Creates new @c FeedGroup, @c Feed, @c FeedMeta and @c FeedArticle instances and saves them to the persistent store. Update duration is set to the default of 30 minutes. */ -+ (void)autoDownloadAndParseURL:(NSString*)url successBlock:(nullable os_block_t)block { ++ (void)autoDownloadAndParseURL:(NSString*)url addAnyway:(BOOL)flag modify:(nullable void(^)(Feed *feed))block { NSManagedObjectContext *moc = [StoreCoordinator createChildContext]; Feed *f = [Feed appendToRootWithDefaultIntervalInContext:moc]; f.meta.url = url; - [self backgroundUpdateBoth:f favicon:YES alert:YES finally:^(BOOL successful){ - if (!successful) { + [self backgroundUpdateBoth:f favicon:YES alert:!flag finally:^(BOOL successful){ + if (!flag && !successful) { [moc deleteObject:f.group]; + } else if (block) { + block(f); // only on success } [StoreCoordinator saveContext:moc andParent:YES]; [moc reset]; if (successful) { PostNotification(kNotificationGroupInserted, f.group.objectID); [self scheduleUpdateForUpcomingFeeds]; - if (block) block(); } }]; } +/// Insert Github URL for version releases with update interval 2 days and rename @c FeedGroup item. ++ (void)autoDownloadAndParseUpdateURL { + [self autoDownloadAndParseURL:versionUpdateURL addAnyway:YES modify:^(Feed *feed) { + feed.group.name = NSLocalizedString(@"baRSS releases", nil); + [feed.meta setRefreshAndSchedule:2 * TimeUnitDays]; + }]; +} + /** Start download of feed xml, then continue with favicon download (optional). diff --git a/baRSS/Info.plist b/baRSS/Info.plist index 484e181..dae1ac5 100644 --- a/baRSS/Info.plist +++ b/baRSS/Info.plist @@ -60,7 +60,7 @@ CFBundleVersion - 10158 + 10180 LSApplicationCategoryType public.app-category.news LSMinimumSystemVersion