use of qupath.lib.gui.extensions.UpdateChecker.ReleaseVersion 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());
}
}
Aggregations