add plugin updates checker into normal updates checker

This commit is contained in:
Andrew Dolgov 2021-02-27 19:14:13 +03:00
parent d821e4b090
commit 7f2fe465b0
10 changed files with 72 additions and 21 deletions

View File

@ -1093,7 +1093,28 @@ class Pref_Prefs extends Handler_Protected {
set_pref(Prefs::_ENABLED_PLUGINS, $plugins);
}
private function _plugin_needs_update($root_dir, $plugin_name) {
static function _get_updated_plugins() {
$root_dir = dirname(dirname(__DIR__)); # we're in classes/pref/
$plugin_dirs = array_filter(glob("$root_dir/plugins.local/*"), "is_dir");
$rv = [];
foreach ($plugin_dirs as $dir) {
if (is_dir("$dir/.git")) {
$plugin_name = basename($dir);
array_push($rv, ["plugin" => $plugin_name, "rv" => self::_plugin_needs_update($root_dir, $plugin_name)]);
}
}
$rv = array_values(array_filter($rv, function ($item) {
return !empty($item["rv"]["o"]);
}));
return $rv;
}
private static function _plugin_needs_update($root_dir, $plugin_name) {
$plugin_dir = "$root_dir/plugins.local/" . basename($plugin_name);
$rv = [];
@ -1150,23 +1171,12 @@ class Pref_Prefs extends Handler_Protected {
if ($_SESSION["access_level"] >= 10) {
$plugin_name = $_REQUEST["name"] ?? "";
# we're in classes/pref/
$root_dir = dirname(dirname(__DIR__));
$rv = [];
$root_dir = dirname(dirname(__DIR__)); # we're in classes/pref/
if (!empty($plugin_name)) {
array_push($rv, ["plugin" => $plugin_name, "rv" => $this->_plugin_needs_update($root_dir, $plugin_name)]);
$rv = ["plugin" => $plugin_name, "rv" => self::_plugin_needs_update($root_dir, $plugin_name)];
} else {
$plugin_dirs = array_filter(glob("$root_dir/plugins.local/*"), "is_dir");
foreach ($plugin_dirs as $dir) {
if (is_dir("$dir/.git")) {
$plugin_name = basename($dir);
array_push($rv, ["plugin" => $plugin_name, "rv" => $this->_plugin_needs_update($root_dir, $plugin_name)]);
}
}
$rv = self::_get_updated_plugins();
}
print json_encode($rv);
@ -1191,7 +1201,7 @@ class Pref_Prefs extends Handler_Protected {
if (is_dir("$dir/.git")) {
$plugin_name = basename($dir);
$test = $this->_plugin_needs_update($root_dir, $plugin_name);
$test = self::_plugin_needs_update($root_dir, $plugin_name);
if (!empty($test["o"]))
array_push($rv, ["plugin" => $plugin_name, "rv" => $this->_update_plugin($root_dir, $plugin_name)]);

View File

@ -394,7 +394,7 @@ class RPC extends Handler_Protected {
}
function checkforupdates() {
$rv = [];
$rv = ["changeset" => [], "plugins" => []];
$git_timestamp = false;
$git_commit = false;
@ -411,10 +411,12 @@ class RPC extends Handler_Protected {
if ($git_timestamp < (int)$content["changeset"]["timestamp"] &&
$git_commit != $content["changeset"]["id"]) {
$rv = $content["changeset"];
$rv["changeset"] = $content["changeset"];
}
}
}
$rv["plugins"] = Pref_Prefs::_get_updated_plugins();
}
print json_encode($rv);

View File

@ -812,10 +812,23 @@ const App = {
.then((reply) => {
console.log('update reply', reply);
if (reply.id) {
App.byId("updates-available").show();
const icon = App.byId("updates-available");
if (reply.changeset.id || reply.plugins.length > 0) {
icon.show();
const tips = [];
if (reply.changeset.id)
tips.push(__("Updates for Tiny Tiny RSS are available."));
if (reply.plugins.length > 0)
tips.push(__("Updates for some local plugins are available."));
icon.setAttribute("title", tips.join("\n"));
} else {
App.byId("updates-available").hide();
icon.hide();
}
});
},

View File

@ -117,6 +117,7 @@
title="<?= __("Communication problem with server.") ?>">error_outline</i>
<i class="material-icons log-alert" style="display : none" onclick="App.openPreferences('system')"
title="<?= __("Recent entries found in event log.") ?>">warning</i>
<i id="updates-available" class="material-icons icon-new-version" style="display : none">new_releases</i>
<a href="#" onclick="document.location.href = 'index.php'"><?= __('Exit preferences') ?></a>
</div>

View File

@ -763,6 +763,10 @@ body.ttrss_main #header i.log-alert {
color: #ddba1c;
cursor: pointer;
}
body.ttrss_main #header #updates-available {
color: #69C671;
padding-right: 4px;
}
body.ttrss_main #header i {
margin: 0 4px;
}

View File

@ -763,6 +763,10 @@ body.ttrss_main #header i.log-alert {
color: #ddba1c;
cursor: pointer;
}
body.ttrss_main #header #updates-available {
color: #69C671;
padding-right: 4px;
}
body.ttrss_main #header i {
margin: 0 4px;
}

View File

@ -763,6 +763,10 @@ body.ttrss_main #header i.log-alert {
color: #ddba1c;
cursor: pointer;
}
body.ttrss_main #header #updates-available {
color: #69C671;
padding-right: 4px;
}
body.ttrss_main #header i {
margin: 0 4px;
}

View File

@ -888,6 +888,11 @@ body.ttrss_main {
cursor : pointer;
}
#updates-available {
color : @color-checked;
padding-right : 4px;
}
i {
margin : 0 4px;
}

View File

@ -764,6 +764,10 @@ body.ttrss_main #header i.log-alert {
color: #ddba1c;
cursor: pointer;
}
body.ttrss_main #header #updates-available {
color: #69C671;
padding-right: 4px;
}
body.ttrss_main #header i {
margin: 0 4px;
}

View File

@ -764,6 +764,10 @@ body.ttrss_main #header i.log-alert {
color: #ddba1c;
cursor: pointer;
}
body.ttrss_main #header #updates-available {
color: #69C671;
padding-right: 4px;
}
body.ttrss_main #header i {
margin: 0 4px;
}