Search in sources :

Example 1 with GithubRelease

use of eu.binjr.common.github.GithubRelease 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 GithubRelease

use of eu.binjr.common.github.GithubRelease 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)

Aggregations

GithubRelease (eu.binjr.common.github.GithubRelease)2 Version (eu.binjr.common.version.Version)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 Dialogs (eu.binjr.core.dialogs.Dialogs)1 AppEnvironment (eu.binjr.core.preferences.AppEnvironment)1 UserPreferences (eu.binjr.core.preferences.UserPreferences)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 StandardOpenOption (java.nio.file.StandardOpenOption)1 Security (java.security.Security)1