RE TS plugin to have continues tune auto-upload feature #1605
This commit is contained in:
parent
8c77227468
commit
6c7f1baf85
|
@ -28,7 +28,7 @@ public class Online {
|
|||
public static final String outputXmlFileName = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + "output.msq";
|
||||
private static final String url = "https://rusefi.com/online/upload.php";
|
||||
|
||||
public static JSONArray upload(File fileName, String authTokenValue) throws IOException {
|
||||
public static UploadResult upload(File fileName, String authTokenValue) throws IOException {
|
||||
HttpClient httpclient = new DefaultHttpClient();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
|
@ -55,20 +55,19 @@ public class Online {
|
|||
JSONArray error = (JSONArray) object.get("error");
|
||||
if (error != null) {
|
||||
System.out.println("error " + error);
|
||||
return error;
|
||||
return new UploadResult(true, error);
|
||||
} else {
|
||||
System.out.println("info " + info);
|
||||
return info;
|
||||
return new UploadResult(false, info);
|
||||
}
|
||||
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return new UploadResult(true, "Error " + e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BasicFuture<JSONArray> uploadTune(Msq tune, AuthTokenPanel authTokenPanel, JComponent parent, FutureCallback<JSONArray> callback) {
|
||||
BasicFuture<JSONArray> result = new BasicFuture<>(callback);
|
||||
public static BasicFuture<UploadResult> uploadTune(Msq tune, AuthTokenPanel authTokenPanel, JComponent parent, FutureCallback<UploadResult> callback) {
|
||||
BasicFuture<UploadResult> result = new BasicFuture<>(callback);
|
||||
String authToken = authTokenPanel.getToken();
|
||||
if (!authTokenPanel.hasToken()) {
|
||||
authTokenPanel.showError(parent);
|
||||
|
@ -77,20 +76,20 @@ public class Online {
|
|||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JSONArray array = doUpload(authToken, tune);
|
||||
UploadResult array = doUpload(authToken, tune);
|
||||
result.completed(array);
|
||||
}
|
||||
}).start();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static JSONArray doUpload(String authToken, Msq tune) {
|
||||
private static UploadResult doUpload(String authToken, Msq tune) {
|
||||
try {
|
||||
tune.writeXmlFile(outputXmlFileName);
|
||||
// todo: network upload should not happen on UI thread
|
||||
return upload(new File(outputXmlFileName), authToken);
|
||||
} catch (JAXBException | IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
return new UploadResult(true, "IO error " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.rusefi.tools.online;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
|
||||
public class UploadResult {
|
||||
private final boolean isError;
|
||||
private final JSONArray message;
|
||||
|
||||
public UploadResult(boolean isError, JSONArray message) {
|
||||
this.isError = isError;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public UploadResult(boolean isError, String value) {
|
||||
message = new JSONArray();
|
||||
message.add(value);
|
||||
this.isError = isError;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return isError;
|
||||
}
|
||||
|
||||
public JSONArray getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.rusefi.ts_plugin;
|
|||
import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
||||
import com.rusefi.autoupdate.AutoupdateUtil;
|
||||
import com.rusefi.tools.online.Online;
|
||||
import com.rusefi.tools.online.UploadResult;
|
||||
import com.rusefi.ts_plugin.util.ManifestHelper;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
|
@ -10,7 +11,6 @@ import com.rusefi.ui.AuthTokenPanel;
|
|||
import com.rusefi.ui.storage.PersistentConfiguration;
|
||||
import com.rusefi.ui.util.URLLabel;
|
||||
import org.apache.http.concurrent.FutureCallback;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.putgemin.VerticalFlowLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -90,11 +90,13 @@ public class PluginEntry implements TsPluginBody {
|
|||
JOptionPane.showMessageDialog(content, "No project opened");
|
||||
return;
|
||||
}
|
||||
uploadView.uploadState.setVisible(true);
|
||||
uploadView.uploadState.setText("Uploading...");
|
||||
|
||||
Msq tune = TuneUploder.writeCurrentTune(controllerAccessSupplier.get(), configurationName);
|
||||
Online.uploadTune(tune, tokenPanel, content, new FutureCallback<JSONArray>() {
|
||||
Online.uploadTune(tune, tokenPanel, content, new FutureCallback<UploadResult>() {
|
||||
@Override
|
||||
public void completed(JSONArray array) {
|
||||
public void completed(UploadResult array) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import com.rusefi.tools.online.UploadResult;
|
||||
import com.rusefi.ui.storage.PersistentConfiguration;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.putgemin.VerticalFlowLayout;
|
||||
|
@ -13,7 +14,7 @@ public class UploadView {
|
|||
|
||||
private static final String AUTO_UPLOAD = "AUTO_UPLOAD";
|
||||
|
||||
private final JLabel uploadState = new JLabel();
|
||||
public final JLabel uploadState = new JLabel();
|
||||
private final JLabel projectWarning = new JLabel(UploaderStatus.NO_PROJECT);
|
||||
private final JLabel tuneInfo = new JLabel();
|
||||
private final JCheckBox autoUpload = new JCheckBox("Continuous auto-upload");
|
||||
|
@ -37,8 +38,8 @@ public class UploadView {
|
|||
return PersistentConfiguration.getConfig().getRoot().getBoolProperty(AUTO_UPLOAD, false);
|
||||
}
|
||||
|
||||
public void setResult(JSONArray array) {
|
||||
uploadState.setText(array.get(0).toString());
|
||||
public void setResult(UploadResult result) {
|
||||
uploadState.setText(result.getMessage().get(0).toString());
|
||||
uploadState.setVisible(true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue