diff --git a/src/ext/updater/class.updater.php b/src/ext/updater/class.updater.php
index b79043d..5ea81ed 100644
--- a/src/ext/updater/class.updater.php
+++ b/src/ext/updater/class.updater.php
@@ -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'])) {
diff --git a/src/ext/updater/extension.json b/src/ext/updater/extension.json
index a033c59..5b05bcd 100644
--- a/src/ext/updater/extension.json
+++ b/src/ext/updater/extension.json
@@ -1,6 +1,6 @@
{
"bundleId": "updater",
"name": "Updates",
- "version": "0.9.2",
+ "version": "0.9.3",
"description": "myTinyTodo self-updater"
}
diff --git a/src/ext/updater/lang/en.json b/src/ext/updater/lang/en.json
index 9418506..af2972a 100644
--- a/src/ext/updater/lang/en.json
+++ b/src/ext/updater/lang/en.json
@@ -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",
diff --git a/src/ext/updater/lang/ru.json b/src/ext/updater/lang/ru.json
index 92e2ee7..57ab22d 100644
--- a/src/ext/updater/lang/ru.json
+++ b/src/ext/updater/lang/ru.json
@@ -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": "Ошибка при загрузке",
diff --git a/src/ext/updater/loader.php b/src/ext/updater/loader.php
index fb79d54..cf413e7 100644
--- a/src/ext/updater/loader.php
+++ b/src/ext/updater/loader.php
@@ -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 = "
{$e('updater.updatet_version_avaialable')}: ". htmlspecialchars($version);
- # allow update to v1.7.x only
- if ("1.7." == substr($version, 0, 4)) {
+ $updateStr = "
{$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 .= "
\n {$e('updater.update')} ";
}
$retval = 0;
@@ -86,7 +86,7 @@ class UpdaterExtension extends MTTExtension implements MTTExtensionSettingsInter
}
}
else {
- $updateStr = "
{$e('updater.no_updates')}";
+ $updateStr = "
{$e('updater.no_updates')}
{$e('updater.last_version', $version)}";
}
}
$lastCheckStr = $err ? $e('updater.download_error') : ($lastCheck ? timestampToDatetime($lastCheck, true) : "");