use of eu.fthevenet.util.github.GithubRelease in project selenium_java by sergueik.
the class MainViewController method onAvailableUpdate.
private void onAvailableUpdate(GithubRelease githubRelease) {
Notifications n = Notifications.create().title("New release available!").text("You are currently running binjr version " + AppEnvironment.getInstance().getVersion() + "\t\t.\nVersion " + githubRelease.getVersion() + " is now available.").hideAfter(Duration.seconds(20)).position(Pos.BOTTOM_RIGHT).owner(root);
n.action(new Action("Download", actionEvent -> {
String newReleaseUrl = githubRelease.getHtmlUrl();
if (newReleaseUrl != null && newReleaseUrl.trim().length() > 0) {
try {
Dialogs.launchUrlInExternalBrowser(newReleaseUrl);
} catch (IOException | URISyntaxException e) {
logger.error("Failed to launch url in browser " + newReleaseUrl, e);
}
}
n.hideAfter(Duration.seconds(0));
}));
n.showInformation();
}
use of eu.fthevenet.util.github.GithubRelease in project selenium_java by sergueik.
the class UpdateManager method asyncCheckForUpdate.
private void asyncCheckForUpdate(Consumer<GithubRelease> newReleaseAvailable, Consumer<Version> upToDate, Runnable onFailure, boolean forceCheck) {
if (forceCheck || LocalDateTime.now().minus(1, ChronoUnit.HOURS).isAfter(getLastCheckForUpdate())) {
setLastCheckForUpdate(LocalDateTime.now());
Task<Optional<GithubRelease>> getLatestTask = new Task<Optional<GithubRelease>>() {
@Override
protected Optional<GithubRelease> call() throws Exception {
logger.trace("getNewRelease running on " + Thread.currentThread().getName());
return GithubApi.getInstance().getLatestRelease(GITHUB_OWNER, GITHUB_REPO).filter(r -> r.getVersion().compareTo(AppEnvironment.getInstance().getVersion()) > 0);
}
};
getLatestTask.setOnSucceeded(workerStateEvent -> {
logger.trace("UI update running on " + Thread.currentThread().getName());
Optional<GithubRelease> latest = getLatestTask.getValue();
Version current = AppEnvironment.getInstance().getVersion();
if (latest.isPresent()) {
newReleaseAvailable.accept(latest.get());
} else {
if (upToDate != null) {
upToDate.accept(current);
}
}
});
getLatestTask.setOnFailed(workerStateEvent -> {
logger.error("Error while checking for update", getLatestTask.getException());
if (onFailure != null) {
onFailure.run();
}
});
AsyncTaskManager.getInstance().submit(getLatestTask);
} else {
logger.trace(() -> "Available update check ignored as it already took place less than 1 hour ago.");
}
}
Aggregations