From bc1c99354f037294201a669b86b97a8f57fc75b6 Mon Sep 17 00:00:00 2001 From: Alvarord Date: Tue, 29 Apr 2014 04:56:43 +0200 Subject: [PATCH 1/2] Adding identificator to show it in the interface, developing branch. --- manifest.webapp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.webapp b/manifest.webapp index 2149404..c4926f4 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -19,5 +19,5 @@ } }, "installs_allowed_from": ["*"], - "version": "0.3.0" -} \ No newline at end of file + "version": "0.3.0_iss30" +} From cfad4d4f4d4bd8fe547a7d78b997513eea0cb4e8 Mon Sep 17 00:00:00 2001 From: AlvaroRD Date: Tue, 6 May 2014 00:12:59 +0200 Subject: [PATCH 2/2] Added 2 parameters to limit the download size, and how many articles are downloaded by request to the server. Alerts to detect size download anytime you connect to the server. This patch catch any exception in case data is not able to be stored in localStorage --- js/App.js | 59 ++++++++++++++++++++++++++++++++++++++++++----- js/OwnCloud.js | 8 +++---- js/Pond.js | 10 ++++---- js/TinyTinyRSS.js | 7 +++--- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/js/App.js b/js/App.js index c874b84..37fb558 100644 --- a/js/App.js +++ b/js/App.js @@ -7,6 +7,13 @@ function App() { if(!color) color = "red"; this.setColor(color); this.fontChange(); + + var numArticles = localStorage.numArticles; + if(!numArticles) numArticles = 50; + this.numArticles(numArticles); + var maxDownload = localStorage.maxDownload; + if(!maxDownload) maxDownload = 500000; + this.maxDownload(maxDownload); }; App.prototype.authenticate = function() { @@ -99,6 +106,14 @@ App.prototype.after_login = function(backend) { } else { this.backend = new TinyTinyRSS(this, localStorage.server_url, localStorage.session_id); } + + var numArticles = localStorage.numArticles; + if(!numArticles) numArticles = 50; + this.numArticles(numArticles); + var maxDownload = localStorage.maxDownload; + if(!maxDownload) maxDownload = 500000; + this.maxDownload(maxDownload); + this.reload(); }; @@ -137,7 +152,8 @@ App.prototype.setColor = function(color) { App.prototype.reload = function() { this.unread_articles = []; $("#all-read").innerHTML = "❌"; - this.backend.reload(this.gotUnreadFeeds.bind(this)); + var number=parseInt(localStorage.numArticles); + this.backend.reload(this.gotUnreadFeeds.bind(this),number); }; App.prototype.gotUnreadFeeds = function(new_articles) { @@ -155,11 +171,25 @@ App.prototype.gotUnreadFeeds = function(new_articles) { this.unread_articles = this.unread_articles.concat(new_articles); if(new_articles.length > 0) { - this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles); - } else { - localStorage.unread_articles = JSON.stringify(this.unread_articles); + try { + //To check if when it fails it is the same + localStorage.unread_articles = JSON.stringify(this.unread_articles); + //alert("Size probando:"+probando.length) + var size = parseInt(localStorage.maxDownload); + if(localStorage.unread_articles.length < size) { + var num = parseInt(localStorage.numArticles); + this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles,num); + } else { + alert("Limit size reached: Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length +" bytes"); + } + } + catch (e) { + alert("Reached maximum memory by app" + e.name + " " +e.message +". We will keep working in anycase with:" + localStorage.unread_articles.length); + } this.populateList(); - } + } else { + alert("Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length + " bytes"); + } } }; @@ -445,5 +475,22 @@ App.prototype.fontChange = function(size) { document.body.addClass("f" + i); } - +}; + +App.prototype.numArticles= function(askfor) { + if(askfor < 200 && askfor > 0) { + localStorage.numArticles=askfor; + } + else { + localStorage.numArticles=100; + } +}; + +App.prototype.maxDownload= function(maxdata) { + if(maxdata < 5000000 && maxdata > 100000) { + localStorage.maxDownload=maxdata; + } + else { + localStorage.maxDownload=500000; + } }; diff --git a/js/OwnCloud.js b/js/OwnCloud.js index 15776f1..25519eb 100644 --- a/js/OwnCloud.js +++ b/js/OwnCloud.js @@ -65,18 +65,18 @@ OwnCloud.prototype.doOperation = function(method, operation, new_options, callba xhr.send(body); } -OwnCloud.prototype.reload = function(callback) { +OwnCloud.prototype.reload = function(callback,limit) { var _this = this; - this.getFeeds(function() { _this.getUnreadFeeds(callback); }); + this.getFeeds(function() { _this.getUnreadFeeds(callback,0,limit); }); }; -OwnCloud.prototype.getUnreadFeeds = function(callback, skip) { +OwnCloud.prototype.getUnreadFeeds = function(callback, skip, limit) { if(skip) { skip = skip[skip.length - 1].id; } var options = { - batchSize: 700, + batchSize: limit || 700, offset: skip || 0, type: 3, id: 0, diff --git a/js/Pond.js b/js/Pond.js index 501494c..47cc5a5 100644 --- a/js/Pond.js +++ b/js/Pond.js @@ -69,15 +69,15 @@ Pond.prototype.doOperation = function(method, operation, new_options, callback) }; -Pond.prototype.reload = function(callback) { +Pond.prototype.reload = function(callback,limit) { var _this = this; - this.getFeeds(function() { _this.getUnreadFeeds(callback); }); + this.getFeeds(function() { _this.getUnreadFeeds(callback,0,limit); }); }; -Pond.prototype.getUnreadFeeds = function(callback, skip) { +Pond.prototype.getUnreadFeeds = function(callback, skip, limit) { var options = { status: "unread", - limit: 100 + limit: limit || 100 }; if(skip && skip.length > 0) { @@ -222,4 +222,4 @@ Pond.login = function(server_url, user, password, callback) { xhr.setRequestHeader("Content-Length", options.length); xhr.setRequestHeader("Connection", "close"); xhr.send(options); -} \ No newline at end of file +} diff --git a/js/TinyTinyRSS.js b/js/TinyTinyRSS.js index 4479f49..1fd2813 100644 --- a/js/TinyTinyRSS.js +++ b/js/TinyTinyRSS.js @@ -54,17 +54,18 @@ TinyTinyRSS.prototype.doOperation = function(operation, new_options, callback) { xhr.send(JSON.stringify(options)); } -TinyTinyRSS.prototype.reload = function(callback) { - this.getUnreadFeeds(callback, []); +TinyTinyRSS.prototype.reload = function(callback,limit) { + this.getUnreadFeeds(callback, 0, limit); }; -TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip) { +TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip, limit) { skip = skip.length; var options = { show_excerpt: false, view_mode: "unread", show_content: true, feed_id: -4, + limit: limit || 0, skip: skip || 0 };