From 8aa5126a59015174c2799f5c977be77bd9581dda Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 22 Jun 2020 01:08:53 -0400 Subject: [PATCH] REO progress --- java_tools/ts_plugin/build.xml | 2 + .../src/com/rusefi/ts_plugin/PluginEntry.java | 50 ++++++++++++++++--- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/java_tools/ts_plugin/build.xml b/java_tools/ts_plugin/build.xml index b729364348..0cc26e482b 100644 --- a/java_tools/ts_plugin/build.xml +++ b/java_tools/ts_plugin/build.xml @@ -35,12 +35,14 @@ + + diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java index 4e1b711536..48466e7d4d 100644 --- a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java +++ b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java @@ -12,6 +12,7 @@ import com.rusefi.tune.xml.Msq; import com.rusefi.ui.AuthTokenPanel; import com.rusefi.ui.storage.PersistentConfiguration; import com.rusefi.ui.util.URLLabel; +import org.jetbrains.annotations.NotNull; import org.putgemin.VerticalFlowLayout; import javax.swing.*; @@ -28,15 +29,40 @@ import java.util.jar.Manifest; * TsPlugin launcher creates an instance of this class via reflection. */ public class PluginEntry implements TsPluginBody { - public static final String BUILT_DATE = "Built-Date"; + private static final String BUILT_DATE = "Built-Date"; + private static final String BUILT_TIMESTAMP = "Built-Timestamp"; public static final String REO = "https://rusefi.com/online/"; private final AuthTokenPanel tokenPanel = new AuthTokenPanel(); private final JComponent content = new JPanel(new VerticalFlowLayout()); private static final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png"); + private final JButton upload = new JButton("Upload Current Tune"); + private static final JLabel warning = new JLabel("Please open project"); + public PluginEntry() { - JButton upload = new JButton("Upload Current Tune"); + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + boolean isProjectActive = getConfigurationName() != null; + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + warning.setVisible(!isProjectActive); + upload.setEnabled(isProjectActive); + } + }); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }).start(); + upload.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { @@ -55,6 +81,10 @@ public class PluginEntry implements TsPluginBody { } }); + content.add(new JLabel(getAttribute(BUILT_TIMESTAMP))); +// content.add(new JLabel("Active project: " + getConfigurationName())); + + content.add(warning); content.add(upload); content.add(new JLabel(LOGO)); content.add(tokenPanel.getContent()); @@ -97,7 +127,10 @@ public class PluginEntry implements TsPluginBody { System.out.println("No ControllerAccess"); return null; } - return controllerAccess.getEcuConfigurationNames()[0]; + String[] configurationNames = controllerAccess.getEcuConfigurationNames(); + if (configurationNames.length == 0) + return null; + return configurationNames[0]; } private static String toString(double scalarValue, int decimalPlaces) { @@ -166,6 +199,11 @@ public class PluginEntry implements TsPluginBody { */ @SuppressWarnings("unused") public static String getVersion() { + return getAttribute(BUILT_DATE); + } + + @NotNull + private static String getAttribute(String attributeName) { // all this magic below to make sure we are reading manifest of the *our* jar file not TS main jar file Class clazz = PluginEntry.class; String className = clazz.getSimpleName() + ".class"; @@ -179,12 +217,8 @@ public class PluginEntry implements TsPluginBody { try { Manifest manifest = new Manifest(new URL(manifestPath).openStream()); Attributes attributes = manifest.getMainAttributes(); - System.out.println("Attributed " + attributes); - System.out.println("Attributed " + attributes.keySet()); - System.out.println("Attributed " + attributes.getValue("Class-Path")); - System.out.println("Attributed " + attributes.getValue("Main-Class")); - String result = attributes.getValue(BUILT_DATE); + String result = attributes.getValue(attributeName); System.out.println(BUILT_DATE + " " + result); return result == null ? "Unknown version" : result; } catch (IOException e) {