Skip to content

Commit 85b2298

Browse files
author
Federico Fissore
committed
When IDE is started and built in core is newer than installed one and this check hasn't been notified before, show "please update" modal
1 parent de95ef6 commit 85b2298

File tree

5 files changed

+125
-18
lines changed

5 files changed

+125
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package cc.arduino.contributions;
2+
3+
import cc.arduino.contributions.filters.BuiltInPredicate;
4+
import cc.arduino.contributions.filters.InstalledPredicate;
5+
import cc.arduino.contributions.packages.ContributedPackage;
6+
import cc.arduino.contributions.packages.ContributedPlatform;
7+
import cc.arduino.view.Event;
8+
import com.google.common.base.Function;
9+
import com.google.common.base.Predicates;
10+
import com.google.common.collect.Collections2;
11+
import com.google.common.collect.Iterables;
12+
import com.google.common.collect.Lists;
13+
import processing.app.Base;
14+
import processing.app.BaseNoGui;
15+
import processing.app.I18n;
16+
import processing.app.PreferencesData;
17+
18+
import javax.swing.*;
19+
import java.awt.event.ActionEvent;
20+
import java.util.LinkedList;
21+
import java.util.List;
22+
23+
import static processing.app.I18n._;
24+
25+
public class BuiltInCoreIsNewerCheck implements Runnable {
26+
27+
private final Base base;
28+
29+
public BuiltInCoreIsNewerCheck(Base base) {
30+
this.base = base;
31+
}
32+
33+
@Override
34+
public void run() {
35+
try {
36+
builtInPackageIsNewerCheck();
37+
} catch (InterruptedException e) {
38+
e.printStackTrace();
39+
}
40+
}
41+
42+
private void builtInPackageIsNewerCheck() throws InterruptedException {
43+
if (PreferencesData.getInteger("builtin_platform_is_newer", -1) >= BaseNoGui.REVISION) {
44+
return;
45+
}
46+
47+
LinkedList<ContributedPlatform> contributedPlatforms = Lists.newLinkedList(Iterables.concat(Collections2.transform(BaseNoGui.indexer.getPackages(), new Function<ContributedPackage, List<ContributedPlatform>>() {
48+
@Override
49+
public List<ContributedPlatform> apply(ContributedPackage input) {
50+
return input.getPlatforms();
51+
}
52+
})));
53+
54+
List<ContributedPlatform> installedBuiltInPlatforms = new LinkedList<ContributedPlatform>(Collections2.filter(contributedPlatforms, Predicates.and(new InstalledPredicate(), new BuiltInPredicate())));
55+
if (installedBuiltInPlatforms.size() != 1) {
56+
return;
57+
}
58+
final ContributedPlatform installedBuiltIn = installedBuiltInPlatforms.get(0);
59+
60+
ContributedPlatform installedNotBuiltIn = BaseNoGui.indexer.getInstalled(installedBuiltIn.getParentPackage().getName(), installedBuiltIn.getArchitecture());
61+
if (installedNotBuiltIn == null) {
62+
return;
63+
}
64+
65+
while (!base.hasActiveEditor()) {
66+
Thread.sleep(100);
67+
}
68+
69+
if (VersionHelper.valueOf(installedBuiltIn.getParsedVersion()).greaterThan(VersionHelper.valueOf(installedNotBuiltIn.getParsedVersion()))) {
70+
SwingUtilities.invokeLater(new Runnable() {
71+
@Override
72+
public void run() {
73+
PreferencesData.setInteger("builtin_platform_is_newer", BaseNoGui.REVISION);
74+
assert base.hasActiveEditor();
75+
int chosenOption = JOptionPane.showConfirmDialog(base.getActiveEditor(), I18n.format(_("The IDE includes an updated {0} package, but you're using an older one.\nDo you want to upgrade {0}?"), installedBuiltIn.getName()), I18n.format(_("A newer {0} package is available"), installedBuiltIn.getName()), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
76+
if (chosenOption == JOptionPane.YES_OPTION) {
77+
Action openBoardsManager = base.getOpenBoardsManager();
78+
Event event = new Event(base.getActiveEditor(), ActionEvent.ACTION_PERFORMED, installedBuiltIn.getName());
79+
event.getPayload().put("filterText", installedBuiltIn.getName());
80+
openBoardsManager.actionPerformed(event);
81+
}
82+
}
83+
});
84+
}
85+
}
86+
}

app/src/cc/arduino/contributions/libraries/filters/InstalledLibraryPredicate.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
package cc.arduino.contributions.libraries.filters;
3131

32+
import cc.arduino.contributions.filters.InstalledPredicate;
3233
import cc.arduino.contributions.libraries.ContributedLibrary;
3334
import cc.arduino.contributions.libraries.LibrariesIndex;
3435
import com.google.common.base.Predicate;
@@ -50,12 +51,7 @@ public boolean apply(ContributedLibrary input) {
5051
return true;
5152
}
5253

53-
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new Predicate<ContributedLibrary>() {
54-
@Override
55-
public boolean apply(ContributedLibrary input) {
56-
return input.isInstalled();
57-
}
58-
});
54+
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new InstalledPredicate());
5955

6056
return !installed.isEmpty();
6157
}

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141
import javax.swing.table.TableColumn;
4242
import javax.swing.table.TableColumnModel;
4343
import java.awt.*;
44-
import java.awt.event.ActionEvent;
45-
import java.awt.event.ActionListener;
46-
import java.awt.event.KeyEvent;
47-
import java.awt.event.WindowEvent;
44+
import java.awt.event.*;
4845
import java.util.Arrays;
4946
import java.util.Collection;
5047
import java.util.LinkedList;
@@ -280,6 +277,13 @@ public void actionPerformed(ActionEvent event) {
280277
}
281278
};
282279

280+
public void setFilterText(String filterText) {
281+
for (FocusListener listener : filterField.getFocusListeners()) {
282+
listener.focusGained(new FocusEvent(filterField, FocusEvent.FOCUS_GAINED));
283+
}
284+
filterField.setText(filterText);
285+
}
286+
283287
/**
284288
* Action performed when the Cancel button is pressed.
285289
*/

app/src/processing/app/Base.java

+28-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
package processing.app;
2424

25-
import cc.arduino.DefaultUncaughtExceptionHandler;
25+
import cc.arduino.contributions.BuiltInCoreIsNewerCheck;
2626
import cc.arduino.contributions.DownloadableContributionVersionComparator;
2727
import cc.arduino.contributions.VersionHelper;
2828
import cc.arduino.contributions.libraries.ContributedLibrary;
@@ -36,7 +36,8 @@
3636
import cc.arduino.files.DeleteFilesOnShutdown;
3737
import cc.arduino.packages.DiscoveryManager;
3838
import cc.arduino.utils.Progress;
39-
import cc.arduino.view.SplashScreenHelper;
39+
import cc.arduino.view.*;
40+
import cc.arduino.view.Event;
4041
import com.google.common.base.Predicate;
4142
import com.google.common.base.Predicates;
4243
import com.google.common.collect.Collections2;
@@ -111,6 +112,7 @@ public boolean apply(UserLibrary library) {
111112
// are the same for all windows (since the board and serial port that are
112113
// actually used are determined by the preferences, which are shared)
113114
private List<JMenu> boardsCustomMenus;
115+
private volatile Action openBoardsManager;
114116

115117
static public void main(String args[]) throws Exception {
116118
System.setProperty("awt.useSystemAAFontSettings", "on");
@@ -446,6 +448,9 @@ protected void onProgress(Progress progress) {
446448
if (PreferencesData.getBoolean("update.check")) {
447449
new UpdateCheck(this);
448450
}
451+
452+
new Thread(new BuiltInCoreIsNewerCheck(this)).start();
453+
449454
} else if (parser.isNoOpMode()) {
450455
// Do nothing (intended for only changing preferences)
451456
System.exit(0);
@@ -1265,7 +1270,7 @@ protected void onIndexesUpdated() throws Exception {
12651270
rebuildExamplesMenu(Editor.examplesMenu);
12661271
}
12671272

1268-
private void openInstallBoardDialog() throws Exception {
1273+
private void openInstallBoardDialog(final String filterText) throws Exception {
12691274
// Create dialog for contribution manager
12701275
@SuppressWarnings("serial")
12711276
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
@@ -1274,6 +1279,10 @@ protected void onIndexesUpdated() throws Exception {
12741279
BaseNoGui.initPackages();
12751280
rebuildBoardsMenu();
12761281
setIndexer(BaseNoGui.indexer);
1282+
if (StringUtils.isNotEmpty(filterText)) {
1283+
setFilterText(filterText);
1284+
}
1285+
12771286
}
12781287
};
12791288
managerUI.setLocationRelativeTo(activeEditor);
@@ -1294,18 +1303,22 @@ public void rebuildBoardsMenu() throws Exception {
12941303
JMenu boardMenu = new JMenu(_("Board"));
12951304
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
12961305
MenuScroller.setScrollerFor(boardMenu);
1297-
@SuppressWarnings("serial")
1298-
Action runInstaller = new AbstractAction(_("Boards Manager...")) {
1306+
1307+
openBoardsManager = new AbstractAction(_("Boards Manager...")) {
12991308
public void actionPerformed(ActionEvent actionevent) {
1309+
String filterText = "";
1310+
if (actionevent instanceof cc.arduino.view.Event) {
1311+
filterText = ((Event) actionevent).getPayload().get("filterText").toString();
1312+
}
13001313
try {
1301-
openInstallBoardDialog();
1314+
openInstallBoardDialog(filterText);
13021315
} catch (Exception e) {
13031316
//TODO show error
13041317
e.printStackTrace();
13051318
}
13061319
}
13071320
};
1308-
boardMenu.add(new JMenuItem(runInstaller));
1321+
boardMenu.add(new JMenuItem(openBoardsManager));
13091322
boardsCustomMenus.add(boardMenu);
13101323

13111324
// If there are no platforms installed we are done
@@ -2700,7 +2713,15 @@ public Editor getActiveEditor() {
27002713
return activeEditor;
27012714
}
27022715

2716+
public boolean hasActiveEditor() {
2717+
return activeEditor != null;
2718+
}
2719+
27032720
public List<Editor> getEditors() {
27042721
return new LinkedList<Editor>(editors);
27052722
}
2723+
2724+
public Action getOpenBoardsManager() {
2725+
return openBoardsManager;
2726+
}
27062727
}

arduino-core/src/processing/app/BaseNoGui.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class BaseNoGui {
6464
static File portableFolder = null;
6565
static final String portableSketchbookFolder = "sketchbook";
6666

67-
static ContributionsIndexer indexer;
67+
public static ContributionsIndexer indexer;
6868
static LibrariesIndexer librariesIndexer;
6969

7070
// Returns a File object for the given pathname. If the pathname

0 commit comments

Comments
 (0)