From 0bb7fd7e8b40e4caf49a02859015a5b67bb50a49 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 4 Aug 2015 12:00:00 +0200 Subject: [PATCH] Cancelling ContributionsSelfCheck will prevent indexes from being updated. Opening boards/libs manager when NotificationPopup is shown will close it --- .../contributions/ContributionsSelfCheck.java | 26 ++++++++++++++++++- .../cc/arduino/view/NotificationPopup.java | 2 +- app/src/processing/app/Base.java | 14 +++++----- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java index 4819b2137..527b8e1ea 100644 --- a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java +++ b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java @@ -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"), "", "", "", ""); } + 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) { diff --git a/app/src/cc/arduino/view/NotificationPopup.java b/app/src/cc/arduino/view/NotificationPopup.java index e3034dda7..7119672bd 100644 --- a/app/src/cc/arduino/view/NotificationPopup.java +++ b/app/src/cc/arduino/view/NotificationPopup.java @@ -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(); } diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 0e6329710..7cc5c2a89 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -94,7 +94,7 @@ public class Base { public static Map FIND_DIALOG_STATE = new HashMap(); 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) {