1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 15:15:56 +00:00

further objectification of JS code

This commit is contained in:
Andrew Dolgov
2018-12-01 17:21:26 +03:00
parent 049a37aa0e
commit d86ddbc635
7 changed files with 345 additions and 359 deletions

View File

@@ -4,15 +4,7 @@ let _widescreen_mode = false;
let hotkey_actions = {};
const App = {
_rpc_seq: 0,
global_unread: -1,
next_seq: function() {
this._rpc_seq += 1;
return this._rpc_seq;
},
get_seq: function() {
return this._rpc_seq;
},
updateTitle: function() {
let tmp = "Tiny Tiny RSS";
@@ -85,126 +77,6 @@ const App = {
xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0});
},
parseRuntimeInfo: function(data) {
//console.log("parsing runtime info...");
for (const k in data) {
const v = data[k];
if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
window.location.reload();
}
}
if (k == "daemon_is_running" && v != 1) {
notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
return;
}
if (k == "update_result") {
const updatesIcon = dijit.byId("updatesIcon").domNode;
if (v) {
Element.show(updatesIcon);
} else {
Element.hide(updatesIcon);
}
}
if (k == "daemon_stamp_ok" && v != 1) {
notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
return;
}
if (k == "max_feed_id" || k == "num_feeds") {
if (init_params[k] != v) {
console.log("feed count changed, need to reload feedlist.");
Feeds.reload();
}
}
init_params[k] = v;
notify('');
}
PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
},
handleRpcJson: function(transport) {
const netalert_dijit = dijit.byId("net-alert");
let netalert = false;
if (netalert_dijit) netalert = netalert_dijit.domNode;
try {
const reply = JSON.parse(transport.responseText);
if (reply) {
const error = reply['error'];
if (error) {
const code = error['code'];
const msg = error['msg'];
console.warn("[handleRpcJson] received fatal error " + code + "/" + msg);
if (code != 0) {
fatalError(code, msg);
return false;
}
}
const seq = reply['seq'];
if (seq && this.get_seq() != seq) {
console.log("[handleRpcJson] sequence mismatch: " + seq +
" (want: " + this.get_seq() + ")");
return true;
}
const message = reply['message'];
if (message == "UPDATE_COUNTERS") {
console.log("need to refresh counters...");
setInitParam("last_article_id", -1);
Feeds.requestCounters(true);
}
const counters = reply['counters'];
if (counters)
Feeds.parseCounters(counters);
const runtime_info = reply['runtime-info'];
if (runtime_info)
this.parseRuntimeInfo(runtime_info);
if (netalert) netalert.hide();
return reply;
} else {
if (netalert)
netalert.show();
else
notify_error("Communication problem with server.");
}
} catch (e) {
if (netalert)
netalert.show();
else
notify_error("Communication problem with server.");
console.error(e);
}
return false;
},
};
function search() {
@@ -459,7 +331,7 @@ function init_hotkey_actions() {
};
hotkey_actions["feed_catchup"] = function() {
if (Feeds.getActiveFeedId() != undefined) {
catchupCurrentFeed();
Feeds.catchupCurrentFeed();
return;
}
};
@@ -677,7 +549,7 @@ function quickMenuGo(opid) {
return;
}
var fn = getFeedName(actid);
var fn = Feeds.getFeedName(actid);
var pr = __("Unsubscribe from %s?").replace("%s", fn);
@@ -743,7 +615,7 @@ function update_random_feed() {
console.log("in update_random_feed");
xhrPost("backend.php", { op: "rpc", method: "updateRandomFeed" }, (transport) => {
App.handleRpcJson(transport, true);
Utils.handleRpcJson(transport, true);
window.setTimeout(update_random_feed, 30*1000);
});
}