diff --git a/java_console/io/src/main/java/com/rusefi/tools/VehicleToken.java b/java_console/io/src/main/java/com/rusefi/tools/VehicleToken.java index 3c74ad6c8f..cffaef4a35 100644 --- a/java_console/io/src/main/java/com/rusefi/tools/VehicleToken.java +++ b/java_console/io/src/main/java/com/rusefi/tools/VehicleToken.java @@ -2,6 +2,7 @@ package com.rusefi.tools; import com.rusefi.server.SessionDetails; import com.rusefi.ui.storage.Node; +import org.jetbrains.annotations.NotNull; import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; @@ -11,9 +12,15 @@ public class VehicleToken { public static int getOrCreate() { String value = getConfig().getRoot().getProperty(VEHICLE_TOKEN, null); if (value == null || !Node.isNumeric(value)) { - value = Integer.toString(SessionDetails.createOneTimeCode()); - getConfig().getRoot().setProperty(VEHICLE_TOKEN, value); + value = refresh(); } return Integer.parseInt(value); } + + @NotNull + public static String refresh() { + String value = Integer.toString(SessionDetails.createOneTimeCode()); + getConfig().getRoot().setProperty(VEHICLE_TOKEN, value); + return value; + } } diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/BroadcastTab.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/BroadcastTab.java index bce97a6c7e..7aed73e71c 100644 --- a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/BroadcastTab.java +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/BroadcastTab.java @@ -5,11 +5,16 @@ import com.rusefi.autodetect.PortDetector; import com.rusefi.autoupdate.AutoupdateUtil; import com.rusefi.proxy.NetworkConnector; import com.rusefi.proxy.NetworkConnectorContext; +import com.rusefi.tools.VehicleToken; import com.rusefi.ui.AuthTokenPanel; import com.rusefi.ui.util.URLLabel; +import com.sun.naming.internal.VersionHelper; import org.putgemin.VerticalFlowLayout; import javax.swing.*; +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -20,7 +25,7 @@ public class BroadcastTab { private final JComponent content = new JPanel(new VerticalFlowLayout()); private final JLabel status = new JLabel(); - private final JButton disconnect = new JButton("Disconnect"); + private final JButton disconnect = new JButton("Stop Broadcasting"); private NetworkConnector networkConnector; public BroadcastTab() { @@ -51,6 +56,8 @@ public class BroadcastTab { } }); + content.add(createVehicleTokenPanel()); + content.add(broadcast); content.add(status); content.add(disconnect); @@ -60,6 +67,40 @@ public class BroadcastTab { AutoupdateUtil.trueLayout(content); } + private Component createVehicleTokenPanel() { + JLabel label = new JLabel(); + updateVehicleTokenLabel(label); + + JButton copy = new JButton("Copy to clipboard"); + copy.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + StringSelection stringSelection = new StringSelection("" + VehicleToken.getOrCreate()); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + }); + + JButton reset = new JButton("Reset"); + reset.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + VehicleToken.refresh(); + updateVehicleTokenLabel(label); + } + }); + + JPanel panel = new JPanel(new FlowLayout()); + panel.add(label); + panel.add(copy); + panel.add(reset); + return panel; + } + + private void updateVehicleTokenLabel(JLabel label) { + label.setText("Vehicle access token: " + VehicleToken.getOrCreate()); + } + private void startBroadcasting(String authToken, String autoDetectedPort) { if (autoDetectedPort == null) { status.setText("rusEFI ECU not detected.
Please make sure that TunerStudio is currently not connected to ECU."); diff --git a/java_tools/ts_plugin_launcher/.idea/libraries/mockito_all_1_10_19.xml b/java_tools/ts_plugin_launcher/.idea/libraries/mockito_all_1_10_19.xml new file mode 100644 index 0000000000..ab9528754e --- /dev/null +++ b/java_tools/ts_plugin_launcher/.idea/libraries/mockito_all_1_10_19.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file