parent
fc8a468c92
commit
5c7f6c21b1
|
@ -1,11 +1,14 @@
|
||||||
package com.rusefi.ts_plugin;
|
package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
import com.efiAnalytics.plugin.ApplicationPlugin;
|
import com.efiAnalytics.plugin.ApplicationPlugin;
|
||||||
import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
import com.efiAnalytics.plugin.ecu.ControllerAccess;
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is the more permanent part of the plugin, it's responsible for refreshing and launcher PluginEntry via reflections.
|
* This class is the more permanent part of the plugin, it's responsible for refreshing and launcher PluginEntry via reflections.
|
||||||
* which downloads the main more volatile UI part (PluginEntry)
|
* which downloads the main more volatile UI part (PluginEntry)
|
||||||
|
@ -16,14 +19,15 @@ import javax.swing.*;
|
||||||
* @see Updater
|
* @see Updater
|
||||||
*/
|
*/
|
||||||
public class TsPluginLauncher implements ApplicationPlugin {
|
public class TsPluginLauncher implements ApplicationPlugin {
|
||||||
public static final int BUILD_VERSION = 4;
|
public static final int BUILD_VERSION = 5;
|
||||||
static final String VERSION = "2022.alpha." + BUILD_VERSION;
|
static final String VERSION = "2024.alpha." + BUILD_VERSION;
|
||||||
|
private static final Logging log = getLogging(TsPluginLauncher.class);
|
||||||
private static final String HELP_URL = "https://github.com/rusefi/rusefi/wiki/TS-Plugin";
|
private static final String HELP_URL = "https://github.com/rusefi/rusefi/wiki/TS-Plugin";
|
||||||
|
|
||||||
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||||
|
|
||||||
public TsPluginLauncher() {
|
public TsPluginLauncher() {
|
||||||
System.out.println("init " + this);
|
log.info("init " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +56,7 @@ public class TsPluginLauncher implements ApplicationPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean displayPlugin(String signature) {
|
public boolean displayPlugin(String signature) {
|
||||||
System.out.println("displayPlugin " + signature);
|
log.info("displayPlugin " + signature);
|
||||||
// todo: smarter implementation one day
|
// todo: smarter implementation one day
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +77,7 @@ public class TsPluginLauncher implements ApplicationPlugin {
|
||||||
// lazy initialization since TunerStudio creates one instance only to get version information without any
|
// lazy initialization since TunerStudio creates one instance only to get version information without any
|
||||||
// intentions to display the UI
|
// intentions to display the UI
|
||||||
if (content.getComponents().length == 0) {
|
if (content.getComponents().length == 0) {
|
||||||
System.out.println("Create Updater " + this);
|
log.info("Create Updater " + this);
|
||||||
Updater updater = new Updater();
|
Updater updater = new Updater();
|
||||||
content.add(updater.getContent());
|
content.add(updater.getContent());
|
||||||
}
|
}
|
||||||
|
@ -83,7 +87,7 @@ public class TsPluginLauncher implements ApplicationPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
System.out.println("TsPluginLauncher.close " + this);
|
log.info("TsPluginLauncher.close " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.ts_plugin;
|
package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
import com.rusefi.core.ui.AutoupdateUtil;
|
import com.rusefi.core.ui.AutoupdateUtil;
|
||||||
import com.rusefi.core.net.ConnectionAndMeta;
|
import com.rusefi.core.net.ConnectionAndMeta;
|
||||||
import com.rusefi.core.FileUtil;
|
import com.rusefi.core.FileUtil;
|
||||||
|
@ -18,6 +19,7 @@ import java.net.URLClassLoader;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
import static com.rusefi.ts_plugin.TsPluginLauncher.VERSION;
|
import static com.rusefi.ts_plugin.TsPluginLauncher.VERSION;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +27,7 @@ import static com.rusefi.ts_plugin.TsPluginLauncher.VERSION;
|
||||||
* @see ConnectionAndMeta#getBaseUrl
|
* @see ConnectionAndMeta#getBaseUrl
|
||||||
*/
|
*/
|
||||||
public class Updater {
|
public class Updater {
|
||||||
|
private static final Logging log = getLogging(Updater.class);
|
||||||
private static final String PLUGIN_ENTRY_CLASS = "com.rusefi.ts_plugin.PluginEntry";
|
private static final String PLUGIN_ENTRY_CLASS = "com.rusefi.ts_plugin.PluginEntry";
|
||||||
private static final String PLUGIN_BODY_JAR = "rusefi_plugin_body.jar";
|
private static final String PLUGIN_BODY_JAR = "rusefi_plugin_body.jar";
|
||||||
private static final String LOCAL_JAR_FILE_NAME = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + PLUGIN_BODY_JAR;
|
private static final String LOCAL_JAR_FILE_NAME = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + PLUGIN_BODY_JAR;
|
||||||
|
@ -33,6 +36,7 @@ public class Updater {
|
||||||
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
private final JPanel content = new JPanel(new VerticalFlowLayout());
|
||||||
private static final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
|
private static final ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png");
|
||||||
private final JLabel countDownLabel = new JLabel();
|
private final JLabel countDownLabel = new JLabel();
|
||||||
|
private final Object lock = new Object();
|
||||||
private final AtomicInteger autoStartCounter = new AtomicInteger(4);
|
private final AtomicInteger autoStartCounter = new AtomicInteger(4);
|
||||||
private TsPluginBody instance;
|
private TsPluginBody instance;
|
||||||
private final Timer timer = new Timer(1000, new ActionListener() {
|
private final Timer timer = new Timer(1000, new ActionListener() {
|
||||||
|
@ -43,10 +47,11 @@ public class Updater {
|
||||||
try {
|
try {
|
||||||
if (shouldAutoStart) {
|
if (shouldAutoStart) {
|
||||||
shouldAutoStart = false;
|
shouldAutoStart = false;
|
||||||
System.out.println("Auto-starting startPlugin");
|
log.info("Auto-starting startPlugin");
|
||||||
startPlugin();
|
startPlugin();
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException | MalformedURLException | ClassNotFoundException | InstantiationException ex) {
|
} catch (IllegalAccessException | MalformedURLException | ClassNotFoundException |
|
||||||
|
InstantiationException | InterruptedException | InvocationTargetException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
JOptionPane.showMessageDialog(content, "Error " + ex);
|
JOptionPane.showMessageDialog(content, "Error " + ex);
|
||||||
}
|
}
|
||||||
|
@ -82,10 +87,10 @@ public class Updater {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
|
log.info("Server has " + connectionAndMeta.getCompleteFileSize() + " from " + new Date(connectionAndMeta.getLastModified()));
|
||||||
|
|
||||||
if (AutoupdateUtil.hasExistingFile(LOCAL_JAR_FILE_NAME, connectionAndMeta.getCompleteFileSize(), connectionAndMeta.getLastModified())) {
|
if (AutoupdateUtil.hasExistingFile(LOCAL_JAR_FILE_NAME, connectionAndMeta.getCompleteFileSize(), connectionAndMeta.getLastModified())) {
|
||||||
System.out.println("We already have latest update " + new Date(connectionAndMeta.getLastModified()));
|
log.info("We already have latest update " + new Date(connectionAndMeta.getLastModified()));
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
download.setText("We have latest plugin version");
|
download.setText("We have latest plugin version");
|
||||||
download.setEnabled(false);
|
download.setEnabled(false);
|
||||||
|
@ -120,9 +125,10 @@ public class Updater {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
try {
|
||||||
cancelAutoStart();
|
cancelAutoStart();
|
||||||
System.out.println("run startPlugin");
|
log.info("run startPlugin");
|
||||||
startPlugin();
|
startPlugin();
|
||||||
} catch (IllegalAccessException | MalformedURLException | ClassNotFoundException | InstantiationException ex) {
|
} catch (IllegalAccessException | MalformedURLException | ClassNotFoundException |
|
||||||
|
InstantiationException | InterruptedException | InvocationTargetException ex) {
|
||||||
run.setText(e.toString());
|
run.setText(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +156,7 @@ public class Updater {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDownload(JButton download) {
|
private void startDownload(JButton download) {
|
||||||
System.out.println("startDownload");
|
log.info("startDownload");
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -163,7 +169,7 @@ public class Updater {
|
||||||
|
|
||||||
AutoupdateUtil.downloadAutoupdateFile(LOCAL_JAR_FILE_NAME, connectionAndMeta,
|
AutoupdateUtil.downloadAutoupdateFile(LOCAL_JAR_FILE_NAME, connectionAndMeta,
|
||||||
TITLE);
|
TITLE);
|
||||||
System.out.println("Downloaded, now startPlugin");
|
log.info("Downloaded, now startPlugin");
|
||||||
startPlugin();
|
startPlugin();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -172,22 +178,25 @@ public class Updater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startPlugin() throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
private void startPlugin() throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, InterruptedException, InvocationTargetException {
|
||||||
System.out.println("Starting plugin " + this);
|
log.info("Starting plugin " + this);
|
||||||
Class clazz = getPluginClass();
|
Class clazz = getPluginClass();
|
||||||
synchronized (this) {
|
synchronized (lock) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
System.out.println("Not starting second instance");
|
log.info("Not starting second instance");
|
||||||
return; // avoid having two instances running
|
return; // avoid having two instances running
|
||||||
}
|
}
|
||||||
instance = (TsPluginBody) clazz.newInstance();
|
SwingUtilities.invokeAndWait(() -> {
|
||||||
|
try {
|
||||||
|
instance = (TsPluginBody) clazz.newInstance();
|
||||||
|
replaceWith(instance);
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
replaceWith(instance);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class getPluginClass() throws MalformedURLException, ClassNotFoundException {
|
private static Class getPluginClass() throws MalformedURLException, ClassNotFoundException {
|
||||||
|
|
Loading…
Reference in New Issue