Support Gitea release update source
All checks were successful
Gitea Smoke / smoke (push) Successful in 2s

This commit is contained in:
Codex 2026-07-05 16:45:40 +00:00
parent 08637eafa6
commit 85469dae4b
2 changed files with 40 additions and 2 deletions

View File

@ -5,13 +5,13 @@ plugins {
}
val repoSlug = providers.gradleProperty("repoSlug")
.orElse("neatstudio/tmux-android")
.orElse("neatstudio/tmux-browser-android")
val defaultServerUrl = providers.gradleProperty("defaultServerUrl")
.orElse("http://100.89.0.116:3000")
val defaultUpdateUrl = providers.gradleProperty("defaultUpdateUrl")
.orElse("https://github.com/${repoSlug.get()}/releases/latest/download/latest.json")
val defaultGiteaUpdateUrl = providers.gradleProperty("defaultGiteaUpdateUrl")
.orElse("https://gitea.neatcn.com/tmux/tmux-browser-android/releases/latest/download/latest.json")
.orElse("https://gitea.neatcn.com/api/v1/repos/tmux/tmux-browser-android/releases/latest")
val signingProps = Properties()
val signingFile = rootProject.file("signing.properties")

View File

@ -10,6 +10,7 @@ import android.os.Build;
import android.provider.Settings;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedInputStream;
@ -103,6 +104,9 @@ final class UpdateManager {
private ReleaseInfo fetchReleaseInfo(String manifestUrl) throws Exception {
String json = readText(manifestUrl);
JSONObject root = new JSONObject(json);
if (root.has("assets") && root.has("tag_name")) {
return fetchReleaseInfoFromReleaseApi(root);
}
return new ReleaseInfo(
root.getInt("versionCode"),
root.optString("versionName", ""),
@ -112,6 +116,40 @@ final class UpdateManager {
);
}
private ReleaseInfo fetchReleaseInfoFromReleaseApi(JSONObject release) throws Exception {
JSONArray assets = release.getJSONArray("assets");
String manifestUrl = findAssetUrl(assets, "latest.json");
String apkUrl = findAssetUrl(assets, "tmux-android.apk");
if (manifestUrl.isEmpty()) {
throw new IllegalStateException("Release has no latest.json");
}
ReleaseInfo info = fetchReleaseInfo(manifestUrl);
if (apkUrl.isEmpty()) {
return info;
}
return new ReleaseInfo(
info.versionCode,
info.versionName,
apkUrl,
info.sha256,
release.optString("html_url", info.releasePageUrl)
);
}
private String findAssetUrl(JSONArray assets, String name) {
for (int index = 0; index < assets.length(); index++) {
JSONObject asset = assets.optJSONObject(index);
if (asset == null || !name.equals(asset.optString("name"))) {
continue;
}
String url = asset.optString("browser_download_url", "");
if (!url.isEmpty()) {
return url;
}
}
return "";
}
private String readText(String url) throws Exception {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setConnectTimeout(12000);