* Updater extension can update to v1.8.x

This commit is contained in:
maxpozdeev 2023-09-14 10:26:00 +03:00
parent cf40bc72b2
commit 6a816619a4
5 changed files with 34 additions and 12 deletions

View file

@ -26,17 +26,37 @@ class Updater
$json = null;
$this->lastErrorString = null;
try {
$json = @file_get_contents("https://api.github.com/repos/maxpozdeev/mytinytodo/releases/latest", false, $context);
$json = @file_get_contents("https://api.github.com/repos/maxpozdeev/mytinytodo/releases", false, $context);
}
catch (\Exception $e) {
$this->lastErrorString = boolval(ini_get('html_errors')) ? htmlspecialchars_decode($e->getMessage()) : $e->getMessage();
}
restore_error_handler();
if ($json === false || $json == '') {
error_log("Failed to get last version info: ".$this->lastErrorString);
error_log("Failed to get releases info: ".$this->lastErrorString);
return null;
}
$a = json_decode($json, true) ?? [];
$releases = json_decode($json, true) ?? [];
$a = null;
foreach ($releases as $rel) {
// find only stable
if ($rel['prerelease'] ?? false) {
continue;
}
$ver = substr($rel['tag_name'] ?? 'v', 1);
if ($ver == '') continue;
if ($a && version_compare($a['__ver'], $ver)) {
continue; // skip lower version
}
$rel['__ver'] = $ver;
$a = $rel;
}
if (null === $a) {
$this->lastErrorString = "No release to update to";
return null;
}
$ret = [];
$ver = '';
if (isset($a['tag_name'])) {

View file

@ -1,6 +1,6 @@
{
"bundleId": "updater",
"name": "Updates",
"version": "0.9.2",
"version": "0.9.3",
"description": "myTinyTodo self-updater"
}

View file

@ -4,10 +4,11 @@
"updater.tarwarning": "Update is not possible, 'tar' utility is not found.",
"updater.h_check_updates": "Check updates",
"updater.check": "Check",
"updater.no_updates": "No updates available",
"updater.no_updates": "No updates",
"updater.last_version": "Last available version: %s",
"updater.current_version": "Current version",
"updater.last_checked": "Last checked",
"updater.updatet_version_avaialable": "Updated version is available",
"updater.new_version_available": "New version is available",
"updater.update": "Update",
"updater.updated": "Update has completed",
"updater.download_error": "Download failed",

View file

@ -5,9 +5,10 @@
"updater.h_check_updates": "Проверка обновлений",
"updater.check": "Проверить",
"updater.no_updates": "Нет обновлений",
"updater.last_version": "Актуальная версия: %s",
"updater.current_version": "Текущая версия",
"updater.last_checked": "Последняя проверка",
"updater.updatet_version_avaialable": "Доступно обновление",
"updater.updated_version_available": "Доступно обновление",
"updater.update": "Обновить",
"updater.updated": "Обновление завершено",
"updater.download_error": "Ошибка при загрузке",

View file

@ -48,7 +48,7 @@ class UpdaterExtension extends MTTExtension implements MTTExtensionSettingsInter
function settingsPage(): string
{
$e = function($s) { return __($s, true); };
$e = function($s, $arg=null) { return __($s, true, $arg); };
$ext = htmlspecialchars(self::bundleId);
$prefs = self::preferences();
$lastCheck = $prefs['lastCheck'] ?? 0;
@ -72,9 +72,9 @@ class UpdaterExtension extends MTTExtension implements MTTExtensionSettingsInter
$warning = '';
if ($version != '') {
if ( version_compare($version, mytinytodo\Version::VERSION) > 0 ) {
$updateStr = "<br> {$e('updater.updatet_version_avaialable')}: ". htmlspecialchars($version);
# allow update to v1.7.x only
if ("1.7." == substr($version, 0, 4)) {
$updateStr = "<br> {$e('updater.updated_version_available')}: ". htmlspecialchars($version);
# allow update to v1.7.x and 1.8.x only
if ( in_array(substr($version, 0, 4), ["1.7.", "1.8."]) ) {
$updateStr .= "<br><br>\n <a href=\"#\" data-ext-settings-action=\"post:update\" data-ext=\"$ext\">{$e('updater.update')}</a> ";
}
$retval = 0;
@ -86,7 +86,7 @@ class UpdaterExtension extends MTTExtension implements MTTExtensionSettingsInter
}
}
else {
$updateStr = "<br>{$e('updater.no_updates')}";
$updateStr = "<br>{$e('updater.no_updates')}<br>{$e('updater.last_version', $version)}";
}
}
$lastCheckStr = $err ? $e('updater.download_error') : ($lastCheck ? timestampToDatetime($lastCheck, true) : "");