offline: try to keep local server info ready for offline mode

This commit is contained in:
Andrew Dolgov 2009-02-13 00:12:18 +03:00
parent a970edb1a2
commit 9ca945a6d2
3 changed files with 55 additions and 17 deletions

View 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);
}
}

View File

@ -132,8 +132,14 @@ function backend_sanity_check_callback(transport) {
}
if (!transport.responseXML) {
fatalError(3, "Sanity check: Received reply is not XML", transport.responseText);
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);
} });
}
} catch (e) {
exception_error("init", e);

View 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;