summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-16 19:05:37 +0300
committerAndrew Dolgov <[email protected]>2018-12-16 19:05:37 +0300
commit957c44d177e6577e2f3b98560c8f2b67883806d4 (patch)
treeb0f4de5b06289d68c841f00e720ce7bef3165b0f
parentc3b8b6a2a19102f958a9e4c2c007d83abe52ef9b (diff)
rework git update checking to be initiated by frontend, outside of runtime info output
-rwxr-xr-xclasses/rpc.php25
-rwxr-xr-xinclude/functions.php33
-rw-r--r--js/AppBase.js8
-rw-r--r--js/tt-rss.js20
4 files changed, 46 insertions, 40 deletions
diff --git a/classes/rpc.php b/classes/rpc.php
index 61212fe8b..eb6fd4895 100755
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -324,7 +324,7 @@ class RPC extends Handler_Protected {
if ($reply['error']['code'] == 0) {
$reply['init-params'] = make_init_params();
- $reply['runtime-info'] = make_runtime_info(true);
+ $reply['runtime-info'] = make_runtime_info();
}
print json_encode($reply);
@@ -597,4 +597,27 @@ class RPC extends Handler_Protected {
}
}
+
+ function checkforupdates() {
+ $rv = [];
+
+ if (CHECK_FOR_UPDATES && defined("GIT_VERSION_TIMESTAMP")) {
+ $content = @fetch_file_contents(["url" => "https://tt-rss.org/version.json"]);
+
+ if ($content) {
+ $content = json_decode($content, true);
+
+ if ($content && isset($content["changeset"])) {
+ if ((int)GIT_VERSION_TIMESTAMP < (int)$content["changeset"]["timestamp"] &&
+ GIT_VERSION_HEAD != $content["changeset"]["id"]) {
+
+ $rv = $content["changeset"];
+ }
+ }
+ }
+ }
+
+ print json_encode($rv);
+ }
+
} \ No newline at end of file
diff --git a/include/functions.php b/include/functions.php
index d5095b071..1d83a41da 100755
--- a/include/functions.php
+++ b/include/functions.php
@@ -679,8 +679,6 @@
$_SESSION["user_agent"] = sha1($_SERVER['HTTP_USER_AGENT']);
$_SESSION["pwd_hash"] = $row["pwd_hash"];
- $_SESSION["last_version_check"] = time();
-
initialize_user_prefs($_SESSION["uid"]);
return true;
@@ -1068,6 +1066,7 @@
$params[strtolower($param)] = (int) get_pref($param);
}
+ $params["check_for_updates"] = CHECK_FOR_UPDATES;
$params["icons_url"] = ICONS_URL;
$params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME;
$params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE");
@@ -1270,27 +1269,7 @@
return array($prefixes, $hotkeys);
}
- function check_for_update() {
- if (defined("GIT_VERSION_TIMESTAMP")) {
- $content = @fetch_file_contents(array("url" => "http://tt-rss.org/version.json", "timeout" => 5));
-
- if ($content) {
- $content = json_decode($content, true);
-
- if ($content && isset($content["changeset"])) {
- if ((int)GIT_VERSION_TIMESTAMP < (int)$content["changeset"]["timestamp"] &&
- GIT_VERSION_HEAD != $content["changeset"]["id"]) {
-
- return $content["changeset"]["id"];
- }
- }
- }
- }
-
- return "";
- }
-
- function make_runtime_info($disable_update_check = false) {
+ function make_runtime_info() {
$data = array();
$pdo = Db::pdo();
@@ -1323,14 +1302,6 @@
}
}
- if (CHECK_FOR_UPDATES && !$disable_update_check && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
- $update_result = @check_for_update();
-
- $data["update_result"] = $update_result;
-
- $_SESSION["last_version_check"] = time();
- }
-
if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
$data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
diff --git a/js/AppBase.js b/js/AppBase.js
index bb2c3cbcc..121b7aa85 100644
--- a/js/AppBase.js
+++ b/js/AppBase.js
@@ -262,14 +262,6 @@ define(["dojo/_base/declare"], function (declare) {
return;
}
- if (k == "update_result") {
- if (v) {
- Element.show("updates-available");
- } else {
- Element.hide("updates-available");
- }
- }
-
if (k == "recent_log_events") {
const alert = $$(".log-alert")[0];
diff --git a/js/tt-rss.js b/js/tt-rss.js
index 7635e3a83..99b44549b 100644
--- a/js/tt-rss.js
+++ b/js/tt-rss.js
@@ -163,11 +163,31 @@ require(["dojo/_base/kernel",
window.setInterval(() => { Feeds.updateRandom() }, 30 * 1000);
}
+ if (App.getInitParam('check_for_updates')) {
+ window.setInterval(() => {
+ App.checkForUpdates();
+ }, 3600 * 1000);
+ }
+
console.log("second stage ok");
PluginHost.run(PluginHost.HOOK_INIT_COMPLETE, null);
},
+ checkForUpdates: function() {
+ console.log('checking for updates...');
+
+ xhrJson("backend.php", {op: 'rpc', method: 'checkforupdates'})
+ .then((reply) => {
+ console.log('update reply', reply);
+
+ if (reply.id) {
+ $("updates-available").show();
+ } else {
+ $("updates-available").hide();
+ }
+ });
+ },
updateTitle: function() {
let tmp = "Tiny Tiny RSS";