Skip to content

Update notifications #3625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/src/cc/arduino/UpdatableBoardsLibsFakeURLsHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cc.arduino;

import processing.app.Base;

import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.net.URL;

public class UpdatableBoardsLibsFakeURLsHandler implements HyperlinkListener {

private static final String BOARDSMANAGER = "boardsmanager";
private static final String LIBRARYMANAGER = "librarymanager";

private final Base base;

public UpdatableBoardsLibsFakeURLsHandler(Base base) {
this.base = base;
}

@Override
public void hyperlinkUpdate(HyperlinkEvent event) {
if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
return;
}

URL url = event.getURL();

if (BOARDSMANAGER.equals(url.getHost())) {
try {
base.openBoardsManager("", "DropdownUpdatableCoresItem");
} catch (Exception e) {
e.printStackTrace();
}
return;
}

if (LIBRARYMANAGER.equals(url.getHost())) {
base.openLibraryManager("DropdownUpdatableLibrariesItem");
return;
}

throw new IllegalArgumentException(url.getHost() + " is invalid");
}

}
9 changes: 5 additions & 4 deletions app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ private void builtInPackageIsNewerCheck() throws InterruptedException {
assert base.hasActiveEditor();
int chosenOption = JOptionPane.showConfirmDialog(base.getActiveEditor(), I18n.format(tr("The IDE includes an updated {0} package, but you're using an older one.\nDo you want to upgrade {0}?"), installedBuiltIn.getName()), I18n.format(tr("A newer {0} package is available"), installedBuiltIn.getName()), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (chosenOption == JOptionPane.YES_OPTION) {
Action openBoardsManager = base.getOpenBoardsManager();
Event event = new Event(base.getActiveEditor(), ActionEvent.ACTION_PERFORMED, installedBuiltIn.getName());
event.getPayload().put("filterText", installedBuiltIn.getName());
openBoardsManager.actionPerformed(event);
try {
base.openBoardsManager(installedBuiltIn.getName(), "");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Expand Down
109 changes: 109 additions & 0 deletions app/src/cc/arduino/contributions/ContributionsSelfCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package cc.arduino.contributions;

import cc.arduino.contributions.libraries.LibrariesIndexer;
import cc.arduino.contributions.libraries.LibraryInstaller;
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
import cc.arduino.contributions.packages.ContributionInstaller;
import cc.arduino.contributions.packages.ContributionsIndexer;
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
import cc.arduino.view.NotificationPopup;
import processing.app.Base;
import processing.app.I18n;

import javax.swing.*;
import javax.swing.event.HyperlinkListener;
import java.util.TimerTask;

import static processing.app.I18n.tr;

public class ContributionsSelfCheck extends TimerTask {

private final Base base;
private final HyperlinkListener hyperlinkListener;
private final ContributionsIndexer contributionsIndexer;
private final ContributionInstaller contributionInstaller;
private final LibrariesIndexer librariesIndexer;
private final LibraryInstaller libraryInstaller;
private final ProgressListener progressListener;

private volatile boolean cancelled;
private volatile NotificationPopup notificationPopup;

public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, ContributionsIndexer contributionsIndexer, ContributionInstaller contributionInstaller, LibrariesIndexer librariesIndexer, LibraryInstaller libraryInstaller) {
this.base = base;
this.hyperlinkListener = hyperlinkListener;
this.contributionsIndexer = contributionsIndexer;
this.contributionInstaller = contributionInstaller;
this.librariesIndexer = librariesIndexer;
this.libraryInstaller = libraryInstaller;
this.progressListener = new NoopProgressListener();
this.cancelled = false;
}

@Override
public void run() {
updateContributionIndex();
updateLibrariesIndex();

long updatablePlatforms = contributionsIndexer.getPackages().stream()
.flatMap(pack -> pack.getPlatforms().stream())
.filter(new UpdatablePlatformPredicate(contributionsIndexer)).count();

long updatableLibraries = librariesIndexer.getInstalledLibraries().stream()
.filter(new UpdatableLibraryPredicate(librariesIndexer))
.count();

if (updatableLibraries <= 0 && updatablePlatforms <= 0) {
return;
}

String text;
if (updatableLibraries > 0 && updatablePlatforms <= 0) {
text = I18n.format(tr("<br/>Update available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager\">", "</a>");
} else if (updatableLibraries <= 0 && updatablePlatforms > 0) {
text = I18n.format(tr("<br/>Update available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager\">", "</a>");
} else {
text = I18n.format(tr("<br/>Update available for some of your {0}boards{1} and {2}libraries{3}"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
}

if (cancelled) {
return;
}

SwingUtilities.invokeLater(() -> {
notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, text);
notificationPopup.setVisible(true);
});
}

@Override
public boolean cancel() {
cancelled = true;
if (notificationPopup != null) {
notificationPopup.close();
}
return super.cancel();
}

private void updateLibrariesIndex() {
if (cancelled) {
return;
}
try {
libraryInstaller.updateIndex(progressListener);
} catch (Exception e) {
// ignore
}
}

private void updateContributionIndex() {
if (cancelled) {
return;
}
try {
contributionInstaller.updateIndex(progressListener);
} catch (Exception e) {
// ignore
}
}
}
39 changes: 12 additions & 27 deletions app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import cc.arduino.contributions.libraries.LibraryTypeComparator;
import cc.arduino.contributions.ui.*;
import cc.arduino.utils.Progress;
import processing.app.Platform;

import javax.swing.*;
import java.awt.*;
Expand All @@ -53,8 +52,8 @@
public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {

private final JComboBox typeChooser;
private final Platform platform;
private LibrariesIndexer indexer;
private final LibrariesIndexer indexer;
private final LibraryInstaller installer;
private Predicate<ContributedLibrary> typeFilter;

@Override
Expand Down Expand Up @@ -90,9 +89,10 @@ protected void onRemove(ContributedLibrary library) {
};
}

public LibraryManagerUI(Frame parent, Platform platform) {
public LibraryManagerUI(Frame parent, LibrariesIndexer indexer, LibraryInstaller installer) {
super(parent, "Library Manager", Dialog.ModalityType.APPLICATION_MODAL, tr("Unable to reach Arduino.cc due to possible network issues."));
this.platform = platform;
this.indexer = indexer;
this.installer = installer;

filtersContainer.add(new JLabel(tr("Topic")), 1);
filtersContainer.remove(2);
Expand Down Expand Up @@ -125,14 +125,12 @@ public void actionPerformed(ActionEvent event) {
@Override
public void updateIndexFilter(String[] filters, Predicate<ContributedLibrary>... additionalFilters) {
if (additionalFilters.length == 1) {
additionalFilters = new Predicate[] { additionalFilters[0], typeFilter };
additionalFilters = new Predicate[]{additionalFilters[0], typeFilter};
}
super.updateIndexFilter(filters, additionalFilters);
}

public void setIndexer(LibrariesIndexer indexer) {
this.indexer = indexer;

public void updateUI() {
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();

Expand Down Expand Up @@ -181,29 +179,16 @@ public void setIndexer(LibrariesIndexer indexer) {
}

filterField.setEnabled(contribModel.getRowCount() > 0);

// Create LibrariesInstaller tied with the provided index
installer = new LibraryInstaller(indexer, platform) {
@Override
public void onProgress(Progress progress) {
setProgress(progress);
}
};
}

public LibrariesIndexer getIndexer() {
return indexer;
public void selectDropdownItemByClassName(String dropdownItem) {
selectDropdownItemByClassName(typeChooser, dropdownItem);
}

public void setProgress(Progress progress) {
progressBar.setValue(progress);
}

/*
* Installer methods follows
*/

private LibraryInstaller installer;
private Thread installerThread = null;

@Override
Expand All @@ -220,7 +205,7 @@ protected void onUpdatePressed() {
installerThread = new Thread(() -> {
try {
setProgressVisible(true, "");
installer.updateIndex();
installer.updateIndex(this::setProgress);
onIndexesUpdated();
} catch (Exception e) {
throw new RuntimeException(e);
Expand All @@ -237,7 +222,7 @@ public void onInstallPressed(final ContributedLibrary lib, final ContributedLibr
installerThread = new Thread(() -> {
try {
setProgressVisible(true, tr("Installing..."));
installer.install(lib, replaced);
installer.install(lib, replaced, this::setProgress);
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
//getContribModel().updateLibrary(lib);
} catch (Exception e) {
Expand All @@ -264,7 +249,7 @@ public void onRemovePressed(final ContributedLibrary lib) {
installerThread = new Thread(() -> {
try {
setProgressVisible(true, tr("Removing..."));
installer.remove(lib);
installer.remove(lib, this::setProgress);
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
//getContribModel().updateLibrary(lib);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
package cc.arduino.contributions.packages.ui;

import cc.arduino.contributions.DownloadableContribution;
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributionInstaller;
import cc.arduino.contributions.packages.ContributionsIndexer;
import cc.arduino.contributions.ui.*;
import cc.arduino.utils.Progress;
import processing.app.I18n;
import processing.app.Platform;

import javax.swing.*;
import java.awt.*;
Expand All @@ -50,7 +48,8 @@
@SuppressWarnings("serial")
public class ContributionManagerUI extends InstallerJDialog {

private final Platform platform;
private final ContributionsIndexer indexer;
private final ContributionInstaller installer;

@Override
protected FilteredAbstractTableModel createContribModel() {
Expand Down Expand Up @@ -85,12 +84,13 @@ protected void onRemove(ContributedPlatform installedPlatform) {
};
}

public ContributionManagerUI(Frame parent, Platform platform) {
public ContributionManagerUI(Frame parent, ContributionsIndexer indexer, ContributionInstaller installer) {
super(parent, tr("Boards Manager"), Dialog.ModalityType.APPLICATION_MODAL, tr("Unable to reach Arduino.cc due to possible network issues."));
this.platform = platform;
this.indexer = indexer;
this.installer = installer;
}

public void setIndexer(ContributionsIndexer indexer) {
public void updateUI() {
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();

categoryChooser.removeActionListener(categoryChooserActionListener);
Expand All @@ -116,14 +116,6 @@ public void setIndexer(ContributionsIndexer indexer) {
} else {
categoryChooser.setSelectedIndex(0);
}

// Create ConstributionInstaller tied with the provided index
installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier()) {
@Override
public void onProgress(Progress progress) {
setProgress(progress);
}
};
}

public void setProgress(Progress progress) {
Expand All @@ -134,7 +126,6 @@ public void setProgress(Progress progress) {
* Installer methods follows
*/

private ContributionInstaller installer;
private Thread installerThread = null;

@Override
Expand All @@ -151,7 +142,7 @@ public void onUpdatePressed() {
installerThread = new Thread(() -> {
try {
setProgressVisible(true, "");
List<String> downloadedPackageIndexFiles = installer.updateIndex();
List<String> downloadedPackageIndexFiles = installer.updateIndex(this::setProgress);
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
onIndexesUpdated();
} catch (Exception e) {
Expand All @@ -170,7 +161,7 @@ public void onInstallPressed(final ContributedPlatform platformToInstall, final
List<String> errors = new LinkedList<>();
try {
setProgressVisible(true, tr("Installing..."));
errors.addAll(installer.install(platformToInstall));
errors.addAll(installer.install(platformToInstall, this::setProgress));
if (platformToRemove != null && !platformToRemove.isReadOnly()) {
errors.addAll(installer.remove(platformToRemove));
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/cc/arduino/contributions/ui/InstallerJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ public void setFilterText(String filterText) {
filterField.setText(filterText);
}

public void selectDropdownItemByClassName(String dropdownItem) {
selectDropdownItemByClassName(categoryChooser, dropdownItem);
}

public void selectDropdownItemByClassName(JComboBox combo, String dropdownItem) {
for (int i = 0; i < combo.getItemCount(); i++) {
if (dropdownItem.equals(combo.getItemAt(i).getClass().getSimpleName())) {
combo.setSelectedIndex(i);
return;
}
}
}

/**
* Action performed when the Cancel button is pressed.
*/
Expand Down
Loading