Skip to content

Commit 1461412

Browse files
committed
Merge pull request arduino#3625 from ffissore/update-notifications
Update notifications
2 parents b68cf12 + 5b0ad4f commit 1461412

22 files changed

+643
-212
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cc.arduino;
2+
3+
import processing.app.Base;
4+
5+
import javax.swing.event.HyperlinkEvent;
6+
import javax.swing.event.HyperlinkListener;
7+
import java.net.URL;
8+
9+
public class UpdatableBoardsLibsFakeURLsHandler implements HyperlinkListener {
10+
11+
private static final String BOARDSMANAGER = "boardsmanager";
12+
private static final String LIBRARYMANAGER = "librarymanager";
13+
14+
private final Base base;
15+
16+
public UpdatableBoardsLibsFakeURLsHandler(Base base) {
17+
this.base = base;
18+
}
19+
20+
@Override
21+
public void hyperlinkUpdate(HyperlinkEvent event) {
22+
if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
23+
return;
24+
}
25+
26+
URL url = event.getURL();
27+
28+
if (BOARDSMANAGER.equals(url.getHost())) {
29+
try {
30+
base.openBoardsManager("", "DropdownUpdatableCoresItem");
31+
} catch (Exception e) {
32+
e.printStackTrace();
33+
}
34+
return;
35+
}
36+
37+
if (LIBRARYMANAGER.equals(url.getHost())) {
38+
base.openLibraryManager("DropdownUpdatableLibrariesItem");
39+
return;
40+
}
41+
42+
throw new IllegalArgumentException(url.getHost() + " is invalid");
43+
}
44+
45+
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ private void builtInPackageIsNewerCheck() throws InterruptedException {
9292
assert base.hasActiveEditor();
9393
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);
9494
if (chosenOption == JOptionPane.YES_OPTION) {
95-
Action openBoardsManager = base.getOpenBoardsManager();
96-
Event event = new Event(base.getActiveEditor(), ActionEvent.ACTION_PERFORMED, installedBuiltIn.getName());
97-
event.getPayload().put("filterText", installedBuiltIn.getName());
98-
openBoardsManager.actionPerformed(event);
95+
try {
96+
base.openBoardsManager(installedBuiltIn.getName(), "");
97+
} catch (Exception e) {
98+
e.printStackTrace();
99+
}
99100
}
100101
});
101102
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package cc.arduino.contributions;
2+
3+
import cc.arduino.contributions.libraries.LibrariesIndexer;
4+
import cc.arduino.contributions.libraries.LibraryInstaller;
5+
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
6+
import cc.arduino.contributions.packages.ContributionInstaller;
7+
import cc.arduino.contributions.packages.ContributionsIndexer;
8+
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
9+
import cc.arduino.view.NotificationPopup;
10+
import processing.app.Base;
11+
import processing.app.I18n;
12+
13+
import javax.swing.*;
14+
import javax.swing.event.HyperlinkListener;
15+
import java.util.TimerTask;
16+
17+
import static processing.app.I18n.tr;
18+
19+
public class ContributionsSelfCheck extends TimerTask {
20+
21+
private final Base base;
22+
private final HyperlinkListener hyperlinkListener;
23+
private final ContributionsIndexer contributionsIndexer;
24+
private final ContributionInstaller contributionInstaller;
25+
private final LibrariesIndexer librariesIndexer;
26+
private final LibraryInstaller libraryInstaller;
27+
private final ProgressListener progressListener;
28+
29+
private volatile boolean cancelled;
30+
private volatile NotificationPopup notificationPopup;
31+
32+
public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, ContributionsIndexer contributionsIndexer, ContributionInstaller contributionInstaller, LibrariesIndexer librariesIndexer, LibraryInstaller libraryInstaller) {
33+
this.base = base;
34+
this.hyperlinkListener = hyperlinkListener;
35+
this.contributionsIndexer = contributionsIndexer;
36+
this.contributionInstaller = contributionInstaller;
37+
this.librariesIndexer = librariesIndexer;
38+
this.libraryInstaller = libraryInstaller;
39+
this.progressListener = new NoopProgressListener();
40+
this.cancelled = false;
41+
}
42+
43+
@Override
44+
public void run() {
45+
updateContributionIndex();
46+
updateLibrariesIndex();
47+
48+
long updatablePlatforms = contributionsIndexer.getPackages().stream()
49+
.flatMap(pack -> pack.getPlatforms().stream())
50+
.filter(new UpdatablePlatformPredicate(contributionsIndexer)).count();
51+
52+
long updatableLibraries = librariesIndexer.getInstalledLibraries().stream()
53+
.filter(new UpdatableLibraryPredicate(librariesIndexer))
54+
.count();
55+
56+
if (updatableLibraries <= 0 && updatablePlatforms <= 0) {
57+
return;
58+
}
59+
60+
String text;
61+
if (updatableLibraries > 0 && updatablePlatforms <= 0) {
62+
text = I18n.format(tr("<br/>Update available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager\">", "</a>");
63+
} else if (updatableLibraries <= 0 && updatablePlatforms > 0) {
64+
text = I18n.format(tr("<br/>Update available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager\">", "</a>");
65+
} else {
66+
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>");
67+
}
68+
69+
if (cancelled) {
70+
return;
71+
}
72+
73+
SwingUtilities.invokeLater(() -> {
74+
notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, text);
75+
notificationPopup.setVisible(true);
76+
});
77+
}
78+
79+
@Override
80+
public boolean cancel() {
81+
cancelled = true;
82+
if (notificationPopup != null) {
83+
notificationPopup.close();
84+
}
85+
return super.cancel();
86+
}
87+
88+
private void updateLibrariesIndex() {
89+
if (cancelled) {
90+
return;
91+
}
92+
try {
93+
libraryInstaller.updateIndex(progressListener);
94+
} catch (Exception e) {
95+
// ignore
96+
}
97+
}
98+
99+
private void updateContributionIndex() {
100+
if (cancelled) {
101+
return;
102+
}
103+
try {
104+
contributionInstaller.updateIndex(progressListener);
105+
} catch (Exception e) {
106+
// ignore
107+
}
108+
}
109+
}

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

+12-27
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import cc.arduino.contributions.libraries.LibraryTypeComparator;
3737
import cc.arduino.contributions.ui.*;
3838
import cc.arduino.utils.Progress;
39-
import processing.app.Platform;
4039

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

5554
private final JComboBox typeChooser;
56-
private final Platform platform;
57-
private LibrariesIndexer indexer;
55+
private final LibrariesIndexer indexer;
56+
private final LibraryInstaller installer;
5857
private Predicate<ContributedLibrary> typeFilter;
5958

6059
@Override
@@ -90,9 +89,10 @@ protected void onRemove(ContributedLibrary library) {
9089
};
9190
}
9291

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

9797
filtersContainer.add(new JLabel(tr("Topic")), 1);
9898
filtersContainer.remove(2);
@@ -125,14 +125,12 @@ public void actionPerformed(ActionEvent event) {
125125
@Override
126126
public void updateIndexFilter(String[] filters, Predicate<ContributedLibrary>... additionalFilters) {
127127
if (additionalFilters.length == 1) {
128-
additionalFilters = new Predicate[] { additionalFilters[0], typeFilter };
128+
additionalFilters = new Predicate[]{additionalFilters[0], typeFilter};
129129
}
130130
super.updateIndexFilter(filters, additionalFilters);
131131
}
132132

133-
public void setIndexer(LibrariesIndexer indexer) {
134-
this.indexer = indexer;
135-
133+
public void updateUI() {
136134
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
137135
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();
138136

@@ -181,29 +179,16 @@ public void setIndexer(LibrariesIndexer indexer) {
181179
}
182180

183181
filterField.setEnabled(contribModel.getRowCount() > 0);
184-
185-
// Create LibrariesInstaller tied with the provided index
186-
installer = new LibraryInstaller(indexer, platform) {
187-
@Override
188-
public void onProgress(Progress progress) {
189-
setProgress(progress);
190-
}
191-
};
192182
}
193183

194-
public LibrariesIndexer getIndexer() {
195-
return indexer;
184+
public void selectDropdownItemByClassName(String dropdownItem) {
185+
selectDropdownItemByClassName(typeChooser, dropdownItem);
196186
}
197187

198188
public void setProgress(Progress progress) {
199189
progressBar.setValue(progress);
200190
}
201191

202-
/*
203-
* Installer methods follows
204-
*/
205-
206-
private LibraryInstaller installer;
207192
private Thread installerThread = null;
208193

209194
@Override
@@ -220,7 +205,7 @@ protected void onUpdatePressed() {
220205
installerThread = new Thread(() -> {
221206
try {
222207
setProgressVisible(true, "");
223-
installer.updateIndex();
208+
installer.updateIndex(this::setProgress);
224209
onIndexesUpdated();
225210
} catch (Exception e) {
226211
throw new RuntimeException(e);
@@ -237,7 +222,7 @@ public void onInstallPressed(final ContributedLibrary lib, final ContributedLibr
237222
installerThread = new Thread(() -> {
238223
try {
239224
setProgressVisible(true, tr("Installing..."));
240-
installer.install(lib, replaced);
225+
installer.install(lib, replaced, this::setProgress);
241226
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
242227
//getContribModel().updateLibrary(lib);
243228
} catch (Exception e) {
@@ -264,7 +249,7 @@ public void onRemovePressed(final ContributedLibrary lib) {
264249
installerThread = new Thread(() -> {
265250
try {
266251
setProgressVisible(true, tr("Removing..."));
267-
installer.remove(lib);
252+
installer.remove(lib, this::setProgress);
268253
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
269254
//getContribModel().updateLibrary(lib);
270255
} catch (Exception e) {

app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java

+8-17
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@
3030
package cc.arduino.contributions.packages.ui;
3131

3232
import cc.arduino.contributions.DownloadableContribution;
33-
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
3433
import cc.arduino.contributions.packages.ContributedPlatform;
3534
import cc.arduino.contributions.packages.ContributionInstaller;
3635
import cc.arduino.contributions.packages.ContributionsIndexer;
3736
import cc.arduino.contributions.ui.*;
3837
import cc.arduino.utils.Progress;
3938
import processing.app.I18n;
40-
import processing.app.Platform;
4139

4240
import javax.swing.*;
4341
import java.awt.*;
@@ -50,7 +48,8 @@
5048
@SuppressWarnings("serial")
5149
public class ContributionManagerUI extends InstallerJDialog {
5250

53-
private final Platform platform;
51+
private final ContributionsIndexer indexer;
52+
private final ContributionInstaller installer;
5453

5554
@Override
5655
protected FilteredAbstractTableModel createContribModel() {
@@ -85,12 +84,13 @@ protected void onRemove(ContributedPlatform installedPlatform) {
8584
};
8685
}
8786

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

93-
public void setIndexer(ContributionsIndexer indexer) {
93+
public void updateUI() {
9494
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
9595

9696
categoryChooser.removeActionListener(categoryChooserActionListener);
@@ -116,14 +116,6 @@ public void setIndexer(ContributionsIndexer indexer) {
116116
} else {
117117
categoryChooser.setSelectedIndex(0);
118118
}
119-
120-
// Create ConstributionInstaller tied with the provided index
121-
installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier()) {
122-
@Override
123-
public void onProgress(Progress progress) {
124-
setProgress(progress);
125-
}
126-
};
127119
}
128120

129121
public void setProgress(Progress progress) {
@@ -134,7 +126,6 @@ public void setProgress(Progress progress) {
134126
* Installer methods follows
135127
*/
136128

137-
private ContributionInstaller installer;
138129
private Thread installerThread = null;
139130

140131
@Override
@@ -151,7 +142,7 @@ public void onUpdatePressed() {
151142
installerThread = new Thread(() -> {
152143
try {
153144
setProgressVisible(true, "");
154-
List<String> downloadedPackageIndexFiles = installer.updateIndex();
145+
List<String> downloadedPackageIndexFiles = installer.updateIndex(this::setProgress);
155146
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
156147
onIndexesUpdated();
157148
} catch (Exception e) {
@@ -170,7 +161,7 @@ public void onInstallPressed(final ContributedPlatform platformToInstall, final
170161
List<String> errors = new LinkedList<>();
171162
try {
172163
setProgressVisible(true, tr("Installing..."));
173-
errors.addAll(installer.install(platformToInstall));
164+
errors.addAll(installer.install(platformToInstall, this::setProgress));
174165
if (platformToRemove != null && !platformToRemove.isReadOnly()) {
175166
errors.addAll(installer.remove(platformToRemove));
176167
}

app/src/cc/arduino/contributions/ui/InstallerJDialog.java

+13
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ public void setFilterText(String filterText) {
276276
filterField.setText(filterText);
277277
}
278278

279+
public void selectDropdownItemByClassName(String dropdownItem) {
280+
selectDropdownItemByClassName(categoryChooser, dropdownItem);
281+
}
282+
283+
public void selectDropdownItemByClassName(JComboBox combo, String dropdownItem) {
284+
for (int i = 0; i < combo.getItemCount(); i++) {
285+
if (dropdownItem.equals(combo.getItemAt(i).getClass().getSimpleName())) {
286+
combo.setSelectedIndex(i);
287+
return;
288+
}
289+
}
290+
}
291+
279292
/**
280293
* Action performed when the Cancel button is pressed.
281294
*/

0 commit comments

Comments
 (0)