refactoring

This commit is contained in:
rusefi 2020-06-05 01:19:02 -04:00
parent 73e206fde3
commit 828bde9797
3 changed files with 16 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class AuthTokenPanel {
public static final String TOKEN_WARNING = "Please copy token from your forum profile";
public static final String AUTH_TOKEN = "auth_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));
@ -22,12 +22,13 @@ public class AuthTokenPanel {
textField.setPreferredSize(new Dimension(200, 24));
String authToken = getAuthToken();
System.out.println("Got from settings: " + authToken);
JButton save = new JButton("Save");
save.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
getConfig().getRoot().setProperty(AUTH_TOKEN, textField.getText());
setAuthToken(AuthTokenPanel.this.textField.getText());
PersistentConfiguration.getConfig().save();
}
});
@ -42,6 +43,10 @@ public class AuthTokenPanel {
textField.setText(authToken);
}
public static void setAuthToken(String value) {
getConfig().getRoot().setProperty(AUTH_TOKEN, value);
}
@NotNull
public static String getAuthToken() {
return getConfig().getRoot().getProperty(AUTH_TOKEN);

View File

@ -12,7 +12,10 @@ import com.rusefi.binaryprotocol.IncomingDataBuffer;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.EngineState;
import com.rusefi.core.ResponseBuffer;
import com.rusefi.io.*;
import com.rusefi.io.ConnectionStateListener;
import com.rusefi.io.ConnectionStatusLogic;
import com.rusefi.io.IoStream;
import com.rusefi.io.LinkManager;
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
import com.rusefi.maintenance.ExecHelper;
import com.rusefi.tools.online.Online;
@ -30,7 +33,6 @@ import java.util.Map;
import java.util.TreeMap;
import static com.rusefi.binaryprotocol.BinaryProtocol.sleep;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
public class ConsoleTools {
public static final String SET_AUTH_TOKEN = "set_auth_token";
@ -62,7 +64,7 @@ public class ConsoleTools {
private static void uploadTune(String[] args) throws IOException {
String fileName = args[1];
String authToken = getConfig().getRoot().getProperty(AuthTokenPanel.AUTH_TOKEN);
String authToken = AuthTokenPanel.getAuthToken();
System.out.println("Trying to upload " + fileName + " using " + authToken);
Online.upload(new File(fileName), authToken);
}
@ -109,11 +111,11 @@ public class ConsoleTools {
private static void setAuthToken(String[] args) {
String newToken = args[1];
System.out.println("Saving auth token " + newToken);
getConfig().getRoot().setProperty(AuthTokenPanel.AUTH_TOKEN, newToken);
AuthTokenPanel.setAuthToken(newToken);
}
private static void printAuthToken() {
String authToken = getConfig().getRoot().getProperty(AuthTokenPanel.AUTH_TOKEN);
String authToken = AuthTokenPanel.getAuthToken();
if (authToken.trim().isEmpty()) {
System.out.println("Auth token not defined. Please use " + SET_AUTH_TOKEN + " command");
System.out.println("\tPlease see https://github.com/rusefi/rusefi/wiki/Online");
@ -226,7 +228,7 @@ public class ConsoleTools {
Msq tune = Msq.toMsq(image);
tune.writeXmlFile(Msq.outputXmlFileName);
String authToken = getConfig().getRoot().getProperty(AuthTokenPanel.AUTH_TOKEN);
String authToken = AuthTokenPanel.getAuthToken();
System.out.println("Using " + authToken);
Online.upload(new File(Msq.outputXmlFileName), authToken);
}

View File

@ -9,6 +9,7 @@ import com.rusefi.tools.online.Online;
import com.rusefi.tune.xml.Constant;
import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.AuthTokenPanel;
import com.rusefi.ui.storage.Node;
import com.rusefi.ui.storage.PersistentConfiguration;
import com.rusefi.ui.util.Misc;
import org.putgemin.VerticalFlowLayout;