now basic updater shows current branch name

closes #7000
This commit is contained in:
kifir 2024-10-29 00:08:17 +02:00 committed by rusefillc
parent 973cb50f5c
commit 407ed51fdd
2 changed files with 46 additions and 7 deletions

View File

@ -1,18 +1,40 @@
package com.rusefi.core.io;
import com.devexperts.logging.Logging;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.InvalidPathException;
import java.util.Date;
import static com.devexperts.logging.Logging.getLogging;
public class BundleUtil {
private static final Logging log = getLogging(BundleUtil.class);
private static final char BUNDLE_TOKEN_SEPARATOR = '.';
private static final String SNAPSHOT = "snapshot";
/**
* @return null in case of error
*/
@Nullable
public static String readBranchNameToDisplay() {
final String bundleFullName = readBundleFullName();
if (bundleFullName != null) {
try {
final BundleInfo bundleInfo = parse(bundleFullName);
// TODO: get rid of the pornography below:
// we should use `development` instead of `snapshot` for master branch in bundle name.
return (bundleInfo.isMaster() ? "development" : bundleInfo.getBranchName());
} catch (final Throwable e) {
log.warn(String.format("We failed to parse bundle full name `%s`", bundleFullName), e);
}
}
return null;
}
/**
* @return null in case of error
@ -68,6 +90,10 @@ public class BundleUtil {
return branchName;
}
public boolean isMaster() {
return SNAPSHOT.equals(branchName);
}
public String getTarget() {
return target;
}

View File

@ -43,6 +43,7 @@ import static javax.swing.JOptionPane.YES_NO_OPTION;
*/
public class StartupFrame {
private static final Logging log = getLogging(Launcher.class);
public static final String ALWAYS_AUTO_PORT = "always_auto_port";
private static final String NO_PORTS_FOUND = "<html>No ports found!<br>Confirm blue LED is blinking</html>";
public static final String SCANNING_PORTS = "Scanning ports";
@ -237,20 +238,32 @@ public class StartupFrame {
}
public static @NotNull JLabel binaryModificationControl() {
long binaryModificationTimestamp = MaintenanceUtil.getBinaryModificationTimestamp();
final long binaryModificationTimestamp = MaintenanceUtil.getBinaryModificationTimestamp();
JLabel jLabel;
if (binaryModificationTimestamp == 0) {
jLabel = new JLabel("firmware file not found");
jLabel.setForeground(Color.red);
} else {
String fileTimestampText = "Files " + new Date(binaryModificationTimestamp);
jLabel = new JLabel(fileTimestampText);
final Date binaryModificationDate = new Date(binaryModificationTimestamp);
final String branchNameToDisplay = BundleUtil.readBranchNameToDisplay();
jLabel = new JLabel(String.format(
"<html><center>%s files<br/>%s</center></html>",
branchNameToDisplay,
binaryModificationDate
));
jLabel.setToolTipText("Click to copy");
jLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(new StringSelection(fileTimestampText), null);
.setContents(
new StringSelection(String.format(
"%s files\r%s",
branchNameToDisplay,
binaryModificationDate
)),
null
);
}
});
}