Another deadlock in console fix #3952

This commit is contained in:
rusefillc 2022-02-21 11:29:33 -05:00
parent dc824f0c42
commit 43e12e0dc7
3 changed files with 19 additions and 15 deletions

View File

@ -22,6 +22,7 @@ public class AutoupdateUtil {
private static final String APPICON = "/appicon.png";
public static JComponent wrap(JComponent component) {
AutoupdateUtil.assertAwtThread();
JPanel result = new JPanel();
result.add(component);
return result;
@ -93,6 +94,7 @@ public class AutoupdateUtil {
}
public static void trueLayout(Component component) {
assertAwtThread();
if (component == null)
return;
component.invalidate();
@ -100,6 +102,11 @@ public class AutoupdateUtil {
component.repaint();
}
public static void assertAwtThread() {
if (!SwingUtilities.isEventDispatchThread())
throw new IllegalStateException("Not on AWT thread but " + Thread.currentThread().getName());
}
public static boolean hasExistingFile(String zipFileName, long completeFileSize, long lastModified) {
File file = new File(zipFileName);
System.out.println("We have " + file.length() + " " + new Date(file.lastModified()) + " " + file.getAbsolutePath());

View File

@ -13,6 +13,7 @@ import com.rusefi.ui.util.FrameHelper;
import com.rusefi.ui.util.UiUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.Objects;
import java.util.TimeZone;
@ -61,20 +62,17 @@ public class MainFrame {
private void windowOpenedHandler() {
setTitle();
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() {
@Override
public void onConnectionStatus(boolean isConnected) {
setTitle();
UiUtils.trueRepaint(tabbedPane.tabbedPane); // this would repaint status label
if (ConnectionStatusLogic.INSTANCE.getValue() == ConnectionStatusValue.CONNECTED) {
long unixGmtTime = System.currentTimeMillis() / 1000L;
long withOffset = unixGmtTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000;
consoleUI.uiContext.getCommandQueue().write(IoUtil.getSetCommand(Fields.CMD_DATE) +
" " + withOffset, CommandQueue.DEFAULT_TIMEOUT,
InvocationConfirmationListener.VOID, false);
}
ConnectionStatusLogic.INSTANCE.addListener(isConnected -> SwingUtilities.invokeLater(() -> {
setTitle();
UiUtils.trueRepaint(tabbedPane.tabbedPane); // this would repaint status label
if (ConnectionStatusLogic.INSTANCE.getValue() == ConnectionStatusValue.CONNECTED) {
long unixGmtTime = System.currentTimeMillis() / 1000L;
long withOffset = unixGmtTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000;
consoleUI.uiContext.getCommandQueue().write(IoUtil.getSetCommand(Fields.CMD_DATE) +
" " + withOffset, CommandQueue.DEFAULT_TIMEOUT,
InvocationConfirmationListener.VOID, false);
}
});
}));
final LinkManager linkManager = consoleUI.uiContext.getLinkManager();
linkManager.getConnector().connectAndReadConfiguration(new BinaryProtocol.Arguments(true), new ConnectionStateListener() {

View File

@ -1,6 +1,5 @@
package com.rusefi.ui.util;
import com.rusefi.StartupFrame;
import com.rusefi.autoupdate.AutoupdateUtil;
import org.jetbrains.annotations.NotNull;
@ -17,7 +16,6 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
import static com.rusefi.ui.util.LocalizedMessages.CLEAR;
@ -59,6 +57,7 @@ public class UiUtils {
}
private static BufferedImage getScreenShot(Component component) {
AutoupdateUtil.assertAwtThread();
// http://stackoverflow.com/questions/5853879/swing-obtain-image-of-jframe/5853992
BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
// call the Component's paint method, using