rusefi/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java

112 lines
3.7 KiB
Java
Raw Normal View History

2020-06-16 20:52:07 -07:00
package com.rusefi.ts_plugin;
2020-06-16 20:24:19 -07:00
import com.efiAnalytics.plugin.ecu.ControllerAccess;
import com.rusefi.core.ui.AutoupdateUtil;
2020-08-29 21:21:34 -07:00
import com.rusefi.ts_plugin.auth.InstanceAuthContext;
import com.rusefi.ts_plugin.util.ManifestHelper;
2020-06-16 20:24:19 -07:00
import com.rusefi.tune.xml.Constant;
import javax.swing.*;
2020-07-24 11:41:50 -07:00
import java.awt.*;
import java.lang.reflect.Field;
2020-06-22 16:52:40 -07:00
import java.util.function.Supplier;
2020-06-16 20:24:19 -07:00
2020-06-16 21:35:16 -07:00
/**
2020-07-25 16:17:28 -07:00
* {@link TsPluginLauncher} creates an instance of this class via reflection.
2020-08-29 21:21:34 -07:00
*
2020-08-12 17:37:37 -07:00
* @see TuneUploadTab upload tune & TODO upload logs
2020-07-26 21:48:04 -07:00
* @see RemoteTab remote ECU access & control
* @see BroadcastTab offer your ECU for remove access & control
* @see PluginBodySandbox
2020-06-16 21:35:16 -07:00
*/
2020-06-16 20:52:07 -07:00
public class PluginEntry implements TsPluginBody {
2020-07-24 11:41:50 -07:00
private final JPanel content = new JPanel(new BorderLayout());
2020-06-22 16:52:40 -07:00
2020-07-26 21:48:04 -07:00
static final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
2020-09-30 20:40:22 -07:00
private final JTabbedPane tabbedPane = new JTabbedPane();
2020-07-26 21:48:04 -07:00
2020-06-22 16:52:40 -07:00
/**
* the real constructor - this one is invoked via reflection
*/
2020-07-25 16:17:28 -07:00
@SuppressWarnings("unused")
2020-06-16 20:52:07 -07:00
public PluginEntry() {
2020-06-22 16:52:40 -07:00
this(ControllerAccess::getInstance);
}
public PluginEntry(Supplier<ControllerAccess> controllerAccessSupplier) {
2020-07-14 19:59:06 -07:00
System.out.println("PluginEntry init " + this);
2020-06-22 21:24:32 -07:00
2020-07-24 11:41:50 -07:00
if (isLauncherTooOld()) {
2020-08-10 19:12:38 -07:00
content.add(new JLabel("<html>Please manually install latest plugin version<br/>Usually we can update to latest version but this time there was a major change.<br/>" +
"Please use TunerStudio controls to update to plugin from recent rusEFI bundle."));
2020-07-24 11:41:50 -07:00
return;
}
2020-08-12 17:37:37 -07:00
TuneUploadTab tuneUploadTab = new TuneUploadTab(controllerAccessSupplier);
LogUploadSelector logUploadTab = new LogUploadSelector(controllerAccessSupplier);
2020-07-18 20:17:36 -07:00
BroadcastTab broadcastTab = new BroadcastTab();
RemoteTab remoteTab = new RemoteTab();
2020-06-17 20:50:57 -07:00
2020-08-12 17:37:37 -07:00
tabbedPane.addTab("Tune Upload", tuneUploadTab.getContent());
tabbedPane.addTab("Log Upload", logUploadTab.getContent());
2020-07-18 20:17:36 -07:00
tabbedPane.addTab("Broadcast", broadcastTab.getContent());
tabbedPane.addTab("Remote ECU", remoteTab.getContent());
2020-09-30 20:40:22 -07:00
this.content.add(tabbedPane);
2020-08-29 21:21:34 -07:00
InstanceAuthContext.startup();
}
public static String getNonDaemonThreads() {
StringBuilder sb = new StringBuilder();
for (Thread thread : Thread.getAllStackTraces().keySet()) {
// Daemon thread will not prevent the JVM from exiting
if (!thread.isDaemon())
sb.append(thread.getName() + "\n");
}
return sb.toString();
2020-07-24 11:41:50 -07:00
}
private boolean isLauncherTooOld() {
try {
// at some point we did not have this field so using reflection for the next couple of months
Field field = TsPluginLauncher.class.getField("BUILD_VERSION");
int launcherVersion = (int) field.get(null);
System.out.println("Launcher version " + launcherVersion + " detected");
return false;
} catch (NoSuchFieldException | IllegalAccessException e) {
return true;
}
2020-07-14 19:59:06 -07:00
}
public static boolean isEmpty(Constant constant) {
2020-06-22 17:58:52 -07:00
if (constant == null)
return true;
return isEmpty(constant.getValue());
}
private static boolean isEmpty(String value) {
2020-06-22 17:58:52 -07:00
return value == null || value.trim().length() == 0;
2020-06-22 16:52:40 -07:00
}
2020-06-16 21:35:16 -07:00
@Override
public JComponent getContent() {
2020-07-24 11:41:50 -07:00
return content;
2020-06-16 20:24:19 -07:00
}
/*
2020-06-16 20:24:19 -07:00
public void close() {
PersistentConfiguration.getConfig().save();
}
*/
2020-06-16 20:24:19 -07:00
2020-06-16 22:14:45 -07:00
/**
* this method is invoked by refection
*
* @see TsPluginBody#GET_VERSION
*/
@SuppressWarnings("unused")
public static String getVersion() {
return ManifestHelper.getVersion();
2020-06-16 22:14:45 -07:00
}
2020-06-16 20:24:19 -07:00
}