Reusing favicon url if already processed html data

This commit is contained in:
relikd
2019-02-10 20:48:26 +01:00
parent f2cca57fbb
commit 9bb1b23d8c
5 changed files with 20 additions and 13 deletions

View File

@@ -4,7 +4,7 @@
For nearly a decade I've been using the then free version of [RSS Menu](https://itunes.apple.com/us/app/rss-menu/id423069534). However, with the release of macOS Mojave, 32bit applications are no longer supported. Furthermore, the currently available version in the Mac App Store was last updated in 2014 (as of writing).
*baRSS* was build from scratch with a minimal footprint in mind. It will be available on the AppStore eventually. If you want a feature to be added, drop me an email or create an issue. Look at the other issues, in case somebody else already filed one similar. If you like this project and want to say thank you drop me a line (or other stuff like money). Regardless, I'll continue development as long as I'm using it on my own. Admittedly, I've invested way too much time in this project already (1200h+) …
*baRSS* was build from scratch with a minimal footprint in mind. It will be available on the AppStore eventually. If you want a feature to be added, drop me an email or create an issue. Look at the other issues, in case somebody else already filed one similar. If you like this project and want to say thank you drop me a line (or other stuff like money). Regardless, I'll continue development as long as I'm using it on my own. Admittedly, I've invested way too much time in this project already (1400h+) …
Why is this project not written in Swift?

View File

@@ -273,9 +273,9 @@
544B011B2114EE9100386E5C /* AppHook.h */,
544B011C2114EE9100386E5C /* AppHook.m */,
541958872190FF1200581B79 /* Constants.h */,
544936F721F1E51E00DEE9AA /* Helper */,
541A90EF21257D4F002680A6 /* Status Bar Menu */,
54A07A8322105E0800082C51 /* Core Data */,
544936F721F1E51E00DEE9AA /* Helper */,
546FC44D2118B357007CC3A3 /* Preferences */,
54ACC28521061B3C0020715F /* Assets.xcassets */,
54ACC28A21061B3C0020715F /* Info.plist */,

View File

@@ -38,10 +38,13 @@
+ (void)scheduleUpdateForUpcomingFeeds;
+ (void)forceUpdateAllFeeds;
// Downloading
+ (void)newFeed:(NSString *)urlStr askUser:(nonnull NSString*(^)(NSArray<RSHTMLMetadataFeedLink*> *list))askUser block:(nonnull void(^)(RSParsedFeed *parsed, NSError *error, NSHTTPURLResponse *response))block;
+ (void)newFeed:(NSString *)urlStr askUser:(nonnull NSString*(^)(RSHTMLMetadata *meta))askUser block:(nonnull void(^)(RSParsedFeed *parsed, NSError *error, NSHTTPURLResponse *response))block;
+ (void)autoDownloadAndParseURL:(NSString*)urlStr;
+ (void)downloadFavicon:(NSString*)urlStr finished:(void(^)(NSImage * _Nullable img))block;
+ (void)batchDownloadFeeds:(NSArray<Feed*> *)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;
+ (void)downloadImage:(NSString*)url finished:(void(^)(NSImage * _Nullable img))block;
+ (nullable NSString*)faviconUrlForMetadata:(RSHTMLMetadata*)meta;
@end

View File

@@ -247,7 +247,7 @@ static BOOL _nextUpdateIsForced = NO;
@param askUser Use @c list to present user a list of detected feed URLs.
@param block Called after webpage has been fully parsed (including html autodetect).
*/
+ (void)newFeed:(NSString *)urlStr askUser:(nonnull NSString*(^)(NSArray<RSHTMLMetadataFeedLink*> *list))askUser block:(nonnull void(^)(RSParsedFeed *parsed, NSError *error, NSHTTPURLResponse *response))block {
+ (void)newFeed:(NSString *)urlStr askUser:(nonnull NSString*(^)(RSHTMLMetadata *meta))askUser block:(nonnull void(^)(RSParsedFeed *parsed, NSError *error, NSHTTPURLResponse *response))block {
[self parseFeedRequest:[self newRequestURL:urlStr] xmlBlock:^BOOL(RSXMLData *xml, NSError **err) {
if (![xml.parserClass isHTMLParser])
return NO;
@@ -261,7 +261,7 @@ static BOOL _nextUpdateIsForced = NO;
}
__block NSString *chosenURL = nil;
dispatch_sync(dispatch_get_main_queue(), ^{ // sync! (thread is already in background)
chosenURL = askUser(parsedMeta.feedLinks);
chosenURL = askUser(parsedMeta);
});
if (!chosenURL || chosenURL.length == 0)
return NO;
@@ -441,7 +441,7 @@ static BOOL _nextUpdateIsForced = NO;
}
/// Extract favicon URL from parsed HTML metadata.
+ (NSString*)faviconUrlForMetadata:(RSHTMLMetadata*)meta {
+ (nullable NSString*)faviconUrlForMetadata:(RSHTMLMetadata*)meta {
if (meta) {
if (meta.faviconLink.length > 0) {
return meta.faviconLink;

View File

@@ -76,6 +76,7 @@
@property (copy) NSString *previousURL; // check if changed and avoid multiple download
@property (copy) NSString *httpDate;
@property (copy) NSString *httpEtag;
@property (copy) NSString *faviconURL;
@property (strong) NSImage *favicon;
@property (strong) NSError *feedError; // download error or xml parser error
@property (strong) RSParsedFeed *feedResult; // parsed result
@@ -148,6 +149,7 @@
self.httpEtag = nil;
self.httpDate = nil;
self.favicon = nil;
self.faviconURL = nil;
}
/**
@@ -159,8 +161,9 @@
if (self.modalSheet.didCloseAndCancel)
return;
[self preDownload];
[FeedDownload newFeed:self.previousURL askUser:^NSString *(NSArray<RSHTMLMetadataFeedLink *> *list) {
return [self letUserChooseXmlUrlFromList:list];
[FeedDownload newFeed:self.previousURL askUser:^NSString *(RSHTMLMetadata *meta) {
self.faviconURL = [FeedDownload faviconUrlForMetadata:meta]; // we can re-use favicon url if we find one
return [self letUserChooseXmlUrlFromList:meta.feedLinks];
} block:^(RSParsedFeed *result, NSError *error, NSHTTPURLResponse* response) {
if (self.modalSheet.didCloseAndCancel)
return;
@@ -222,10 +225,11 @@
if (self.feedError) {
[self finishDownloadWithFavicon:[NSImage imageNamed:NSImageNameCaution]];
} else {
NSString *faviconURL = self.feedResult.link;
if (faviconURL.length == 0)
faviconURL = responseURL;
[FeedDownload downloadFavicon:faviconURL finished:^(NSImage * _Nullable img) {
if (!self.faviconURL)
self.faviconURL = self.feedResult.link;
if (self.faviconURL.length == 0)
self.faviconURL = responseURL;
[FeedDownload downloadFavicon:self.faviconURL finished:^(NSImage * _Nullable img) {
if (self.modalSheet.didCloseAndCancel)
return;
self.favicon = img;