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

This commit is contained in:
Federico Fissore 2015-05-05 13:03:28 +02:00
parent de95ef6c41
commit 85b2298ca7
5 changed files with 125 additions and 18 deletions

View File

@ -0,0 +1,86 @@
package cc.arduino.contributions;
import cc.arduino.contributions.filters.BuiltInPredicate;
import cc.arduino.contributions.filters.InstalledPredicate;
import cc.arduino.contributions.packages.ContributedPackage;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.view.Event;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.LinkedList;
import java.util.List;
import static processing.app.I18n._;
public class BuiltInCoreIsNewerCheck implements Runnable {
private final Base base;
public BuiltInCoreIsNewerCheck(Base base) {
this.base = base;
}
@Override
public void run() {
try {
builtInPackageIsNewerCheck();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void builtInPackageIsNewerCheck() throws InterruptedException {
if (PreferencesData.getInteger("builtin_platform_is_newer", -1) >= BaseNoGui.REVISION) {
return;
}
LinkedList<ContributedPlatform> contributedPlatforms = Lists.newLinkedList(Iterables.concat(Collections2.transform(BaseNoGui.indexer.getPackages(), new Function<ContributedPackage, List<ContributedPlatform>>() {
@Override
public List<ContributedPlatform> apply(ContributedPackage input) {
return input.getPlatforms();
}
})));
List<ContributedPlatform> installedBuiltInPlatforms = new LinkedList<ContributedPlatform>(Collections2.filter(contributedPlatforms, Predicates.and(new InstalledPredicate(), new BuiltInPredicate())));
if (installedBuiltInPlatforms.size() != 1) {
return;
}
final ContributedPlatform installedBuiltIn = installedBuiltInPlatforms.get(0);
ContributedPlatform installedNotBuiltIn = BaseNoGui.indexer.getInstalled(installedBuiltIn.getParentPackage().getName(), installedBuiltIn.getArchitecture());
if (installedNotBuiltIn == null) {
return;
}
while (!base.hasActiveEditor()) {
Thread.sleep(100);
}
if (VersionHelper.valueOf(installedBuiltIn.getParsedVersion()).greaterThan(VersionHelper.valueOf(installedNotBuiltIn.getParsedVersion()))) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
PreferencesData.setInteger("builtin_platform_is_newer", BaseNoGui.REVISION);
assert base.hasActiveEditor();
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);
if (chosenOption == JOptionPane.YES_OPTION) {
Action openBoardsManager = base.getOpenBoardsManager();
Event event = new Event(base.getActiveEditor(), ActionEvent.ACTION_PERFORMED, installedBuiltIn.getName());
event.getPayload().put("filterText", installedBuiltIn.getName());
openBoardsManager.actionPerformed(event);
}
}
});
}
}
}

View File

@ -29,6 +29,7 @@
package cc.arduino.contributions.libraries.filters;
import cc.arduino.contributions.filters.InstalledPredicate;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.LibrariesIndex;
import com.google.common.base.Predicate;
@ -50,12 +51,7 @@ public class InstalledLibraryPredicate implements Predicate<ContributedLibrary>
return true;
}
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new Predicate<ContributedLibrary>() {
@Override
public boolean apply(ContributedLibrary input) {
return input.isInstalled();
}
});
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new InstalledPredicate());
return !installed.isEmpty();
}

View File

@ -41,10 +41,7 @@ import javax.swing.border.EmptyBorder;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
@ -280,6 +277,13 @@ public abstract class InstallerJDialog<T> extends JDialog {
}
};
public void setFilterText(String filterText) {
for (FocusListener listener : filterField.getFocusListeners()) {
listener.focusGained(new FocusEvent(filterField, FocusEvent.FOCUS_GAINED));
}
filterField.setText(filterText);
}
/**
* Action performed when the Cancel button is pressed.
*/

View File

@ -22,7 +22,7 @@
package processing.app;
import cc.arduino.DefaultUncaughtExceptionHandler;
import cc.arduino.contributions.BuiltInCoreIsNewerCheck;
import cc.arduino.contributions.DownloadableContributionVersionComparator;
import cc.arduino.contributions.VersionHelper;
import cc.arduino.contributions.libraries.ContributedLibrary;
@ -36,7 +36,8 @@ import cc.arduino.contributions.packages.ui.ContributionManagerUI;
import cc.arduino.files.DeleteFilesOnShutdown;
import cc.arduino.packages.DiscoveryManager;
import cc.arduino.utils.Progress;
import cc.arduino.view.SplashScreenHelper;
import cc.arduino.view.*;
import cc.arduino.view.Event;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
@ -111,6 +112,7 @@ public class Base {
// are the same for all windows (since the board and serial port that are
// actually used are determined by the preferences, which are shared)
private List<JMenu> boardsCustomMenus;
private volatile Action openBoardsManager;
static public void main(String args[]) throws Exception {
System.setProperty("awt.useSystemAAFontSettings", "on");
@ -446,6 +448,9 @@ public class Base {
if (PreferencesData.getBoolean("update.check")) {
new UpdateCheck(this);
}
new Thread(new BuiltInCoreIsNewerCheck(this)).start();
} else if (parser.isNoOpMode()) {
// Do nothing (intended for only changing preferences)
System.exit(0);
@ -1265,7 +1270,7 @@ public class Base {
rebuildExamplesMenu(Editor.examplesMenu);
}
private void openInstallBoardDialog() throws Exception {
private void openInstallBoardDialog(final String filterText) throws Exception {
// Create dialog for contribution manager
@SuppressWarnings("serial")
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
@ -1274,6 +1279,10 @@ public class Base {
BaseNoGui.initPackages();
rebuildBoardsMenu();
setIndexer(BaseNoGui.indexer);
if (StringUtils.isNotEmpty(filterText)) {
setFilterText(filterText);
}
}
};
managerUI.setLocationRelativeTo(activeEditor);
@ -1294,18 +1303,22 @@ public class Base {
JMenu boardMenu = new JMenu(_("Board"));
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
MenuScroller.setScrollerFor(boardMenu);
@SuppressWarnings("serial")
Action runInstaller = new AbstractAction(_("Boards Manager...")) {
openBoardsManager = new AbstractAction(_("Boards Manager...")) {
public void actionPerformed(ActionEvent actionevent) {
String filterText = "";
if (actionevent instanceof cc.arduino.view.Event) {
filterText = ((Event) actionevent).getPayload().get("filterText").toString();
}
try {
openInstallBoardDialog();
openInstallBoardDialog(filterText);
} catch (Exception e) {
//TODO show error
e.printStackTrace();
}
}
};
boardMenu.add(new JMenuItem(runInstaller));
boardMenu.add(new JMenuItem(openBoardsManager));
boardsCustomMenus.add(boardMenu);
// If there are no platforms installed we are done
@ -2700,7 +2713,15 @@ public class Base {
return activeEditor;
}
public boolean hasActiveEditor() {
return activeEditor != null;
}
public List<Editor> getEditors() {
return new LinkedList<Editor>(editors);
}
public Action getOpenBoardsManager() {
return openBoardsManager;
}
}

View File

@ -64,7 +64,7 @@ public class BaseNoGui {
static File portableFolder = null;
static final String portableSketchbookFolder = "sketchbook";
static ContributionsIndexer indexer;
public static ContributionsIndexer indexer;
static LibrariesIndexer librariesIndexer;
// Returns a File object for the given pathname. If the pathname