Search in sources :

Example 1 with GithubRelease

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();
}
Also used : StageStyle(javafx.stage.StageStyle) DataAdapterException(eu.fthevenet.binjr.data.exceptions.DataAdapterException) HPos(javafx.geometry.HPos) Pos(javafx.geometry.Pos) Initializable(javafx.fxml.Initializable) DoubleBinding(javafx.beans.binding.DoubleBinding) javafx.scene.layout(javafx.scene.layout) Dialogs(eu.fthevenet.binjr.dialogs.Dialogs) javafx.scene.control(javafx.scene.control) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) ZonedDateTime(java.time.ZonedDateTime) NoAdapterFoundException(eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException) DataAdapterDialog(eu.fthevenet.binjr.dialogs.DataAdapterDialog) Side(javafx.geometry.Side) Application(javafx.application.Application) Parent(javafx.scene.Parent) MaskerPane(org.controlsfx.control.MaskerPane) ListChangeListener(javafx.collections.ListChangeListener) DiagnosticCommand(eu.fthevenet.util.diagnositic.DiagnosticCommand) CannotInitializeDataAdapterException(eu.fthevenet.binjr.data.exceptions.CannotInitializeDataAdapterException) eu.fthevenet.util.javafx.controls(eu.fthevenet.util.javafx.controls) UpdateManager(eu.fthevenet.binjr.preferences.UpdateManager) eu.fthevenet.binjr.data.workspace(eu.fthevenet.binjr.data.workspace) USE_COMPUTED_SIZE(javafx.scene.layout.Region.USE_COMPUTED_SIZE) Event(javafx.event.Event) AsyncTaskManager(eu.fthevenet.binjr.data.async.AsyncTaskManager) AppEnvironment(eu.fthevenet.binjr.preferences.AppEnvironment) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) DataAdapter(eu.fthevenet.binjr.data.adapters.DataAdapter) Duration(javafx.util.Duration) Logger(org.apache.logging.log4j.Logger) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) Binjr(eu.fthevenet.binjr.Binjr) Notifications(org.controlsfx.control.Notifications) StageAppearanceManager(eu.fthevenet.binjr.dialogs.StageAppearanceManager) Binding(javafx.beans.binding.Binding) java.util(java.util) GithubRelease(eu.fthevenet.util.github.GithubRelease) Action(org.controlsfx.control.action.Action) DiagnosticException(eu.fthevenet.util.diagnositic.DiagnosticException) javafx.animation(javafx.animation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataAdapterFactory(eu.fthevenet.binjr.data.adapters.DataAdapterFactory) DataAdapterInfo(eu.fthevenet.binjr.data.adapters.DataAdapterInfo) Bindings(javafx.beans.binding.Bindings) Supplier(java.util.function.Supplier) VPos(javafx.geometry.VPos) FXMLLoader(javafx.fxml.FXMLLoader) GlobalPreferences(eu.fthevenet.binjr.preferences.GlobalPreferences) StreamSupport(java.util.stream.StreamSupport) Callback(javafx.util.Callback) Color(javafx.scene.paint.Color) javafx.beans.property(javafx.beans.property) javafx.scene.input(javafx.scene.input) Files(java.nio.file.Files) Node(javafx.scene.Node) IOException(java.io.IOException) File(java.io.File) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) ChronoUnit(java.time.temporal.ChronoUnit) Stage(javafx.stage.Stage) Paths(java.nio.file.Paths) ObservableValue(javafx.beans.value.ObservableValue) LogManager(org.apache.logging.log4j.LogManager) Action(org.controlsfx.control.action.Action) Notifications(org.controlsfx.control.Notifications)

Example 2 with GithubRelease

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.");
    }
}
Also used : Task(javafx.concurrent.Task) Optional(java.util.Optional) Version(eu.fthevenet.util.version.Version) GithubRelease(eu.fthevenet.util.github.GithubRelease)

Aggregations

GithubRelease (eu.fthevenet.util.github.GithubRelease)2 Binjr (eu.fthevenet.binjr.Binjr)1 DataAdapter (eu.fthevenet.binjr.data.adapters.DataAdapter)1 DataAdapterFactory (eu.fthevenet.binjr.data.adapters.DataAdapterFactory)1 DataAdapterInfo (eu.fthevenet.binjr.data.adapters.DataAdapterInfo)1 TimeSeriesBinding (eu.fthevenet.binjr.data.adapters.TimeSeriesBinding)1 AsyncTaskManager (eu.fthevenet.binjr.data.async.AsyncTaskManager)1 CannotInitializeDataAdapterException (eu.fthevenet.binjr.data.exceptions.CannotInitializeDataAdapterException)1 DataAdapterException (eu.fthevenet.binjr.data.exceptions.DataAdapterException)1 NoAdapterFoundException (eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException)1 eu.fthevenet.binjr.data.workspace (eu.fthevenet.binjr.data.workspace)1 DataAdapterDialog (eu.fthevenet.binjr.dialogs.DataAdapterDialog)1 Dialogs (eu.fthevenet.binjr.dialogs.Dialogs)1 StageAppearanceManager (eu.fthevenet.binjr.dialogs.StageAppearanceManager)1 AppEnvironment (eu.fthevenet.binjr.preferences.AppEnvironment)1 GlobalPreferences (eu.fthevenet.binjr.preferences.GlobalPreferences)1 UpdateManager (eu.fthevenet.binjr.preferences.UpdateManager)1 DiagnosticCommand (eu.fthevenet.util.diagnositic.DiagnosticCommand)1 DiagnosticException (eu.fthevenet.util.diagnositic.DiagnosticException)1 eu.fthevenet.util.javafx.controls (eu.fthevenet.util.javafx.controls)1