mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-22 07:30:24 +00:00
Use improved changelog api
This commit is contained in:
parent
d3fef8efac
commit
6bd96f6433
9 changed files with 22 additions and 52 deletions
|
@ -4,6 +4,7 @@ import io.xpipe.app.core.AppProperties;
|
|||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.util.HttpHelper;
|
||||
import io.xpipe.core.util.JacksonMapper;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.kohsuke.github.GHRelease;
|
||||
import org.kohsuke.github.GHRepository;
|
||||
|
@ -78,6 +79,18 @@ public class AppDownloads {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
try {
|
||||
var url = URI.create("https://api.xpipe.io/changelog?from=" + AppProperties.get().getVersion() +
|
||||
"&to=" + version + "&stage=" + AppProperties.get().isStaging()).toURL();
|
||||
var bytes = HttpHelper.executeGet(url, aFloat -> {});
|
||||
var string = new String(bytes, StandardCharsets.UTF_8);
|
||||
var json = JacksonMapper.getDefault().readTree(string);
|
||||
var changelog = json.required("changelog").asText();
|
||||
return Optional.of(changelog);
|
||||
} catch (Throwable t) {
|
||||
ErrorEvent.fromThrowable(t).omitted(omitErrors).handle();
|
||||
}
|
||||
|
||||
try {
|
||||
var asset = release.get().listAssets().toList().stream()
|
||||
.filter(ghAsset -> ghAsset.getName().equals("changelog.md"))
|
||||
|
@ -96,12 +109,6 @@ public class AppDownloads {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getLatestVersion() throws IOException {
|
||||
return getLatestSuitableRelease()
|
||||
.map(ghRelease -> ghRelease.getTagName())
|
||||
.orElse("?");
|
||||
}
|
||||
|
||||
public static Optional<GHRelease> getLatestIncludingPreRelease() throws IOException {
|
||||
var repo = getRepository();
|
||||
return Optional.ofNullable(repo.listReleases().iterator().next());
|
||||
|
|
|
@ -49,7 +49,6 @@ public class ChocoUpdater extends UpdateHandler {
|
|||
null,
|
||||
null,
|
||||
Instant.now(),
|
||||
null,
|
||||
isUpdate);
|
||||
lastUpdateCheckResult.setValue(rel);
|
||||
return lastUpdateCheckResult.getValue();
|
||||
|
|
|
@ -35,7 +35,6 @@ public class GitHubUpdater extends UpdateHandler {
|
|||
XPipeDistributionType.get().getId(),
|
||||
lastUpdateCheckResult.getValue().getVersion(),
|
||||
lastUpdateCheckResult.getValue().getReleaseUrl(),
|
||||
lastUpdateCheckResult.getValue().getReleaseDate(),
|
||||
downloadFile.get(),
|
||||
changelog,
|
||||
lastUpdateCheckResult.getValue().getAssetType());
|
||||
|
@ -79,7 +78,6 @@ public class GitHubUpdater extends UpdateHandler {
|
|||
ghAsset.get().getBrowserDownloadUrl(),
|
||||
assetType,
|
||||
Instant.now(),
|
||||
rel.get().getCreatedAt() != null ? rel.get().getCreatedAt().toInstant() : null,
|
||||
isUpdate));
|
||||
return lastUpdateCheckResult.getValue();
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ public class HomebrewUpdater extends GitHubUpdater {
|
|||
lastUpdateCheckResult.getValue().getVersion(),
|
||||
lastUpdateCheckResult.getValue().getReleaseUrl(),
|
||||
null,
|
||||
null,
|
||||
changelog,
|
||||
lastUpdateCheckResult.getValue().getAssetType());
|
||||
preparedUpdate.setValue(rel);
|
||||
|
|
|
@ -50,7 +50,6 @@ public class PortableUpdater extends UpdateHandler {
|
|||
null,
|
||||
null,
|
||||
Instant.now(),
|
||||
rel.get().getCreatedAt() != null ? rel.get().getCreatedAt().toInstant() : null,
|
||||
isUpdate));
|
||||
return lastUpdateCheckResult.getValue();
|
||||
}
|
||||
|
|
|
@ -10,10 +10,6 @@ import javafx.scene.control.ButtonType;
|
|||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
|
||||
public class UpdateAvailableAlert {
|
||||
|
||||
public static void showIfNeeded() {
|
||||
|
@ -26,14 +22,7 @@ public class UpdateAvailableAlert {
|
|||
var update = AppWindowHelper.showBlockingAlert(alert -> {
|
||||
alert.setTitle(AppI18n.get("updateReadyAlertTitle"));
|
||||
alert.setAlertType(Alert.AlertType.NONE);
|
||||
|
||||
var date = u.getReleaseDate() != null ?
|
||||
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
|
||||
.format(u.getReleaseDate().atZone(ZoneId.systemDefault())) : "Latest";
|
||||
var markdown = new MarkdownComp(u.getBody() != null ? u.getBody() : "", s -> {
|
||||
var header = " <h1>" + AppI18n.get("whatsNew", u.getVersion(), date) + "</h1>";
|
||||
return header + s;
|
||||
})
|
||||
var markdown = new MarkdownComp(u.getBody() != null ? u.getBody() : "", s -> " " + s)
|
||||
.createRegion();
|
||||
alert.getButtonTypes().clear();
|
||||
var updaterContent = uh.createInterface();
|
||||
|
|
|
@ -10,10 +10,6 @@ import javafx.scene.control.ButtonBar;
|
|||
import javafx.scene.control.ButtonType;
|
||||
import javafx.stage.Modality;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
|
||||
public class UpdateChangelogAlert {
|
||||
|
||||
private static boolean shown = false;
|
||||
|
@ -46,13 +42,7 @@ public class UpdateChangelogAlert {
|
|||
alert.setAlertType(Alert.AlertType.NONE);
|
||||
alert.initModality(Modality.NONE);
|
||||
|
||||
var date = update.getReleaseDate() != null ?
|
||||
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
|
||||
.format(update.getReleaseDate().atZone(ZoneId.systemDefault())) : "Latest";
|
||||
var markdown = new MarkdownComp(update.getRawDescription(), s -> {
|
||||
var header = " <h1>" + AppI18n.get("whatsNew", update.getName(), date) + "</h1>";
|
||||
return header + s;
|
||||
})
|
||||
var markdown = new MarkdownComp(update.getRawDescription(), s -> " " + s)
|
||||
.createRegion();
|
||||
alert.getDialogPane().setContent(markdown);
|
||||
|
||||
|
|
|
@ -184,7 +184,6 @@ public abstract class UpdateHandler {
|
|||
XPipeDistributionType.get().getId(),
|
||||
lastUpdateCheckResult.getValue().getVersion(),
|
||||
lastUpdateCheckResult.getValue().getReleaseUrl(),
|
||||
lastUpdateCheckResult.getValue().getReleaseDate(),
|
||||
null,
|
||||
changelog,
|
||||
lastUpdateCheckResult.getValue().getAssetType());
|
||||
|
@ -223,8 +222,7 @@ public abstract class UpdateHandler {
|
|||
var performedUpdate = new PerformedUpdate(
|
||||
preparedUpdate.getValue().getVersion(),
|
||||
preparedUpdate.getValue().getBody(),
|
||||
preparedUpdate.getValue().getVersion(),
|
||||
preparedUpdate.getValue().getReleaseDate());
|
||||
preparedUpdate.getValue().getVersion());
|
||||
AppCache.update("performedUpdate", performedUpdate);
|
||||
|
||||
executeUpdateOnCloseImpl();
|
||||
|
@ -262,7 +260,6 @@ public abstract class UpdateHandler {
|
|||
String name;
|
||||
String rawDescription;
|
||||
String newVersion;
|
||||
Instant releaseDate;
|
||||
}
|
||||
|
||||
@Value
|
||||
|
@ -277,7 +274,6 @@ public abstract class UpdateHandler {
|
|||
String downloadUrl;
|
||||
AppInstaller.InstallerAssetType assetType;
|
||||
Instant checkTime;
|
||||
Instant releaseDate;
|
||||
boolean isUpdate;
|
||||
}
|
||||
|
||||
|
@ -289,7 +285,6 @@ public abstract class UpdateHandler {
|
|||
String sourceDist;
|
||||
String version;
|
||||
String releaseUrl;
|
||||
Instant releaseDate;
|
||||
Path file;
|
||||
String body;
|
||||
AppInstaller.InstallerAssetType assetType;
|
||||
|
|
|
@ -3,23 +3,12 @@ package io.xpipe.app.util;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class HttpHelper {
|
||||
|
||||
public static Path downloadFile(String urlS) throws Exception {
|
||||
var url = URI.create(urlS).toURL();
|
||||
var bytes = HttpHelper.executeGet(url, aFloat -> {});
|
||||
var downloadFile = Files.createTempFile(null, null);
|
||||
Files.write(downloadFile, bytes);
|
||||
return downloadFile;
|
||||
}
|
||||
|
||||
public static byte[] executeGet(URL targetURL, Consumer<Float> progress) throws Exception {
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
|
@ -36,7 +25,12 @@ public class HttpHelper {
|
|||
}
|
||||
|
||||
InputStream is = connection.getInputStream();
|
||||
int size = Integer.parseInt(connection.getHeaderField("Content-Length"));
|
||||
var lengthField = connection.getHeaderField("Content-Length");
|
||||
if (lengthField == null) {
|
||||
return is.readAllBytes();
|
||||
}
|
||||
|
||||
int size = Integer.parseInt(lengthField);
|
||||
|
||||
byte[] line;
|
||||
int bytes = 0;
|
||||
|
|
Loading…
Reference in a new issue