]> git.wh0rd.org - tt-rss.git/commitdiff
offline: try to keep local server info ready for offline mode
authorAndrew Dolgov <fox@bah.org.ru>
Thu, 12 Feb 2009 21:12:18 +0000 (00:12 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Thu, 12 Feb 2009 21:12:18 +0000 (00:12 +0300)
offline.js
tt-rss.js
viewfeed.js

index c192c59661779979cbda99d3dbc2f4aa47a57ae0..ff09b7167aafe2d84c54fada8fc212ecc66a588a 100644 (file)
@@ -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);
+       }
+}
index fbfde92d4394e456b4213ce4057486b5d300766b..f6eea6661ea35575aa69d71ad12cf3ebeeec03f5 100644 (file)
--- 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);
index fa7c56b5f7b98825280ae71b55520e3d9f4ecfa4..339950caca31a9e3859ec6294c0915fa45176427 100644 (file)
@@ -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;