mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
Automatically check for updates to contributions in the background.
This commit is contained in:
@@ -53,7 +53,7 @@ public class Base {
|
||||
/** True if heavy debugging error/log messages are enabled */
|
||||
static public boolean DEBUG = false;
|
||||
// static public boolean DEBUG = true;
|
||||
static public boolean ENABLE_LIBRARY_MANAGER = true;
|
||||
static public boolean ENABLE_LIBRARY_MANAGER = false;
|
||||
|
||||
static HashMap<Integer, String> platformNames =
|
||||
new HashMap<Integer, String>();
|
||||
@@ -1404,16 +1404,22 @@ public class Base {
|
||||
* Show the library installer window.
|
||||
*/
|
||||
public void handleAddOrRemoveLibrary() {
|
||||
if (libraryManagerFrame == null) libraryManagerFrame = new ContributionManager();
|
||||
if (libraryManagerFrame == null) libraryManagerFrame = new ContributionManager(activeEditor);
|
||||
libraryManagerFrame.showFrame(activeEditor);
|
||||
}
|
||||
|
||||
|
||||
public void handleShowUpdates() {
|
||||
if (libraryManagerFrame == null) libraryManagerFrame = new ContributionManager(activeEditor);
|
||||
libraryManagerFrame.showFrame(activeEditor);
|
||||
libraryManagerFrame.setFilterText("has:updates");
|
||||
}
|
||||
|
||||
/**
|
||||
* Installed the libraries in the given file after a confirmation from the
|
||||
* user. Returns the number of libraries installed.
|
||||
*/
|
||||
public boolean handleConfirmAndInstallLibrary(File libFile) {
|
||||
if (libraryManagerFrame == null) libraryManagerFrame = new ContributionManager();
|
||||
if (libraryManagerFrame == null) libraryManagerFrame = new ContributionManager(activeEditor);
|
||||
return libraryManagerFrame.confirmAndInstallLibrary(activeEditor, libFile) != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public abstract class Contribution {
|
||||
|
||||
protected String link = "";
|
||||
|
||||
protected ContributionInfo latestVersion;
|
||||
protected ContributionInfo advertisedVersion;
|
||||
|
||||
public static class Author {
|
||||
public String name;
|
||||
@@ -84,8 +84,12 @@ public abstract class Contribution {
|
||||
*/
|
||||
public abstract Contribution getContribution();
|
||||
|
||||
public void setLatestVersion(ContributionInfo advertisedInfo) {
|
||||
latestVersion = advertisedInfo;
|
||||
public void setAdvertisedVersion(ContributionInfo advertisedInfo) {
|
||||
advertisedVersion = advertisedInfo;
|
||||
}
|
||||
|
||||
public boolean hasUpdates() {
|
||||
return advertisedVersion != null && advertisedVersion.version > version;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
|
||||
private ContributionInstaller compilationInstaller;
|
||||
|
||||
|
||||
public ContributionListPanel(ContributionManager libraryManager, ContributionListing libraryListing) {
|
||||
public ContributionListPanel(ContributionManager libraryManager) {
|
||||
super();
|
||||
|
||||
this.contributionManager = libraryManager;
|
||||
@@ -117,24 +117,17 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
|
||||
requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.weightx = 1;
|
||||
c.weighty = 1;
|
||||
c.anchor = GridBagConstraints.CENTER;
|
||||
|
||||
if (libraryListing == null) {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.weightx = 1;
|
||||
c.weighty = 1;
|
||||
c.anchor = GridBagConstraints.CENTER;
|
||||
|
||||
setupProgressBar = new JProgressBar();
|
||||
setupProgressBar.setString("");
|
||||
setupProgressBar.setStringPainted(true);
|
||||
add(setupProgressBar, c);
|
||||
} else {
|
||||
// Add all the libraries in libraryListing to this panel
|
||||
for (ContributionInfo info : libraryListing.getAllLibararies()) {
|
||||
contributionAdded(info);
|
||||
}
|
||||
}
|
||||
setupProgressBar = new JProgressBar();
|
||||
setupProgressBar.setString("");
|
||||
setupProgressBar.setStringPainted(true);
|
||||
add(setupProgressBar, c);
|
||||
|
||||
}
|
||||
|
||||
@@ -502,7 +495,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
if (okayToOpenHyperLink) {
|
||||
if (UPDATE_LINK.equals(e.getURL().toString())) {
|
||||
installContribution(info.latestVersion.link);
|
||||
installContribution(info.advertisedVersion.link);
|
||||
} else {
|
||||
Base.openURL(e.getURL().toString());
|
||||
}
|
||||
@@ -609,8 +602,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib
|
||||
versionText.append("Version ");
|
||||
versionText.append(info.prettyVersion);
|
||||
versionText.append(" installed.");
|
||||
if (info.latestVersion != null
|
||||
&& info.latestVersion.version > info.version) {
|
||||
if (info.hasUpdates()) {
|
||||
versionText.append(" <a href=\"");
|
||||
versionText.append(UPDATE_LINK);
|
||||
versionText.append("\">");
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ContributionListing {
|
||||
|
||||
ContributionInfo advertised = getAdvertisedContribution(contribution.name,
|
||||
contribution.getType());
|
||||
contribution.setLatestVersion(advertised);
|
||||
contribution.setAdvertisedVersion(advertised);
|
||||
|
||||
if (advertised != null) {
|
||||
// Merge information from the advertised and local versions.
|
||||
@@ -181,8 +181,7 @@ public class ContributionListing {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Set<String> getCategories() {
|
||||
return librariesByCategory.keySet();
|
||||
}
|
||||
@@ -224,7 +223,7 @@ public class ContributionListing {
|
||||
|
||||
// Maybe this can be fancy some other time
|
||||
if (filter.equals("has:update") || filter.equals("has:updates")) {
|
||||
return info.latestVersion != null;
|
||||
return info.hasUpdates();
|
||||
}
|
||||
if (filter.equals("is:installed")) {
|
||||
return info.isInstalled();
|
||||
@@ -286,6 +285,13 @@ public class ContributionListing {
|
||||
return new ArrayList<ContributionChangeListener>(listeners);
|
||||
}
|
||||
|
||||
public void getAdvertisedContributions(ProgressMonitor pm) {
|
||||
|
||||
final ContributionListFetcher llf = new ContributionListFetcher();
|
||||
llf.setProgressMonitor(pm);
|
||||
new Thread(llf).start();
|
||||
}
|
||||
|
||||
public static interface ContributionChangeListener {
|
||||
|
||||
public void contributionAdded(ContributionInfo ContributionInfo);
|
||||
@@ -296,9 +302,7 @@ public class ContributionListing {
|
||||
|
||||
}
|
||||
|
||||
public static class ContributionListFetcher implements Runnable {
|
||||
|
||||
ContributionListing libListing;
|
||||
public class ContributionListFetcher implements Runnable {
|
||||
|
||||
File dest;
|
||||
|
||||
@@ -310,9 +314,7 @@ public class ContributionListing {
|
||||
|
||||
ProgressMonitor progressMonitor;
|
||||
|
||||
public ContributionListFetcher(ContributionListing libListing) {
|
||||
|
||||
this.libListing = libListing;
|
||||
public ContributionListFetcher() {
|
||||
|
||||
progressMonitor = new NullProgressMonitor();
|
||||
|
||||
@@ -341,7 +343,7 @@ public class ContributionListing {
|
||||
|
||||
File xmlFile = downloader.getFile();
|
||||
if (xmlFile != null) {
|
||||
libListing.setAdvertisedList(xmlFile);
|
||||
setAdvertisedList(xmlFile);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -349,9 +351,6 @@ public class ContributionListing {
|
||||
downloader.run();
|
||||
}
|
||||
|
||||
public ContributionListing getContributionListing() {
|
||||
return libListing;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -478,4 +477,13 @@ public class ContributionListing {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUpdates() {
|
||||
for (ContributionInfo info : allLibraries) {
|
||||
if (info.hasUpdates()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import processing.app.Contribution.ContributionInfo;
|
||||
import processing.app.ContributionListing.ContributionListFetcher;
|
||||
|
||||
public class ContributionManager {
|
||||
|
||||
@@ -75,9 +74,12 @@ public class ContributionManager {
|
||||
String category;
|
||||
|
||||
ContributionListing contributionListing;
|
||||
|
||||
public ContributionManager() {
|
||||
|
||||
private boolean hasBeenShow;
|
||||
|
||||
public ContributionManager(Editor editor) {
|
||||
|
||||
this.editor = editor;
|
||||
dialog = new JFrame("Contribution Manager");
|
||||
|
||||
Base.setIcon(dialog);
|
||||
@@ -111,11 +113,23 @@ public class ContributionManager {
|
||||
|
||||
pane.add(filterField, c);
|
||||
|
||||
contributionListPanel = new ContributionListPanel(this, contributionListing);
|
||||
if (contributionListing == null) {
|
||||
JProgressBar progressBar = contributionListPanel.getSetupProgressBar();
|
||||
getContributionListing(progressBar);
|
||||
}
|
||||
contributionListing = new ContributionListing();
|
||||
contributionListPanel = new ContributionListPanel(this);
|
||||
contributionListing.addContributionListener(contributionListPanel);
|
||||
|
||||
JProgressBar progressBar = contributionListPanel.getSetupProgressBar();
|
||||
contributionListing.getAdvertisedContributions(new JProgressMonitor(progressBar) {
|
||||
|
||||
@Override
|
||||
public void finishedAction() {
|
||||
synchronized (contributionListing) {
|
||||
updateContributionListing();
|
||||
updateCategoryChooser();
|
||||
|
||||
progressBar.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
@@ -167,15 +181,10 @@ public class ContributionManager {
|
||||
|
||||
private void updateCategoryChooser() {
|
||||
ArrayList<String> categories;
|
||||
if (contributionListing != null) {
|
||||
categoryChooser.removeAllItems();
|
||||
categories = new ArrayList<String>(contributionListing.getCategories());
|
||||
Collections.sort(categories);
|
||||
categories.add(0, ANY_CATEGORY);
|
||||
} else {
|
||||
categories = new ArrayList<String>();
|
||||
categories.add(0, ANY_CATEGORY);
|
||||
}
|
||||
categoryChooser.removeAllItems();
|
||||
categories = new ArrayList<String>(contributionListing.getCategories());
|
||||
Collections.sort(categories);
|
||||
categories.add(0, ANY_CATEGORY);
|
||||
for (String s : categories) {
|
||||
categoryChooser.addItem(s);
|
||||
}
|
||||
@@ -210,6 +219,7 @@ public class ContributionManager {
|
||||
|
||||
protected void showFrame(Editor editor) {
|
||||
this.editor = editor;
|
||||
hasBeenShow = true;
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -220,45 +230,16 @@ public class ContributionManager {
|
||||
dialog.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the library listing has already been downloaded
|
||||
*/
|
||||
public boolean hasContributionListing() {
|
||||
return contributionListing != null;
|
||||
public boolean hasBeenShow() {
|
||||
return hasBeenShow;
|
||||
}
|
||||
|
||||
|
||||
public void filterLibraries(String category, List<String> filters) {
|
||||
|
||||
if (contributionListing != null) {
|
||||
List<ContributionInfo> filteredLibraries = contributionListing
|
||||
.getFilteredLibraryList(category, filters);
|
||||
|
||||
List<ContributionInfo> filteredLibraries = contributionListing
|
||||
.getFilteredLibraryList(category, filters);
|
||||
|
||||
contributionListPanel.filterLibraries(filteredLibraries);
|
||||
}
|
||||
}
|
||||
|
||||
private void getContributionListing(JProgressBar progressBar) {
|
||||
if (contributionListing == null) {
|
||||
contributionListing = new ContributionListing();
|
||||
contributionListing.addContributionListener(contributionListPanel);
|
||||
|
||||
final ContributionListFetcher llf = new ContributionListFetcher(contributionListing);
|
||||
llf.setProgressMonitor(new JProgressMonitor(progressBar) {
|
||||
|
||||
@Override
|
||||
public void finishedAction() {
|
||||
contributionListing = llf.getContributionListing();
|
||||
synchronized (contributionListing) {
|
||||
updateContributionListing();
|
||||
updateCategoryChooser();
|
||||
|
||||
progressBar.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
new Thread(llf).start();
|
||||
}
|
||||
contributionListPanel.filterLibraries(filteredLibraries);
|
||||
}
|
||||
|
||||
protected void updateContributionListing() {
|
||||
@@ -702,6 +683,18 @@ public class ContributionManager {
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void setFilterText(String filter) {
|
||||
if (filter == null || filter.isEmpty()) {
|
||||
filterField.setText("");
|
||||
filterField.isShowingHint = true;
|
||||
} else {
|
||||
filterField.setText(filter);
|
||||
filterField.isShowingHint = false;
|
||||
}
|
||||
filterField.applyFilter();
|
||||
|
||||
}
|
||||
|
||||
class FilterField extends JTextField {
|
||||
|
||||
final static String filterHint = "Filter your search...";
|
||||
@@ -740,29 +733,29 @@ public class ContributionManager {
|
||||
getDocument().addDocumentListener(new DocumentListener() {
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
filter();
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
filter();
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
filter();
|
||||
}
|
||||
|
||||
void filter() {
|
||||
String filter = filterField.getFilterText();
|
||||
filter = filter.toLowerCase();
|
||||
|
||||
// Replace anything but 0-9, a-z, or : with a space
|
||||
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
||||
filters = Arrays.asList(filter.split(" "));
|
||||
filterLibraries(category, filters);
|
||||
applyFilter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void applyFilter() {
|
||||
String filter = filterField.getFilterText();
|
||||
filter = filter.toLowerCase();
|
||||
|
||||
// Replace anything but 0-9, a-z, or : with a space
|
||||
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
||||
filters = Arrays.asList(filter.split(" "));
|
||||
filterLibraries(category, filters);
|
||||
}
|
||||
|
||||
public String getFilterText() {
|
||||
return isShowingHint ? "" : getText();
|
||||
}
|
||||
|
||||
@@ -114,6 +114,10 @@ public class UpdateCheck {
|
||||
"A new version of Processing is available,\n" +
|
||||
"would you like to visit the Processing download page?";
|
||||
|
||||
String contributionPrompt =
|
||||
"There are updates available for some of the installed contributions,\n" +
|
||||
"would you like to open the the Contribution Manager now?";
|
||||
|
||||
if (base.activeEditor != null) {
|
||||
if (latest > Base.REVISION) {
|
||||
Object[] options = { "Yes", "No" };
|
||||
@@ -128,6 +132,27 @@ public class UpdateCheck {
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
Base.openURL("http://processing.org/download/");
|
||||
}
|
||||
} else {
|
||||
if (base.libraryManagerFrame == null)
|
||||
base.libraryManagerFrame = new ContributionManager(base.getActiveEditor());
|
||||
|
||||
Thread.sleep(5 * 1000);
|
||||
if (!base.libraryManagerFrame.hasBeenShow() &&
|
||||
base.libraryManagerFrame.contributionListing.hasUpdates()) {
|
||||
|
||||
Object[] options = { "Yes", "No" };
|
||||
int result = JOptionPane.showOptionDialog(base.activeEditor,
|
||||
contributionPrompt,
|
||||
"Update",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
base.handleShowUpdates();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user