TS plugin

This commit is contained in:
rusefi 2020-06-17 23:50:57 -04:00
parent c27dfae2bb
commit 2b98b3c19e
8 changed files with 62 additions and 20 deletions

View File

@ -14,9 +14,8 @@ import org.apache.http.util.EntityUtils;
import javax.swing.*;
import javax.xml.bind.JAXBException;
import java.io.*;
import static com.rusefi.ui.AuthTokenPanel.TOKEN_WARNING;
import java.io.File;
import java.io.IOException;
public class Online {
private static final String url = "https://rusefi.com/online/upload.php";
@ -43,8 +42,8 @@ public class Online {
public static void uploadTune(Msq tune, AuthTokenPanel authTokenPanel, JComponent parent) {
String authToken = authTokenPanel.getToken();
if (authToken.contains(TOKEN_WARNING)) {
JOptionPane.showMessageDialog(parent, "Does not work without auth token");
if (!authTokenPanel.hasToken()) {
authTokenPanel.showError(parent);
return;
}
new Thread(() -> doUpload(authToken, tune)).start();

View File

@ -11,14 +11,20 @@ import java.awt.event.ActionEvent;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class AuthTokenPanel {
public static final String TOKEN_WARNING = "Please copy token from your forum profile";
private static final String TOKEN_WARNING = "Please copy token from your forum profile";
private static final String TOKEN_SUBSTRING = "token";
private static final String AUTH_TOKEN = "auth_token";
private static final String TOKEN_PROFILE_URL = "https://rusefi.com/forum/ucp.php?i=254";
private JPanel content = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JPanel content = new JPanel(new BorderLayout());
private JTextField textField = new JTextField();
public AuthTokenPanel() {
JPanel top = new JPanel(new FlowLayout(FlowLayout.LEFT));
content.setBorder(BorderFactory.createTitledBorder("rusEFI Online Authentication Token"));
textField.setPreferredSize(new Dimension(200, 24));
String authToken = getAuthToken();
@ -33,12 +39,13 @@ public class AuthTokenPanel {
}
});
content.add(textField);
content.add(save);
top.add(textField);
top.add(save);
content.add(top);
if (authToken.trim().isEmpty()) {
authToken = TOKEN_WARNING;
content.add(new URLLabel("Get it here", TOKEN_PROFILE_URL));
content.add(new URLLabel("Get your token here", TOKEN_PROFILE_URL), BorderLayout.SOUTH);
}
textField.setText(authToken);
}
@ -56,7 +63,15 @@ public class AuthTokenPanel {
return content;
}
public boolean hasToken() {
return textField.getText().trim().length() > 0 && !textField.getText().contains(TOKEN_SUBSTRING);
}
public String getToken() {
return textField.getText();
}
public void showError(JComponent parent) {
JOptionPane.showMessageDialog(parent, "Does not work without auth token, see below.");
}
}

View File

@ -30,6 +30,10 @@
<mkdir dir="${jar_file_folder}"/>
<delete file="${jar_file}"/>
<copy todir="build/classes">
<fileset dir="../ts_plugin_launcher/resources" includes="**/*.png"/>
</copy>
<tstamp>
<format property="TODAY_DATE" pattern="yyyy-MM-dd"/>
</tstamp>

View File

@ -0,0 +1,12 @@
package com.rusefi.ts_plugin;
import com.rusefi.ui.util.FrameHelper;
/**
* @see PluginLauncherSandbox
*/
public class PluginBodySandbox {
public static void main(String[] args) {
new FrameHelper().showFrame(new PluginEntry().getContent());
}
}

View File

@ -10,12 +10,12 @@ import com.rusefi.tune.xml.Constant;
import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.AuthTokenPanel;
import com.rusefi.ui.storage.PersistentConfiguration;
import org.putgemin.VerticalFlowLayout;
import javax.swing.*;
import javax.xml.bind.JAXBException;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import java.util.TreeMap;
@ -28,20 +28,26 @@ import java.util.jar.Manifest;
public class PluginEntry implements TsPluginBody {
public static final String BUILT_DATE = "Built-Date";
private final AuthTokenPanel tokenPanel = new AuthTokenPanel();
private final JComponent content = new JPanel();
private final JComponent content = new JPanel(new VerticalFlowLayout());
public PluginEntry() {
content.add(tokenPanel.getContent());
JButton upload = new JButton("Upload Tune");
JButton upload = new JButton("Upload Current Tune");
upload.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!tokenPanel.hasToken()) {
tokenPanel.showError(content);
return;
}
Msq tune = writeCurrentTune(ControllerAccess.getInstance());
Online.uploadTune(tune, tokenPanel, content);
}
});
content.add(upload);
content.add(new JLabel(Updater.LOGO));
content.add(tokenPanel.getContent());
}
@Override
@ -75,7 +81,12 @@ public class PluginEntry implements TsPluginBody {
}
public static String getConfigurationName() {
return ControllerAccess.getInstance().getEcuConfigurationNames()[0];
ControllerAccess controllerAccess = ControllerAccess.getInstance();
if (controllerAccess == null) {
System.out.println("No ControllerAccess");
return null;
}
return controllerAccess.getEcuConfigurationNames()[0];
}
private static String toString(double scalarValue, int decimalPlaces) {

View File

@ -2,7 +2,7 @@ package com.rusefi.ts_plugin;
import javax.swing.*;
public class Sandbox {
public class PluginLauncherSandbox {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(800, 500);

View File

@ -11,6 +11,7 @@ import javax.swing.*;
*/
public class TsPluginLauncher implements ApplicationPlugin {
static final String VERSION = "alpha2020";
private static final String HELP_URL = "https://github.com/rusefi/rusefi/wiki/TS-Plugin";
private final JPanel content = new JPanel(new VerticalFlowLayout());
@ -70,7 +71,7 @@ public class TsPluginLauncher implements ApplicationPlugin {
@Override
public String getHelpUrl() {
return "https://rusefi.com";
return HELP_URL;
}
@Override

View File

@ -22,13 +22,12 @@ public class Updater {
private static final String TITLE = "rusEFI plugin installer " + VERSION;
private final JPanel content = new JPanel(new VerticalFlowLayout());
public static final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
public Updater() {
content.add(new JLabel("" + VERSION));
ImageIcon logo = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
content.add(new JLabel(logo));
content.add(new JLabel(LOGO));
String version = null;
File localFile = new File(LOCAL_JAR_FILE_NAME);
@ -140,6 +139,7 @@ public class Updater {
content.add(instance.getContent());
AutoupdateUtil.trueLayout(content.getParent());
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(content);
AutoupdateUtil.trueLayout(topFrame);
topFrame.pack();
AutoupdateUtil.trueLayout(topFrame);
}