mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
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:
parent
de95ef6c41
commit
85b2298ca7
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.filters;
|
package cc.arduino.contributions.libraries.filters;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.LibrariesIndex;
|
import cc.arduino.contributions.libraries.LibrariesIndex;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
@ -50,12 +51,7 @@ public class InstalledLibraryPredicate implements Predicate<ContributedLibrary>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new Predicate<ContributedLibrary>() {
|
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new InstalledPredicate());
|
||||||
@Override
|
|
||||||
public boolean apply(ContributedLibrary input) {
|
|
||||||
return input.isInstalled();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return !installed.isEmpty();
|
return !installed.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,7 @@ import javax.swing.border.EmptyBorder;
|
|||||||
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumn;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.event.WindowEvent;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
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.
|
* Action performed when the Cancel button is pressed.
|
||||||
*/
|
*/
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
package processing.app;
|
package processing.app;
|
||||||
|
|
||||||
import cc.arduino.DefaultUncaughtExceptionHandler;
|
import cc.arduino.contributions.BuiltInCoreIsNewerCheck;
|
||||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||||
import cc.arduino.contributions.VersionHelper;
|
import cc.arduino.contributions.VersionHelper;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
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.files.DeleteFilesOnShutdown;
|
||||||
import cc.arduino.packages.DiscoveryManager;
|
import cc.arduino.packages.DiscoveryManager;
|
||||||
import cc.arduino.utils.Progress;
|
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.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Collections2;
|
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
|
// are the same for all windows (since the board and serial port that are
|
||||||
// actually used are determined by the preferences, which are shared)
|
// actually used are determined by the preferences, which are shared)
|
||||||
private List<JMenu> boardsCustomMenus;
|
private List<JMenu> boardsCustomMenus;
|
||||||
|
private volatile Action openBoardsManager;
|
||||||
|
|
||||||
static public void main(String args[]) throws Exception {
|
static public void main(String args[]) throws Exception {
|
||||||
System.setProperty("awt.useSystemAAFontSettings", "on");
|
System.setProperty("awt.useSystemAAFontSettings", "on");
|
||||||
@ -446,6 +448,9 @@ public class Base {
|
|||||||
if (PreferencesData.getBoolean("update.check")) {
|
if (PreferencesData.getBoolean("update.check")) {
|
||||||
new UpdateCheck(this);
|
new UpdateCheck(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Thread(new BuiltInCoreIsNewerCheck(this)).start();
|
||||||
|
|
||||||
} else if (parser.isNoOpMode()) {
|
} else if (parser.isNoOpMode()) {
|
||||||
// Do nothing (intended for only changing preferences)
|
// Do nothing (intended for only changing preferences)
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@ -1265,7 +1270,7 @@ public class Base {
|
|||||||
rebuildExamplesMenu(Editor.examplesMenu);
|
rebuildExamplesMenu(Editor.examplesMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openInstallBoardDialog() throws Exception {
|
private void openInstallBoardDialog(final String filterText) throws Exception {
|
||||||
// Create dialog for contribution manager
|
// Create dialog for contribution manager
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
|
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
|
||||||
@ -1274,6 +1279,10 @@ public class Base {
|
|||||||
BaseNoGui.initPackages();
|
BaseNoGui.initPackages();
|
||||||
rebuildBoardsMenu();
|
rebuildBoardsMenu();
|
||||||
setIndexer(BaseNoGui.indexer);
|
setIndexer(BaseNoGui.indexer);
|
||||||
|
if (StringUtils.isNotEmpty(filterText)) {
|
||||||
|
setFilterText(filterText);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
managerUI.setLocationRelativeTo(activeEditor);
|
managerUI.setLocationRelativeTo(activeEditor);
|
||||||
@ -1294,18 +1303,22 @@ public class Base {
|
|||||||
JMenu boardMenu = new JMenu(_("Board"));
|
JMenu boardMenu = new JMenu(_("Board"));
|
||||||
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
|
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
|
||||||
MenuScroller.setScrollerFor(boardMenu);
|
MenuScroller.setScrollerFor(boardMenu);
|
||||||
@SuppressWarnings("serial")
|
|
||||||
Action runInstaller = new AbstractAction(_("Boards Manager...")) {
|
openBoardsManager = new AbstractAction(_("Boards Manager...")) {
|
||||||
public void actionPerformed(ActionEvent actionevent) {
|
public void actionPerformed(ActionEvent actionevent) {
|
||||||
|
String filterText = "";
|
||||||
|
if (actionevent instanceof cc.arduino.view.Event) {
|
||||||
|
filterText = ((Event) actionevent).getPayload().get("filterText").toString();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
openInstallBoardDialog();
|
openInstallBoardDialog(filterText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//TODO show error
|
//TODO show error
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
boardMenu.add(new JMenuItem(runInstaller));
|
boardMenu.add(new JMenuItem(openBoardsManager));
|
||||||
boardsCustomMenus.add(boardMenu);
|
boardsCustomMenus.add(boardMenu);
|
||||||
|
|
||||||
// If there are no platforms installed we are done
|
// If there are no platforms installed we are done
|
||||||
@ -2700,7 +2713,15 @@ public class Base {
|
|||||||
return activeEditor;
|
return activeEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasActiveEditor() {
|
||||||
|
return activeEditor != null;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Editor> getEditors() {
|
public List<Editor> getEditors() {
|
||||||
return new LinkedList<Editor>(editors);
|
return new LinkedList<Editor>(editors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action getOpenBoardsManager() {
|
||||||
|
return openBoardsManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class BaseNoGui {
|
|||||||
static File portableFolder = null;
|
static File portableFolder = null;
|
||||||
static final String portableSketchbookFolder = "sketchbook";
|
static final String portableSketchbookFolder = "sketchbook";
|
||||||
|
|
||||||
static ContributionsIndexer indexer;
|
public static ContributionsIndexer indexer;
|
||||||
static LibrariesIndexer librariesIndexer;
|
static LibrariesIndexer librariesIndexer;
|
||||||
|
|
||||||
// Returns a File object for the given pathname. If the pathname
|
// Returns a File object for the given pathname. If the pathname
|
||||||
|
Loading…
x
Reference in New Issue
Block a user