only:refactoring: now `onUpdateFirmwareButtonClicked` method handles click on update firmware button click for the both cases - with obfuscation and without obfuscation #6864

This commit is contained in:
kifir 2024-09-16 17:23:35 +03:00 committed by Andrey
parent 58e69cdcc3
commit 62acc8459a
1 changed files with 24 additions and 22 deletions

View File

@ -42,6 +42,7 @@ public class BasicStartupFrame {
private final FrameHelper frame = FrameHelper.createFrame( private final FrameHelper frame = FrameHelper.createFrame(
whiteLabel + " basic console " + Launcher.CONSOLE_VERSION whiteLabel + " basic console " + Launcher.CONSOLE_VERSION
); );
private final boolean isObfusacted = FindFileHelper.isObfuscated();
private final JLabel statusMessage = new JLabel(); private final JLabel statusMessage = new JLabel();
private final StatusAnimation status = new StatusAnimation(this::updateStatus, StartupFrame.SCANNING_PORTS); private final StatusAnimation status = new StatusAnimation(this::updateStatus, StartupFrame.SCANNING_PORTS);
@ -64,9 +65,8 @@ public class BasicStartupFrame {
panel.add(ToolButtons.createShowDeviceManagerButton()); panel.add(ToolButtons.createShowDeviceManagerButton());
panel.add(StartupFrame.binaryModificationControl()); panel.add(StartupFrame.binaryModificationControl());
boolean requireBlt = FindFileHelper.isObfuscated(); updateFirmwareButton.addActionListener(e-> onUpdateFirmwareButtonClicked());
if (requireBlt) { if (isObfusacted) {
updateFirmwareButton.addActionListener(e-> onUpdateFirmwareButtonClicked());
updateFirmwareButton.setEnabled(false); updateFirmwareButton.setEnabled(false);
statusMessage.setForeground(Color.red); statusMessage.setForeground(Color.red);
@ -75,8 +75,6 @@ public class BasicStartupFrame {
SerialPortScanner.INSTANCE.addListener(currentHardware -> SwingUtilities.invokeLater(() -> { SerialPortScanner.INSTANCE.addListener(currentHardware -> SwingUtilities.invokeLater(() -> {
onHardwareUpdated(currentHardware); onHardwareUpdated(currentHardware);
})); }));
} else {
updateFirmwareButton.addActionListener(e -> DfuFlasher.doAutoDfu(updateFirmwareButton, PortDetector.AUTO, new UpdateStatusWindow("Update")));
} }
panel.add(updateFirmwareButton); panel.add(updateFirmwareButton);
} else { } else {
@ -164,25 +162,29 @@ public class BasicStartupFrame {
} }
private void onUpdateFirmwareButtonClicked() { private void onUpdateFirmwareButtonClicked() {
portToUpdateFirmware.ifPresentOrElse(port -> { if (isObfusacted) {
switch (port.type) { portToUpdateFirmware.ifPresentOrElse(port -> {
case EcuWithOpenblt: { switch (port.type) {
ProgramSelector.executeJob(updateFirmwareButton, ProgramSelector.OPENBLT_AUTO, port); case EcuWithOpenblt: {
break; ProgramSelector.executeJob(updateFirmwareButton, ProgramSelector.OPENBLT_AUTO, port);
} break;
case OpenBlt: { }
ProgramSelector.executeJob(updateFirmwareButton, ProgramSelector.OPENBLT_MANUAL, port); case OpenBlt: {
break; ProgramSelector.executeJob(updateFirmwareButton, ProgramSelector.OPENBLT_MANUAL, port);
} break;
default: { }
log.error(String.format("Unexpected port type: %s (%s)", port.type, port)); default: {
break; log.error(String.format("Unexpected port type: %s (%s)", port.type, port));
break;
}
} }
}, () -> {
log.error("Port to update firmware is not defined.");
} }
}, ()-> { );
log.error("Port to update firmware is not defined."); } else {
} DfuFlasher.doAutoDfu(updateFirmwareButton, PortDetector.AUTO, new UpdateStatusWindow("Update"));
); }
} }
private void runTool() { private void runTool() {