summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--offline.js37
-rw-r--r--tt-rss.js25
-rw-r--r--viewfeed.js10
3 files changed, 55 insertions, 17 deletions
diff --git a/offline.js b/offline.js
index c192c5966..ff09b7167 100644
--- a/offline.js
+++ b/offline.js
@@ -567,6 +567,7 @@ function render_offline_feedlist() {
function init_offline() {
try {
offline_mode = true;
+ store.enabled = true;
Element.hide("dispSwitchPrompt");
Element.hide("feedBrowserPrompt");
@@ -852,6 +853,7 @@ function update_offline_data(stage) {
}
offlineSyncShowHideElems(true);
+ offlineUpdateStore();
sync_in_progress = true;
@@ -1039,6 +1041,7 @@ function init_gears() {
store = localServer.createManagedStore("tt-rss");
store.manifestUrl = "manifest.json.php";
+ store.enabled = false;
db = google.gears.factory.create('beta.database');
db.open('tt-rss');
@@ -1146,6 +1149,7 @@ function gotoOffline() {
if (confirm(__("Switch Tiny Tiny RSS into offline mode?"))) {
+ store.enabled = true;
store.checkForUpdate();
notify_progress("Preparing offline mode...", true);
@@ -1158,7 +1162,6 @@ function gotoOffline() {
//window.location.href = "tt-rss.php";
offlineDownloadStop();
- offline_mode = true;
init_offline();
notify_info("Tiny Tiny RSS is in offline mode.");
@@ -1171,8 +1174,9 @@ function gotoOffline() {
}
function gotoOnline() {
- if (confirm(__("You won't be able to access offline version of Tiny Tiny RSS until you switch it into offline mode again. Go online?"))) {
- localServer.removeManagedStore("tt-rss");
+// if (confirm(__("You won't be able to access offline version of Tiny Tiny RSS until you switch it into offline mode again. Go online?"))) {
+ if (confirm(__("Tiny Tiny RSS will reload. Go online?"))) {
+ //localServer.removeManagedStore("tt-rss");
window.location.href = "tt-rss.php";
}
}
@@ -1640,8 +1644,17 @@ function offlineClearData() {
function offlineUpdateStore() {
try {
+ if (offline_mode || !store) return;
- if (offline_mode) return;
+ store.checkForUpdate();
+
+ var timerId = window.setInterval(function() {
+ if (store.currentVersion) {
+ window.clearInterval(timerId);
+ debug("[Local store] sync complete: " + store.currentVersion);
+ } else if (store.updateStatus == 3) {
+ debug("[Local store] sync error: " + store.lastErrorMessage);
+ } }, 500);
} catch (e) {
exception_error("offlineUpdateStore", e);
@@ -1675,3 +1688,19 @@ function offlineSyncShowHideElems(syncing) {
exception_error("offlineSyncShowHideElems", e);
}
}
+
+function offlineConfirmModeChange() {
+ try {
+
+ if (db) {
+ var ok = confirm(__("Tiny Tiny RSS has trouble accessing its server. Would you like to go offline?"));
+
+ if (ok) {
+ init_offline();
+ }
+ }
+
+ } catch (e) {
+ exception_error("offlineConfirmModeChange", e);
+ }
+}
diff --git a/tt-rss.js b/tt-rss.js
index fbfde92d4..f6eea6661 100644
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -132,8 +132,14 @@ function backend_sanity_check_callback(transport) {
}
if (!transport.responseXML) {
- fatalError(3, "Sanity check: Received reply is not XML", transport.responseText);
- return;
+ if (!store) {
+ fatalError(3, "Sanity check: Received reply is not XML",
+ transport.responseText);
+ return;
+ } else {
+ init_offline();
+ return;
+ }
}
var reply = transport.responseXML.firstChild.firstChild;
@@ -397,17 +403,10 @@ function init() {
loading_set_progress(30);
- offline_mode = false;
- if (store) offline_mode = store.currentVersion;
-
- if (offline_mode) {
- init_offline();
- } else {
- new Ajax.Request("backend.php?op=rpc&subop=sanityCheck" + params, {
- onComplete: function(transport) {
- backend_sanity_check_callback(transport);
- } });
- }
+ new Ajax.Request("backend.php?op=rpc&subop=sanityCheck" + params, {
+ onComplete: function(transport) {
+ backend_sanity_check_callback(transport);
+ } });
} catch (e) {
exception_error("init", e);
diff --git a/viewfeed.js b/viewfeed.js
index fa7c56b5f..339950cac 100644
--- a/viewfeed.js
+++ b/viewfeed.js
@@ -48,6 +48,11 @@ function clean_feed_selections() {
function headlines_callback2(transport, feed_cur_page) {
try {
+ if (!transport.responseText && db) {
+ offlineConfirmModeChange();
+ return;
+ }
+
loading_set_progress(100);
debug("headlines_callback2 [page=" + feed_cur_page + "]");
@@ -312,6 +317,11 @@ function article_callback2(transport, id, feed_id) {
try {
debug("article_callback2 " + id);
+ if (!transport.responseText && db) {
+ offlineConfirmModeChange();
+ return;
+ }
+
if (transport.responseXML) {
if (!transport_error_check(transport)) return;