From ea27b40ed7bac49ba6379751c316a0cd587cecb0 Mon Sep 17 00:00:00 2001 From: Arthur Poiret Date: Mon, 1 Dec 2025 22:26:04 +0100 Subject: [PATCH] chore(#402): use github release api to retrieve last app version --- .../core/components/ApplicationDefaults.java | 8 ++-- .../core/controllers/MainController.java | 35 +++++++-------- .../core/model/json/RemoteVersion.java | 30 ------------- .../services/AppUpdateService.java} | 43 ++++++++++--------- .../src/main/resources/application.properties | 4 +- 5 files changed, 45 insertions(+), 75 deletions(-) delete mode 100644 owlplug-client/src/main/java/com/owlplug/core/model/json/RemoteVersion.java rename owlplug-client/src/main/java/com/owlplug/{plugin/services/UpdateService.java => core/services/AppUpdateService.java} (59%) diff --git a/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java b/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java index 35743a66..edc58d56 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java +++ b/owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java @@ -212,12 +212,12 @@ public String getVersion() { return env.getProperty("owlplug.version"); } - public String getOwlPlugHubUrl() { - return env.getProperty("owlplug.hub.url"); + public String getLatestUrl() { + return env.getProperty("owlplug.github.latestUrl"); } - public String getUpdateDownloadUrl() { - return env.getProperty("owlplug.hub.updateDownloadUrl"); + public String getDownloadUrl() { + return env.getProperty("owlplug.github.downloadUrl"); } public String getOwlPlugRegistryUrl() { diff --git a/owlplug-client/src/main/java/com/owlplug/core/controllers/MainController.java b/owlplug-client/src/main/java/com/owlplug/core/controllers/MainController.java index ccaa3a1c..aec9bb73 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/controllers/MainController.java +++ b/owlplug-client/src/main/java/com/owlplug/core/controllers/MainController.java @@ -37,12 +37,14 @@ import com.owlplug.explore.controllers.ExploreController; import com.owlplug.explore.services.ExploreService; import com.owlplug.plugin.services.PluginService; -import com.owlplug.plugin.services.UpdateService; +import com.owlplug.core.services.AppUpdateService; import jakarta.annotation.PreDestroy; import java.util.ArrayList; import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; import javafx.application.Platform; -import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.geometry.Pos; import javafx.scene.Parent; @@ -79,7 +81,7 @@ public class MainController extends BaseController { @Autowired private AuthenticationService authenticationService; @Autowired - private UpdateService updateService; + private AppUpdateService appUpdateService; @Autowired private PluginService pluginService; @Autowired @@ -151,25 +153,20 @@ public void initialize() { refreshAccounts(); downloadUpdateButton.setOnAction(e -> { - PlatformUtils.openDefaultBrowser(this.getApplicationDefaults().getUpdateDownloadUrl()); + PlatformUtils.openDefaultBrowser(this.getApplicationDefaults().getDownloadUrl()); }); updatePane.setVisible(false); - - Task retrieveUpdateStatusTask = new Task<>() { - @Override - protected Boolean call() throws Exception { - return updateService.isUpToDate(); - } - }; - - retrieveUpdateStatusTask.setOnSucceeded(e -> { - if (!retrieveUpdateStatusTask.getValue()) { - updatePane.setVisible(true); - } - }); - - new Thread(retrieveUpdateStatusTask).start(); + Executor executor = Executors.newVirtualThreadPerTaskExecutor(); + CompletableFuture + .supplyAsync(() -> appUpdateService.isUpToDate(), executor) + .thenAccept(isUpToDate -> { + Platform.runLater(() -> { + if (!isUpToDate) { + updatePane.setVisible(true); + } + }); + }); tabPaneContent.getSelectionModel() .selectedItemProperty() diff --git a/owlplug-client/src/main/java/com/owlplug/core/model/json/RemoteVersion.java b/owlplug-client/src/main/java/com/owlplug/core/model/json/RemoteVersion.java deleted file mode 100644 index 4353cec7..00000000 --- a/owlplug-client/src/main/java/com/owlplug/core/model/json/RemoteVersion.java +++ /dev/null @@ -1,30 +0,0 @@ -/* OwlPlug - * Copyright (C) 2021 Arthur - * - * This file is part of OwlPlug. - * - * OwlPlug is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 - * as published by the Free Software Foundation. - * - * OwlPlug is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OwlPlug. If not, see . - */ - -package com.owlplug.core.model.json; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class RemoteVersion { - public String version; - - public RemoteVersion() { - - } -} diff --git a/owlplug-client/src/main/java/com/owlplug/plugin/services/UpdateService.java b/owlplug-client/src/main/java/com/owlplug/core/services/AppUpdateService.java similarity index 59% rename from owlplug-client/src/main/java/com/owlplug/plugin/services/UpdateService.java rename to owlplug-client/src/main/java/com/owlplug/core/services/AppUpdateService.java index a529d386..c4d6f0ea 100644 --- a/owlplug-client/src/main/java/com/owlplug/plugin/services/UpdateService.java +++ b/owlplug-client/src/main/java/com/owlplug/core/services/AppUpdateService.java @@ -16,11 +16,10 @@ * along with OwlPlug. If not, see . */ -package com.owlplug.plugin.services; +package com.owlplug.core.services; -import com.owlplug.core.model.json.RemoteVersion; -import com.owlplug.core.services.BaseService; import com.vdurmont.semver4j.Semver; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -28,7 +27,7 @@ import org.springframework.web.client.RestTemplate; @Service -public class UpdateService extends BaseService { +public class AppUpdateService extends BaseService { private final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -39,34 +38,38 @@ public class UpdateService extends BaseService { */ public boolean isUpToDate() { - String remoteVersion = getLastVersion(); + String lastVersion = getLastVersion(); - if (remoteVersion != null) { - Semver remoteSemver = new Semver(remoteVersion); + if (lastVersion != null) { + log.debug("Last app version retrieved: {}", lastVersion); + Semver lastSemver = new Semver(lastVersion); Semver currentSemver = new Semver(this.getApplicationDefaults().getVersion()); - return remoteSemver.isLowerThanOrEqualTo(currentSemver); + return lastSemver.isLowerThanOrEqualTo(currentSemver); } return true; - } - + private String getLastVersion() { RestTemplate restTemplate = new RestTemplate(); - RemoteVersion remoteVersion = null; - try { - remoteVersion = restTemplate.getForObject(this.getApplicationDefaults().getOwlPlugHubUrl() - + "/releases/latest/version.json", RemoteVersion.class); - } catch (RestClientException e) { - log.error("Error retrieving latest owlplug version", e); - } + restTemplate.getInterceptors().add((request, body, execution) -> { + request.getHeaders().add("User-Agent", "OwlPlug/App"); + request.getHeaders().add("Accept", "application/vnd.github+json"); + return execution.execute(request, body); + }); + String url = this.getApplicationDefaults().getLatestUrl(); - if (remoteVersion != null) { - return remoteVersion.version; + try { + // Map GitHub JSON to a simple Map so we can extract "tag_name" + Map response = restTemplate.getForObject(url, Map.class); + if (response.containsKey("tag_name")) { + return (String) response.get("tag_name"); + } + } catch (RestClientException e) { + log.error("Error retrieving latest GitHub release version", e); } return null; - } } diff --git a/owlplug-client/src/main/resources/application.properties b/owlplug-client/src/main/resources/application.properties index f72fb3af..dba2e664 100644 --- a/owlplug-client/src/main/resources/application.properties +++ b/owlplug-client/src/main/resources/application.properties @@ -2,8 +2,8 @@ owlplug.version=@project.version@ owlplug.workspace.min-version = 1.29.0 -owlplug.hub.url = https://hub.owlplug.com -owlplug.hub.updateDownloadUrl = https://github.com/DropSnorz/OwlPlug/releases +owlplug.github.latestUrl = https://api.github.com/repos/Dropsnorz/OwlPlug/releases/latest +owlplug.github.downloadUrl = https://github.com/DropSnorz/OwlPlug/releases owlplug.github.issues.url = https://github.com/DropSnorz/OwlPlug/issues owlplug.github.wiki.url = https://github.com/DropSnorz/OwlPlug/wiki owlplug.roadmap.url = https://owlplug.com/roadmap