rework gears offline/online interaction the way it probably should be done (also remove redirecting login system)

This commit is contained in:
Andrew Dolgov 2009-02-12 20:16:10 +03:00
parent b4dc02e207
commit 206d496762
5 changed files with 68 additions and 29 deletions

View File

@ -1508,7 +1508,7 @@ function fatalError(code, msg, ext_info) {
if (!ext_info) ext_info = "N/A"; if (!ext_info) ext_info = "N/A";
if (code == 6) { if (code == 6) {
window.location.href = "login.php"; window.location.href = "tt-rss.php";
} else if (code == 5) { } else if (code == 5) {
window.location.href = "update.php"; window.location.href = "update.php";
} else { } else {

View File

@ -1918,8 +1918,8 @@
} }
if (!$_SESSION["uid"] || !validate_session($link)) { if (!$_SESSION["uid"] || !validate_session($link)) {
//render_login_form($link, $mobile); render_login_form($link, $mobile);
header("Location: login.php"); //header("Location: login.php");
exit; exit;
} else { } else {
/* bump login timestamp */ /* bump login timestamp */

View File

@ -6,6 +6,7 @@ var localServer = false;
var db = false; var db = false;
var articles_synced = 0; var articles_synced = 0;
var sync_in_progress = false; var sync_in_progress = false;
var sync_timer = false;
function view_offline(id, feed_id) { function view_offline(id, feed_id) {
try { try {
@ -617,6 +618,8 @@ function offline_download_parse(stage, transport) {
try { try {
if (transport.responseXML) { if (transport.responseXML) {
if (!sync_in_progress) return;
var sync_ok = transport.responseXML.getElementsByTagName("sync-ok"); var sync_ok = transport.responseXML.getElementsByTagName("sync-ok");
if (sync_ok.length > 0) { if (sync_ok.length > 0) {
@ -681,7 +684,7 @@ function offline_download_parse(stage, transport) {
[id, caption, fg_color, bg_color]); [id, caption, fg_color, bg_color]);
} }
window.setTimeout("update_offline_data("+(stage+1)+")", 1*1000); sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", 10*1000);
} else { } else {
var articles = transport.responseXML.getElementsByTagName("article"); var articles = transport.responseXML.getElementsByTagName("article");
@ -731,11 +734,12 @@ function offline_download_parse(stage, transport) {
var has_sync_data = has_local_sync_data(); var has_sync_data = has_local_sync_data();
if (articles_found >= limit || has_sync_data) { if (articles_found >= limit || has_sync_data) {
window.setTimeout("update_offline_data("+(stage+1)+")", 5*1000); sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")",
5*1000);
debug("<b>update_offline_data: done " + stage + " HSD: " + debug("<b>update_offline_data: done " + stage + " HSD: " +
has_sync_data + "</b>"); has_sync_data + "</b>");
} else { } else {
window.setTimeout("update_offline_data(0)", 180*1000); window.setTimeout("offlineDownloadStart()", 180*1000);
debug("update_offline_data: finished"); debug("update_offline_data: finished");
var pic = $("offlineModePic"); var pic = $("offlineModePic");
@ -1017,10 +1021,6 @@ function enable_offline_reading() {
try { try {
if (db && getInitParam("offline_enabled") == "1") { if (db && getInitParam("offline_enabled") == "1") {
store.manifestUrl = "manifest.json.php";
store.checkForUpdate();
init_local_sync_data(); init_local_sync_data();
Element.show("offlineModePic"); Element.show("offlineModePic");
offlineDownloadStart(); offlineDownloadStart();
@ -1037,6 +1037,7 @@ function init_gears() {
if (window.google && google.gears) { if (window.google && google.gears) {
localServer = google.gears.factory.create("beta.localserver"); localServer = google.gears.factory.create("beta.localserver");
store = localServer.createManagedStore("tt-rss"); store = localServer.createManagedStore("tt-rss");
store.manifestUrl = "manifest.json.php";
db = google.gears.factory.create('beta.database'); db = google.gears.factory.create('beta.database');
db.open('tt-rss'); db.open('tt-rss');
@ -1126,12 +1127,32 @@ function init_gears() {
} }
function gotoOffline() { function gotoOffline() {
window.location.href = "tt-rss.php?offline=1";
// debug("[Local store] currentVersion = " + store.currentVersion);
if (confirm(__("Switch Tiny Tiny RSS into offline mode?"))) {
store.checkForUpdate();
notify_progress("Preparing offline mode...");
var timerId = window.setInterval(function() {
if (store.currentVersion) {
window.clearInterval(timerId);
//debug("[Local store] sync complete: " + store.currentVersion);
window.location.href = "tt-rss.php";
} else if (store.updateStatus == 3) {
debug("[Local store] sync error: " + store.lastErrorMessage);
} }, 500);
}
} }
function gotoOnline() { 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");
window.location.href = "tt-rss.php"; window.location.href = "tt-rss.php";
} }
}
function local_collapse_cat(id) { function local_collapse_cat(id) {
try { try {
@ -1542,6 +1563,16 @@ function offlineDownloadStart() {
} }
} }
function offlineDownloadStop() {
try {
if (db && sync_in_progress && getInitParam("offline_enabled") == "1") {
window.clearTimeout(sync_timer);
}
} catch (e) {
exception_error("offlineDownloadStart", e);
}
}
function offlineClearData() { function offlineClearData() {
try { try {
if (db) { if (db) {
@ -1564,3 +1595,13 @@ function offlineClearData() {
exception_error("offlineClearData", e); exception_error("offlineClearData", e);
} }
} }
function offlineUpdateStore() {
try {
if (offline_mode) return;
} catch (e) {
exception_error("offlineUpdateStore", e);
}
}

View File

@ -132,18 +132,10 @@ function backend_sanity_check_callback(transport) {
} }
if (!transport.responseXML) { if (!transport.responseXML) {
if (!window.google && !google.gears) {
fatalError(3, "Sanity check: Received reply is not XML", transport.responseText); fatalError(3, "Sanity check: Received reply is not XML", transport.responseText);
} else {
init_offline();
}
return; return;
} }
if (getURLParam("offline")) {
return init_offline();
}
var reply = transport.responseXML.firstChild.firstChild; var reply = transport.responseXML.firstChild.firstChild;
if (!reply) { if (!reply) {
@ -405,10 +397,17 @@ function init() {
loading_set_progress(30); 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, { new Ajax.Request("backend.php?op=rpc&subop=sanityCheck" + params, {
onComplete: function(transport) { onComplete: function(transport) {
backend_sanity_check_callback(transport); backend_sanity_check_callback(transport);
} }); } });
}
} catch (e) { } catch (e) {
exception_error("init", e); exception_error("init", e);

View File

@ -146,7 +146,7 @@ window.onload = init;
<div class="hideWhenSyncing"><a href="javascript:offlineClearData()"> <div class="hideWhenSyncing"><a href="javascript:offlineClearData()">
<?php echo __('Remove offline data') ?></a></div> <?php echo __('Remove offline data') ?></a></div>
<div><a href="javascript:gotoOffline()"> <div><a href="javascript:gotoOffline()">
<?php echo __('Restart in offline mode') ?></a></div> <?php echo __('Go offline') ?></a></div>
</div> </div>
<img id="newVersionIcon" style="display:none;" onclick="javascript:explainError(2)" <img id="newVersionIcon" style="display:none;" onclick="javascript:explainError(2)"
@ -157,8 +157,7 @@ window.onload = init;
<span id="topLinksOffline" style="display : none"> <span id="topLinksOffline" style="display : none">
<img id="restartOnlinePic" src="images/online.png" <img id="restartOnlinePic" src="images/online.png"
onclick="gotoOnline()" onclick="gotoOnline()" title="<?php echo __('Go online') ?>"/>
title="<?php echo __('Restart in online mode') ?>"/>
</span> </span>
</div> </div>