Search in sources :

Example 1 with GitHubProject

use of qupath.lib.gui.extensions.GitHubProject in project qupath by qupath.

the class QuPathGUI method doUpdateCheck.

/**
 * Do an update check.
 * @param isAutoCheck if true, avoid prompting the user unless an update is available. If false, the update has been explicitly
 *                    requested and so the user should be notified of the outcome, regardless of whether an update is found.
 */
private synchronized void doUpdateCheck(boolean isAutoCheck) {
    String title = "Update check";
    // Get a map of all the projects we can potentially check
    Map<GitHubRepo, Version> projects = new LinkedHashMap<>();
    Map<GitHubRepo, ReleaseVersion> projectUpdates = new LinkedHashMap<>();
    // Start with the main app
    var qupathVersion = getVersion();
    if (qupathVersion != null && qupathVersion != Version.UNKNOWN) {
        projects.put(GitHubRepo.create("QuPath", "qupath", "qupath"), qupathVersion);
    }
    // Work through extensions
    for (var ext : getLoadedExtensions()) {
        var v = ext.getVersion();
        if (v != null && v != Version.UNKNOWN && ext instanceof GitHubProject) {
            var project = (GitHubProject) ext;
            projects.put(project.getRepository(), v);
        }
    }
    // Report if there is nothing to update
    if (projects.isEmpty()) {
        if (isAutoCheck) {
            logger.warn("Cannot check for updates for this installation");
        } else {
            Dialogs.showMessageDialog(title, "Sorry, no update check is available for this installation");
        }
        return;
    }
    // Check for any updates
    for (var entry : projects.entrySet()) {
        try {
            var project = entry.getKey();
            logger.info("Update check for {}", project.getUrlString());
            var release = UpdateChecker.checkForUpdate(entry.getKey());
            if (release != null && release.getVersion() != Version.UNKNOWN && entry.getValue().compareTo(release.getVersion()) < 0)
                projectUpdates.put(project, release);
        } catch (Exception e) {
            logger.error("Update check failed for {}", entry.getKey());
            logger.debug(e.getLocalizedMessage(), e);
        }
    }
    PathPrefs.getUserPreferences().putLong("lastUpdateCheck", System.currentTimeMillis());
    // If we couldn't determine the version, tell the user only if this isn't the automatic check
    if (projectUpdates.isEmpty()) {
        if (!isAutoCheck)
            Dialogs.showMessageDialog(title, "No updates found!");
        return;
    }
    // Create a table showing the updates available
    var table = new TableView<GitHubRepo>();
    table.getItems().setAll(projectUpdates.keySet());
    var colRepo = new TableColumn<GitHubRepo, String>("Name");
    colRepo.setCellValueFactory(r -> new SimpleStringProperty(r.getValue().getName()));
    var colCurrent = new TableColumn<GitHubRepo, String>("Current version");
    colCurrent.setCellValueFactory(r -> new SimpleStringProperty(projects.get(r.getValue()).toString()));
    var colNew = new TableColumn<GitHubRepo, String>("New version");
    colNew.setCellValueFactory(r -> new SimpleStringProperty(projectUpdates.get(r.getValue()).getVersion().toString()));
    table.setRowFactory(r -> {
        var row = new TableRow<GitHubRepo>();
        row.itemProperty().addListener((v, o, n) -> {
            if (n == null) {
                row.setTooltip(null);
                row.setOnMouseClicked(null);
            } else {
                var release = projectUpdates.get(n);
                var uri = release.getUri();
                if (uri == null) {
                    row.setTooltip(new Tooltip("No URL available, sorry!"));
                    row.setOnMouseClicked(null);
                } else {
                    row.setTooltip(new Tooltip(uri.toString()));
                    row.setOnMouseClicked(e -> {
                        if (e.getClickCount() > 1) {
                            launchBrowserWindow(uri.toString());
                        }
                    });
                }
            }
        });
        return row;
    });
    table.getColumns().setAll(Arrays.asList(colRepo, colCurrent, colNew));
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.setPrefHeight(200);
    table.setPrefWidth(500);
    var checkbox = new CheckBox("Automatically check for updates on startup");
    checkbox.setSelected(PathPrefs.doAutoUpdateCheckProperty().get());
    checkbox.setMaxWidth(Double.MAX_VALUE);
    var pane = new BorderPane(table);
    checkbox.setPadding(new Insets(5, 0, 0, 0));
    pane.setBottom(checkbox);
    var result = new Dialogs.Builder().buttons(ButtonType.OK).title(title).headerText("Updates are available!\nDouble-click an entry to open the webpage, if available.").content(pane).resizable().showAndWait().orElse(ButtonType.CANCEL) == ButtonType.OK;
    if (result) {
        PathPrefs.doAutoUpdateCheckProperty().set(checkbox.isSelected());
    }
}
Also used : BorderPane(javafx.scene.layout.BorderPane) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) ServerBuilder(qupath.lib.images.servers.ImageServerBuilder.ServerBuilder) ImageServerBuilder(qupath.lib.images.servers.ImageServerBuilder) GitHubProject(qupath.lib.gui.extensions.GitHubProject) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ScriptException(javax.script.ScriptException) FileNotFoundException(java.io.FileNotFoundException) LinkedHashMap(java.util.LinkedHashMap) ReleaseVersion(qupath.lib.gui.extensions.UpdateChecker.ReleaseVersion) Version(qupath.lib.common.Version) ReleaseVersion(qupath.lib.gui.extensions.UpdateChecker.ReleaseVersion) CheckBox(javafx.scene.control.CheckBox) TableRow(javafx.scene.control.TableRow) GitHubRepo(qupath.lib.gui.extensions.GitHubProject.GitHubRepo) SelectedMeasurementTableView(qupath.lib.gui.panes.SelectedMeasurementTableView) TreeTableView(javafx.scene.control.TreeTableView) TableView(javafx.scene.control.TableView)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashMap (java.util.LinkedHashMap)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 Insets (javafx.geometry.Insets)1 CheckBox (javafx.scene.control.CheckBox)1 TableColumn (javafx.scene.control.TableColumn)1 TableRow (javafx.scene.control.TableRow)1 TableView (javafx.scene.control.TableView)1 Tooltip (javafx.scene.control.Tooltip)1 TreeTableView (javafx.scene.control.TreeTableView)1 BorderPane (javafx.scene.layout.BorderPane)1 ScriptException (javax.script.ScriptException)1 Version (qupath.lib.common.Version)1 GitHubProject (qupath.lib.gui.extensions.GitHubProject)1 GitHubRepo (qupath.lib.gui.extensions.GitHubProject.GitHubRepo)1 ReleaseVersion (qupath.lib.gui.extensions.UpdateChecker.ReleaseVersion)1 SelectedMeasurementTableView (qupath.lib.gui.panes.SelectedMeasurementTableView)1 ImageServerBuilder (qupath.lib.images.servers.ImageServerBuilder)1