use of eu.binjr.common.version.Version in project binjr by binjr.
the class UpdateManager method asyncCheckForUpdate.
private void asyncCheckForUpdate(Consumer<GithubRelease> newReleaseAvailable, Consumer<Version> upToDate, Runnable onFailure, boolean forceCheck) {
if (appEnv.isDisableUpdateCheck()) {
logger.trace(() -> "Update check is explicitly disabled.");
if (onFailure != null) {
onFailure.run();
}
return;
}
if (!forceCheck && LocalDateTime.now().minus(1, ChronoUnit.HOURS).isBefore(userPrefs.lastCheckForUpdate.get())) {
logger.trace(() -> "Available update check ignored as it already took place less than 1 hour ago.");
if (onFailure != null) {
onFailure.run();
}
return;
}
userPrefs.lastCheckForUpdate.set(LocalDateTime.now());
Task<Optional<GithubRelease>> getLatestTask = new Task<>() {
@Override
protected Optional<GithubRelease> call() throws Exception {
logger.trace("getNewRelease running on " + Thread.currentThread().getName());
return github.getLatestRelease(appEnv.getUpdateRepoSlug()).filter(r -> r.getVersion().compareTo(appEnv.getVersion()) > 0);
}
};
getLatestTask.setOnSucceeded(workerStateEvent -> {
logger.trace("UI update running on " + Thread.currentThread().getName());
Optional<GithubRelease> latest = getLatestTask.getValue();
Version current = appEnv.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);
}
use of eu.binjr.common.version.Version in project binjr by binjr.
the class UpdateManager method showUpdateAvailableNotification.
public void showUpdateAvailableNotification(GithubRelease release, Node root) {
if (updatePackage != null) {
showUpdateReadyNotification(root);
return;
}
Notifications n = Notifications.create().title("New release available!").text("You are currently running " + AppEnvironment.APP_NAME + " version " + appEnv.getVersion() + "\t\t\nVersion " + release.getVersion() + " is now available.").hideAfter(Duration.seconds(20)).position(Pos.BOTTOM_RIGHT).owner(root);
List<Action> actions = new ArrayList<>();
actions.add(new Action("More info", event -> {
URL newReleaseUrl = release.getHtmlUrl();
if (newReleaseUrl != null) {
try {
Dialogs.launchUrlInExternalBrowser(newReleaseUrl);
} catch (IOException | URISyntaxException e) {
logger.error("Failed to launch url in browser " + newReleaseUrl, e);
}
}
}));
if (platformUpdater.isInAppUpdateSupported()) {
actions.add(new Action("Download update", event -> {
this.asyncDownloadUpdatePackage(release, path -> {
updatePackage = path;
updateVersion = release.getVersion();
showUpdateReadyNotification(root);
}, exception -> Dialogs.notifyException("Error downloading update", exception, root));
Dialogs.dismissParentNotificationPopup((Node) event.getSource());
}));
}
n.action(actions.toArray(Action[]::new));
n.showInformation();
}
use of eu.binjr.common.version.Version in project binjr by binjr.
the class Workspace method sanityCheck.
private static boolean sanityCheck(File file) throws IOException, CannotLoadWorkspaceException {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
if (!file.exists()) {
throw new FileNotFoundException("Could not find specified workspace file " + file.getPath());
}
try {
String verStr = XmlUtils.getFirstAttributeValue(file, "schemaVersion");
if (verStr == null) {
throw new CannotLoadWorkspaceException("Could not determine the workspace's schema version: it was probably produced with an older, incompatible version of binjr." + "\n (Minimum supported schema version=" + MINIMUM_SUPPORTED_SCHEMA_VERSION.toString() + ")");
}
Version foundVersion = new Version(verStr);
if (foundVersion.compareTo(SUPPORTED_SCHEMA_VERSION) > 0) {
if (foundVersion.getMajor() != SUPPORTED_SCHEMA_VERSION.getMajor()) {
// Only throw if major version is different, only warn otherwise.
throw new CannotLoadWorkspaceException("This workspace is not compatible with the current version of binjr. (Supported schema version=" + SUPPORTED_SCHEMA_VERSION.toString() + ", found=" + foundVersion.toString() + ")");
}
logger.warn("This workspace version is higher that the supported version; there may be incompatibilities (Supported schema version=" + SUPPORTED_SCHEMA_VERSION.toString() + ", found=" + foundVersion.toString() + ")");
}
if (foundVersion.compareTo(MINIMUM_SUPPORTED_SCHEMA_VERSION) < 0) {
// Returns true to signal workspace requires schema migration
return true;
}
} catch (XMLStreamException e) {
throw new CannotLoadWorkspaceException("Error retrieving bjr schema version", e);
}
return false;
}
Aggregations