1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Cancelling ContributionsSelfCheck will prevent indexes from being updated.

Opening boards/libs manager when NotificationPopup is shown will close it
This commit is contained in:
Federico Fissore 2015-08-04 12:00:00 +02:00
parent 2daf330c09
commit 0bb7fd7e8b
3 changed files with 33 additions and 9 deletions

View File

@ -26,6 +26,9 @@ public class ContributionsSelfCheck extends TimerTask {
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;
@ -34,6 +37,7 @@ public class ContributionsSelfCheck extends TimerTask {
this.librariesIndexer = librariesIndexer;
this.libraryInstaller = libraryInstaller;
this.progressListener = new NoopProgressListener();
this.cancelled = false;
}
@Override
@ -62,12 +66,29 @@ public class ContributionsSelfCheck extends TimerTask {
text = I18n.format(_("Some {0}boards{1} and some {2}libraries{3} may be updated"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
}
if (cancelled) {
return;
}
SwingUtilities.invokeLater(() -> {
new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), text).setVisible(true);
notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), 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) {
@ -76,6 +97,9 @@ public class ContributionsSelfCheck extends TimerTask {
}
private void updateContributionIndex() {
if (cancelled) {
return;
}
try {
contributionInstaller.updateIndex(progressListener);
} catch (Exception e) {

View File

@ -98,7 +98,7 @@ public class NotificationPopup extends JDialog {
setLocation(parentX + parent.getWidth() - getWidth(), parentY + parent.getHeight() - getHeight());
}
private void close() {
public void close() {
if (autoCloseAfterTimeout.isRunning()) {
autoCloseAfterTimeout.stop();
}

View File

@ -94,7 +94,7 @@ public class Base {
public static Map<String, Object> FIND_DIALOG_STATE = new HashMap<String, Object>();
private final ContributionInstaller contributionInstaller;
private final LibraryInstaller libraryInstaller;
private Timer selfCheckTimer;
private ContributionsSelfCheck contributionsSelfCheck;
// set to true after the first time the menu is built.
// so that the errors while building don't show up again.
@ -466,8 +466,8 @@ public class Base {
new Thread(new BuiltInCoreIsNewerCheck(this)).start();
selfCheckTimer = new Timer(false);
selfCheckTimer.schedule(new ContributionsSelfCheck(this, new UpdatableBoardsLibsFakeURLsHandler(this), BaseNoGui.indexer, contributionInstaller, BaseNoGui.librariesIndexer, libraryInstaller), Constants.BOARDS_LIBS_UPDATABLE_CHECK_START_PERIOD);
contributionsSelfCheck = new ContributionsSelfCheck(this, new UpdatableBoardsLibsFakeURLsHandler(this), BaseNoGui.indexer, contributionInstaller, BaseNoGui.librariesIndexer, libraryInstaller);
new Timer(false).schedule(contributionsSelfCheck, Constants.BOARDS_LIBS_UPDATABLE_CHECK_START_PERIOD);
} else if (parser.isNoOpMode()) {
// Do nothing (intended for only changing preferences)
@ -1228,8 +1228,8 @@ public class Base {
}
public void openLibraryManager(String dropdownItem) {
if (selfCheckTimer != null) {
selfCheckTimer.cancel();
if (contributionsSelfCheck != null) {
contributionsSelfCheck.cancel();
}
@SuppressWarnings("serial")
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.librariesIndexer, libraryInstaller) {
@ -1257,8 +1257,8 @@ public class Base {
}
public void openBoardsManager(final String filterText, String dropdownItem) throws Exception {
if (selfCheckTimer != null) {
selfCheckTimer.cancel();
if (contributionsSelfCheck != null) {
contributionsSelfCheck.cancel();
}
@SuppressWarnings("serial")
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.indexer, contributionInstaller) {