Launcher splash screen is freezy fix #2560

This commit is contained in:
rusefillc 2021-04-15 17:03:24 -04:00
parent 2b24045584
commit e5a2b58edf
4 changed files with 37 additions and 30 deletions

View File

@ -28,6 +28,8 @@ All notable user-facing or behavior-altering changes will be documented in this
## Month 202x Release - "Release Name"
### Fixed
- SD card logs bugfix #2556
- Too many small logs are zero size #2553
- Launcher splash screen is freezy #2560
## April 2021 Release "Be Kind to Lawyers Day"
### Added

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20210413;
public static final int CONSOLE_VERSION = 20210415;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -4,7 +4,6 @@ import com.rusefi.io.LinkManager;
import com.rusefi.io.tcp.TcpConnector;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -16,19 +15,17 @@ import java.util.concurrent.CopyOnWriteArrayList;
public enum SerialPortScanner {
INSTANCE;
private volatile boolean isRunning = true;
static final String AUTO_SERIAL = "Auto Serial";
@NotNull
private List<String> knownPorts = new ArrayList<>();
private final List<String> knownPorts = new ArrayList<>();
public List<Listener> listeners = new CopyOnWriteArrayList<>();
private final Timer scanPortsTimer = new Timer(1000, e -> findAllAvailablePorts());
/**
* Find all available serial ports and checks if simulator local TCP port is available
*/
@NotNull
void findAllAvailablePorts() {
List<String> ports = new ArrayList<>();
String[] serialPorts = LinkManager.getCommPorts();
@ -57,11 +54,23 @@ public enum SerialPortScanner {
}
public void startTimer() {
scanPortsTimer.start();
Thread portsScanner = new Thread(() -> {
while (isRunning) {
findAllAvailablePorts();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
}, "Ports Scanner");
portsScanner.setDaemon(true);
portsScanner.start();
}
public void stopTimer() {
scanPortsTimer.stop();
isRunning = false;
}
interface Listener {

View File

@ -25,7 +25,6 @@ import java.util.List;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
import static com.rusefi.ui.util.UiUtils.getAllComponents;
import static com.rusefi.ui.util.UiUtils.setToolTip;
import static java.awt.image.ImageObserver.ABORT;
import static javax.swing.JOptionPane.YES_NO_OPTION;
/**
@ -50,10 +49,10 @@ public class StartupFrame {
@NotNull
private List<String> currentlyDisplayedPorts = new ArrayList<>();
private boolean isFirstTimeApplyingPorts = true;
private JPanel leftPanel = new JPanel(new VerticalFlowLayout());
private final JPanel leftPanel = new JPanel(new VerticalFlowLayout());
private JPanel realHardwarePanel = new JPanel(new MigLayout());
private JPanel miscPanel = new JPanel(new MigLayout()) {
private final JPanel realHardwarePanel = new JPanel(new MigLayout());
private final JPanel miscPanel = new JPanel(new MigLayout()) {
@Override
public Dimension getPreferredSize() {
// want miscPanel and realHardwarePanel to be the same width
@ -66,7 +65,7 @@ public class StartupFrame {
* closing the application.
*/
private boolean isProceeding;
private JLabel noPortsMessage = new JLabel("No ports found!");
private final JLabel noPortsMessage = new JLabel("No ports found!");
public StartupFrame() {
// AudioPlayback.start();
@ -152,28 +151,25 @@ public class StartupFrame {
realHardwarePanel.add(new EraseChip().getButton(), "right, wrap");
}
SerialPortScanner.INSTANCE.listeners.add(new SerialPortScanner.Listener() {
@Override
public void onChange() {
List<String> ports = SerialPortScanner.INSTANCE.getKnownPorts();
if (!currentlyDisplayedPorts.equals(ports) || isFirstTimeApplyingPorts) {
FileLog.MAIN.logLine("Available ports " + ports);
isFirstTimeApplyingPorts = false;
connectPanel.setVisible(!ports.isEmpty());
noPortsMessage.setVisible(ports.isEmpty());
SerialPortScanner.INSTANCE.listeners.add(() -> SwingUtilities.invokeLater(() -> {
List<String> ports = SerialPortScanner.INSTANCE.getKnownPorts();
if (!currentlyDisplayedPorts.equals(ports) || isFirstTimeApplyingPorts) {
FileLog.MAIN.logLine("Available ports " + ports);
isFirstTimeApplyingPorts = false;
connectPanel.setVisible(!ports.isEmpty());
noPortsMessage.setVisible(ports.isEmpty());
// panel.add(comboSpeeds); // todo: finish speed selector UI component
// horizontalLine.setVisible(!ports.isEmpty());
applyPortSelectionToUIcontrol(ports);
currentlyDisplayedPorts = ports;
UiUtils.trueLayout(connectPanel);
frame.pack();
}
applyPortSelectionToUIcontrol(ports);
currentlyDisplayedPorts = ports;
UiUtils.trueLayout(connectPanel);
frame.pack();
}
});
}));
// todo: invoke this NOT on AWT thread?
SerialPortScanner.INSTANCE.findAllAvailablePorts();
final JButton buttonLogViewer = new JButton();