From 9b65f77accacc6a373e6fbb951b20cda4f869d72 Mon Sep 17 00:00:00 2001 From: Jakub Szwacz Date: Fri, 15 Nov 2013 20:27:34 +0100 Subject: [PATCH] favicons loading amended --- app/controllers/appCtrl.js | 9 +++++---- app/services/faviconsService.js | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/appCtrl.js b/app/controllers/appCtrl.js index 01b9ec2..a6b507f 100644 --- a/app/controllers/appCtrl.js +++ b/app/controllers/appCtrl.js @@ -50,10 +50,7 @@ function AppCtrl($scope, $location, config, feedsService, articlesService, favic $scope.$on('feedSiteUrlSpecified', function (evt, feed) { // is siteUrl first time specified try to get its favicon - faviconsService.updateOne(feed) - .then(function () { - $scope.$apply(); - }); + faviconsService.updateOne(feed); }); $scope.$on('feedRemoved', function (evt, feed) { @@ -70,6 +67,10 @@ function AppCtrl($scope, $location, config, feedsService, articlesService, favic $scope.allTags = articlesService.allTags; }); + $scope.$on('faviconUpdated', function (evt) { + $scope.$apply(); + }); + //----------------------------------------------------- // Preserving window size //----------------------------------------------------- diff --git a/app/services/faviconsService.js b/app/services/faviconsService.js index ef34af0..09f7563 100644 --- a/app/services/faviconsService.js +++ b/app/services/faviconsService.js @@ -1,6 +1,6 @@ 'use strict'; -sputnik.factory('faviconsService', function (config, net) { +sputnik.factory('faviconsService', function (config, net, $rootScope) { var cheerio = require('cheerio'); var urlUtil = require('url'); @@ -16,6 +16,9 @@ sputnik.factory('faviconsService', function (config, net) { if (!href) { href = dom('link[rel="shortcut icon"]').attr('href'); } + if (!href) { + href = dom('link[rel="Shortcut Icon"]').attr('href'); + } if (href && !href.match(/^http/)) { // is relative, so make absolute href = urlUtil.resolve(siteUrl, href); } @@ -109,6 +112,7 @@ sputnik.factory('faviconsService', function (config, net) { var filePath = storeDir + '/' + filename; fs.writeFile(filePath, result.faviconBytes, function (err) { feed.favicon = filePath; + $rootScope.$broadcast('faviconUpdated'); deferred.resolve(); }); }, function () { @@ -121,9 +125,15 @@ sputnik.factory('faviconsService', function (config, net) { } function updateMany(feeds) { - feeds.forEach(function (feed) { - updateOne(feed); - }); + feeds = feeds.concat(); + + function next() { + if (feeds.length > 0) { + updateOne(feeds.pop()).then(next); + } + } + + next(); } return {