Skip to content

Commit 0bb7fd7

Browse files
author
Federico Fissore
committed
Cancelling ContributionsSelfCheck will prevent indexes from being updated.
Opening boards/libs manager when NotificationPopup is shown will close it
1 parent 2daf330 commit 0bb7fd7

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

app/src/cc/arduino/contributions/ContributionsSelfCheck.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class ContributionsSelfCheck extends TimerTask {
2626
private final LibraryInstaller libraryInstaller;
2727
private final ProgressListener progressListener;
2828

29+
private volatile boolean cancelled;
30+
private volatile NotificationPopup notificationPopup;
31+
2932
public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, ContributionsIndexer contributionsIndexer, ContributionInstaller contributionInstaller, LibrariesIndexer librariesIndexer, LibraryInstaller libraryInstaller) {
3033
this.base = base;
3134
this.hyperlinkListener = hyperlinkListener;
@@ -34,6 +37,7 @@ public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, Co
3437
this.librariesIndexer = librariesIndexer;
3538
this.libraryInstaller = libraryInstaller;
3639
this.progressListener = new NoopProgressListener();
40+
this.cancelled = false;
3741
}
3842

3943
@Override
@@ -62,12 +66,29 @@ public void run() {
6266
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>");
6367
}
6468

69+
if (cancelled) {
70+
return;
71+
}
72+
6573
SwingUtilities.invokeLater(() -> {
66-
new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), text).setVisible(true);
74+
notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, _("Updates available"), text);
75+
notificationPopup.setVisible(true);
6776
});
6877
}
6978

79+
@Override
80+
public boolean cancel() {
81+
cancelled = true;
82+
if (notificationPopup != null) {
83+
notificationPopup.close();
84+
}
85+
return super.cancel();
86+
}
87+
7088
private void updateLibrariesIndex() {
89+
if (cancelled) {
90+
return;
91+
}
7192
try {
7293
libraryInstaller.updateIndex(progressListener);
7394
} catch (Exception e) {
@@ -76,6 +97,9 @@ private void updateLibrariesIndex() {
7697
}
7798

7899
private void updateContributionIndex() {
100+
if (cancelled) {
101+
return;
102+
}
79103
try {
80104
contributionInstaller.updateIndex(progressListener);
81105
} catch (Exception e) {

app/src/cc/arduino/view/NotificationPopup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void updateLocation(Frame parent) {
9898
setLocation(parentX + parent.getWidth() - getWidth(), parentY + parent.getHeight() - getHeight());
9999
}
100100

101-
private void close() {
101+
public void close() {
102102
if (autoCloseAfterTimeout.isRunning()) {
103103
autoCloseAfterTimeout.stop();
104104
}

app/src/processing/app/Base.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public boolean test(UserLibrary library) {
9494
public static Map<String, Object> FIND_DIALOG_STATE = new HashMap<String, Object>();
9595
private final ContributionInstaller contributionInstaller;
9696
private final LibraryInstaller libraryInstaller;
97-
private Timer selfCheckTimer;
97+
private ContributionsSelfCheck contributionsSelfCheck;
9898

9999
// set to true after the first time the menu is built.
100100
// so that the errors while building don't show up again.
@@ -466,8 +466,8 @@ public Base(String[] args) throws Exception {
466466

467467
new Thread(new BuiltInCoreIsNewerCheck(this)).start();
468468

469-
selfCheckTimer = new Timer(false);
470-
selfCheckTimer.schedule(new ContributionsSelfCheck(this, new UpdatableBoardsLibsFakeURLsHandler(this), BaseNoGui.indexer, contributionInstaller, BaseNoGui.librariesIndexer, libraryInstaller), Constants.BOARDS_LIBS_UPDATABLE_CHECK_START_PERIOD);
469+
contributionsSelfCheck = new ContributionsSelfCheck(this, new UpdatableBoardsLibsFakeURLsHandler(this), BaseNoGui.indexer, contributionInstaller, BaseNoGui.librariesIndexer, libraryInstaller);
470+
new Timer(false).schedule(contributionsSelfCheck, Constants.BOARDS_LIBS_UPDATABLE_CHECK_START_PERIOD);
471471

472472
} else if (parser.isNoOpMode()) {
473473
// Do nothing (intended for only changing preferences)
@@ -1228,8 +1228,8 @@ public void onBoardOrPortChange() {
12281228
}
12291229

12301230
public void openLibraryManager(String dropdownItem) {
1231-
if (selfCheckTimer != null) {
1232-
selfCheckTimer.cancel();
1231+
if (contributionsSelfCheck != null) {
1232+
contributionsSelfCheck.cancel();
12331233
}
12341234
@SuppressWarnings("serial")
12351235
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.librariesIndexer, libraryInstaller) {
@@ -1257,8 +1257,8 @@ protected void onIndexesUpdated() throws Exception {
12571257
}
12581258

12591259
public void openBoardsManager(final String filterText, String dropdownItem) throws Exception {
1260-
if (selfCheckTimer != null) {
1261-
selfCheckTimer.cancel();
1260+
if (contributionsSelfCheck != null) {
1261+
contributionsSelfCheck.cancel();
12621262
}
12631263
@SuppressWarnings("serial")
12641264
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.indexer, contributionInstaller) {

0 commit comments

Comments
 (0)