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"; private static final String APPICON = "/appicon.png";
public static JComponent wrap(JComponent component) { public static JComponent wrap(JComponent component) {
AutoupdateUtil.assertAwtThread();
JPanel result = new JPanel(); JPanel result = new JPanel();
result.add(component); result.add(component);
return result; return result;
@ -93,6 +94,7 @@ public class AutoupdateUtil {
} }
public static void trueLayout(Component component) { public static void trueLayout(Component component) {
assertAwtThread();
if (component == null) if (component == null)
return; return;
component.invalidate(); component.invalidate();
@ -100,6 +102,11 @@ public class AutoupdateUtil {
component.repaint(); 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) { public static boolean hasExistingFile(String zipFileName, long completeFileSize, long lastModified) {
File file = new File(zipFileName); File file = new File(zipFileName);
System.out.println("We have " + file.length() + " " + new Date(file.lastModified()) + " " + file.getAbsolutePath()); 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 com.rusefi.ui.util.UiUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.Objects; import java.util.Objects;
import java.util.TimeZone; import java.util.TimeZone;
@ -61,20 +62,17 @@ public class MainFrame {
private void windowOpenedHandler() { private void windowOpenedHandler() {
setTitle(); setTitle();
ConnectionStatusLogic.INSTANCE.addListener(new ConnectionStatusLogic.Listener() { ConnectionStatusLogic.INSTANCE.addListener(isConnected -> SwingUtilities.invokeLater(() -> {
@Override setTitle();
public void onConnectionStatus(boolean isConnected) { UiUtils.trueRepaint(tabbedPane.tabbedPane); // this would repaint status label
setTitle(); if (ConnectionStatusLogic.INSTANCE.getValue() == ConnectionStatusValue.CONNECTED) {
UiUtils.trueRepaint(tabbedPane.tabbedPane); // this would repaint status label long unixGmtTime = System.currentTimeMillis() / 1000L;
if (ConnectionStatusLogic.INSTANCE.getValue() == ConnectionStatusValue.CONNECTED) { long withOffset = unixGmtTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000;
long unixGmtTime = System.currentTimeMillis() / 1000L; consoleUI.uiContext.getCommandQueue().write(IoUtil.getSetCommand(Fields.CMD_DATE) +
long withOffset = unixGmtTime + TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000; " " + withOffset, CommandQueue.DEFAULT_TIMEOUT,
consoleUI.uiContext.getCommandQueue().write(IoUtil.getSetCommand(Fields.CMD_DATE) + InvocationConfirmationListener.VOID, false);
" " + withOffset, CommandQueue.DEFAULT_TIMEOUT,
InvocationConfirmationListener.VOID, false);
}
} }
}); }));
final LinkManager linkManager = consoleUI.uiContext.getLinkManager(); final LinkManager linkManager = consoleUI.uiContext.getLinkManager();
linkManager.getConnector().connectAndReadConfiguration(new BinaryProtocol.Arguments(true), new ConnectionStateListener() { linkManager.getConnector().connectAndReadConfiguration(new BinaryProtocol.Arguments(true), new ConnectionStateListener() {

View File

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