Search in sources :

Example 1 with Version

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);
}
Also used : Task(javafx.concurrent.Task) Version(eu.binjr.common.version.Version) GithubRelease(eu.binjr.common.github.GithubRelease)

Example 2 with Version

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();
}
Also used : GithubRelease(eu.binjr.common.github.GithubRelease) Pos(javafx.geometry.Pos) java.util(java.util) URL(java.net.URL) Action(org.controlsfx.control.action.Action) URISyntaxException(java.net.URISyntaxException) LocalDateTime(java.time.LocalDateTime) Security(java.security.Security) Task(javafx.concurrent.Task) UserPreferences(eu.binjr.core.preferences.UserPreferences) Version(eu.binjr.common.version.Version) org.bouncycastle.openpgp(org.bouncycastle.openpgp) JcaPGPContentVerifierBuilderProvider(org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider) WindowEvent(javafx.stage.WindowEvent) URI(java.net.URI) Logger(eu.binjr.common.logging.Logger) Path(java.nio.file.Path) JcaKeyFingerprintCalculator(org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator) Dialogs(eu.binjr.core.dialogs.Dialogs) Files(java.nio.file.Files) ProxyConfiguration(eu.binjr.common.io.ProxyConfiguration) NodeUtils(eu.binjr.common.javafx.controls.NodeUtils) AppEnvironment(eu.binjr.core.preferences.AppEnvironment) Node(javafx.scene.Node) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) AsyncTaskManager(eu.binjr.core.data.async.AsyncTaskManager) Consumer(java.util.function.Consumer) GithubApiHelper(eu.binjr.common.github.GithubApiHelper) Duration(javafx.util.Duration) ChronoUnit(java.time.temporal.ChronoUnit) JcaPGPObjectFactory(org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory) Notifications(org.controlsfx.control.Notifications) InputStream(java.io.InputStream) Action(org.controlsfx.control.action.Action) Node(javafx.scene.Node) Notifications(org.controlsfx.control.Notifications) URL(java.net.URL)

Example 3 with Version

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;
}
Also used : CannotLoadWorkspaceException(eu.binjr.core.data.exceptions.CannotLoadWorkspaceException) XMLStreamException(javax.xml.stream.XMLStreamException) Version(eu.binjr.common.version.Version) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Version (eu.binjr.common.version.Version)3 GithubRelease (eu.binjr.common.github.GithubRelease)2 Task (javafx.concurrent.Task)2 GithubApiHelper (eu.binjr.common.github.GithubApiHelper)1 ProxyConfiguration (eu.binjr.common.io.ProxyConfiguration)1 NodeUtils (eu.binjr.common.javafx.controls.NodeUtils)1 Logger (eu.binjr.common.logging.Logger)1 AsyncTaskManager (eu.binjr.core.data.async.AsyncTaskManager)1 CannotLoadWorkspaceException (eu.binjr.core.data.exceptions.CannotLoadWorkspaceException)1 Dialogs (eu.binjr.core.dialogs.Dialogs)1 AppEnvironment (eu.binjr.core.preferences.AppEnvironment)1 UserPreferences (eu.binjr.core.preferences.UserPreferences)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1