Skip to content

Commit

Permalink
🚧 #85
Browse files Browse the repository at this point in the history
  • Loading branch information
rucko24 committed Dec 3, 2024
1 parent e3ce74f commit 3b3dba7
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 123 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.esp.espflow.service.EsptoolPathService;
import com.esp.espflow.service.hashservice.ComputeSha256Service;
import com.esp.espflow.service.respository.impl.EsptoolExecutableServiceImpl;
import com.esp.espflow.util.MakeExecutable;
import com.esp.espflow.util.IMakeExecutable;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -47,7 +47,7 @@
*/
@Log4j2
@Configuration
public class LoadEsptoolBundleConfiguration implements MakeExecutable {
public class LoadEsptoolBundleConfiguration implements IMakeExecutable {

/**
* Move the esptool executable to the system's temporary directory in runtime
Expand Down Expand Up @@ -103,7 +103,7 @@ private String moveBundleToTempDirectory(final String bundleFileName) {
if (GetOsName.getOsName() == GetOsName.LINUX) {
final var pathResourceAsStream = META_INF_RESOURCES_ESPTOOL_BUNDLE + bundleFileName;
this.processResourceAsStream(pathResourceAsStream, outPathFileName);
this.makeExecutable(outPathFileName);
this.makeExecutable(outPathFileName.toString());
}

return outPathFileName.toString();
Expand Down
21 changes: 2 additions & 19 deletions src/main/java/com/esp/espflow/service/EsptoolPathService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.esp.espflow.entity.dto.EsptoolExecutableDto;
import com.esp.espflow.enums.GetOsName;
import com.esp.espflow.service.respository.impl.EsptoolExecutableServiceImpl;
import com.esp.espflow.util.MakeExecutable;
import com.esp.espflow.util.IMakeExecutable;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.nio.file.Path;

import static com.esp.espflow.util.EspFlowConstants.ESPTOOL_BUNDLE_DIR;
import static com.esp.espflow.util.EspFlowConstants.JAVA_IO_TEMPORAL_DIR_OS;

Expand All @@ -20,7 +18,7 @@
@Log4j2
@Service
@RequiredArgsConstructor
public class EsptoolPathService implements MakeExecutable {
public class EsptoolPathService implements IMakeExecutable {

private final EsptoolExecutableServiceImpl esptoolExecutableServiceImpl;
private String esptoolPath = StringUtils.EMPTY;
Expand All @@ -39,7 +37,6 @@ public String esptoolPath() {
log.info("Loaded esptoolPath() esptool.py bundled {}", esptoolPath);
} else {
this.esptoolPath = esptoolBundleDto.absolutePathEsptool();
this.makeExecutable(esptoolPath);
log.info("Loaded esptoolPath() custom esptool.py from {}", esptoolBundleDto.absolutePathEsptool());
}
}, () -> {
Expand Down Expand Up @@ -70,7 +67,6 @@ public String esptoolPath(EsptoolExecutableDto esptoolExecutableDto) {
log.info("Loaded esptool.py bundled {}", esptoolPath);
} else {
this.esptoolPath = esptoolBundleDto.absolutePathEsptool();
this.makeExecutable(esptoolPath);
log.info("Loaded custom esptool.py from {}", esptoolBundleDto.absolutePathEsptool());
}
}, () -> {
Expand Down Expand Up @@ -104,17 +100,4 @@ private String bundlePath() {
}
}

/**
*
*/
private void makeExecutable(String esptoolPath) {
if (GetOsName.getOsName() == GetOsName.LINUX) {
if (this.makeExecutable(Path.of(esptoolPath))) {
log.info("esptool is executable");
} else {
log.info("Error when setting permissions in the esptool executable {}", esptoolPath);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ComputeSha256Service {
/**
* First dir /home/user/.espflow/1.0.0/esptool/esptool.py
*
* @param fileName the input file
* @param fileName the input file /home/user/.espflow/1.0.0/esptool/esptool.py
* @return A {@link Mono} with computed 256 hash
*/
public Mono<EsptoolSha256Dto> computeSha256(final String fileName) {
Expand All @@ -47,7 +47,7 @@ public Mono<EsptoolSha256Dto> computeSha256(final String fileName) {
}

/**
* @param fileName the input file
* @param fileName the input file /home/user/.espflow/1.0.0/esptool/esptool.py
* @return A {@link Mono} with sha256 computed String
*/
private Mono<EsptoolSha256Dto> startComputeSha256(final String fileName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
package com.esp.espflow.util;

import com.esp.espflow.enums.GetOsName;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;
import java.util.logging.Logger;

import static com.esp.espflow.util.EspFlowConstants.SET_CHMOD_X;

/**
* @author rubn
*/
public interface MakeExecutable {
public interface IMakeExecutable {

Logger log = Logger.getLogger(IMakeExecutable.class.getName());

default boolean makeExecutable(String esptoolPath) {
boolean isExecutable = false;
if (GetOsName.getOsName() == GetOsName.LINUX) {
if (this.setPosixFilePermissions(Path.of(esptoolPath))) {
log.info("esptool is executable: " + esptoolPath);
isExecutable = true;
} else {
log.info("Error when setting permissions in the esptool executable " + esptoolPath);
isExecutable = false;
}
}
return isExecutable;
}

/**
* Set run permissions if it is a linux or macOS executable.
*
* @param esptoolPath contains the path where the esptool executable is located
*/
default boolean makeExecutable(final Path esptoolPath) {
private boolean setPosixFilePermissions(final Path esptoolPath) {
try {
Set<PosixFilePermission> permissions = PosixFilePermissions.fromString(SET_CHMOD_X);
Files.setPosixFilePermissions(esptoolPath, permissions);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/esp/espflow/util/console/OutPutConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ protected void onDetach(DetachEvent detachEvent) {
@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
if (attachEvent.isInitialAttach()) {
//if (attachEvent.isInitialAttach()) {
this.getConsole();
this.xterm.getXTerm().fit();
}
//}
}
}
34 changes: 26 additions & 8 deletions src/main/java/com/esp/espflow/views/flashesp/FlashEspView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.vaadin.flow.component.radiobutton.RadioButtonGroup;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.component.splitlayout.SplitLayout.Orientation;
import com.vaadin.flow.router.AfterNavigationEvent;
import com.vaadin.flow.router.AfterNavigationObserver;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteAlias;
Expand Down Expand Up @@ -78,7 +80,7 @@
@RolesAllowed("ADMIN")
@RequiredArgsConstructor
//@PreserveOnRefresh
public class FlashEspView extends Div implements ResponsiveHeaderDiv {
public class FlashEspView extends Div implements AfterNavigationObserver, ResponsiveHeaderDiv {

private final DivFlashUploader divFlashUploader;
private final DivHeaderPorts divHeaderPorts;
Expand All @@ -97,6 +99,7 @@ public class FlashEspView extends Div implements ResponsiveHeaderDiv {
/**
* OutputConsole
*/
private Div divColumnItems = new Div();
private final OutPutConsole outPutConsole = new OutPutConsole();

private String[] commands;
Expand Down Expand Up @@ -158,12 +161,12 @@ private SplitLayout getSplitLayout() {
divRowToSecondary.addClassNames(Display.FLEX, FlexDirection.ROW);
divRowToSecondary.getStyle().set(OVERFLOW_Y, HIDDEN);

outPutConsole.getStyle().set("overflow-x", "hidden");
outPutConsole.getDivTextArea().removeClassNames(Left.LARGE, Right.LARGE);
outPutConsole.getButtonClear().addClassName(BOX_SHADOW_VAADIN_BUTTON);
outPutConsole.getButtonDownScroll().addClassName(BOX_SHADOW_VAADIN_BUTTON);
Div divColumnItems = new Div(outPutConsole.getButtonDownScroll(),
outPutConsole.getButtonClear());
// outPutConsole.getStyle().set("overflow-x", "hidden");
// outPutConsole.getDivTextArea().removeClassNames(Left.LARGE, Right.LARGE);
// outPutConsole.getButtonClear().addClassName(BOX_SHADOW_VAADIN_BUTTON);
// outPutConsole.getButtonDownScroll().addClassName(BOX_SHADOW_VAADIN_BUTTON);
// Div divColumnItems = new Div(outPutConsole.getButtonDownScroll(),
// outPutConsole.getButtonClear());
divColumnItems.setId("divColumnItems");

divColumnItems.addClassNames(
Expand Down Expand Up @@ -194,7 +197,11 @@ private SplitLayout getSplitLayout() {

splitLayout.getSecondaryComponent().getElement().getStyle().set("scrollbar-color", "#3b3b3b #202020");

splitLayout.addClickListener(event -> this.outPutConsole.fit());
splitLayout.addClickListener(event -> {
if(this.outPutConsole.isAttached()) {
this.outPutConsole.fit();
}
});

return splitLayout;
}
Expand Down Expand Up @@ -419,4 +426,15 @@ protected void onAttach(AttachEvent attachEvent) {

}

@Override
public void afterNavigation(AfterNavigationEvent event) {
//Ignored listener invocation for terminal-initialized event from the client side for an inert fc-xterm element
if(outPutConsole.isAttached()) {
outPutConsole.getStyle().set("overflow-x", "hidden");
outPutConsole.getDivTextArea().removeClassNames(Left.LARGE, Right.LARGE);
outPutConsole.getButtonClear().addClassName(BOX_SHADOW_VAADIN_BUTTON);
outPutConsole.getButtonDownScroll().addClassName(BOX_SHADOW_VAADIN_BUTTON);
this.divColumnItems.add(outPutConsole.getButtonDownScroll(), outPutConsole.getButtonClear());
}
}
}
31 changes: 23 additions & 8 deletions src/main/java/com/esp/espflow/views/readflash/ReadFlashView.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import com.vaadin.flow.component.splitlayout.SplitLayout.Orientation;
import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.AfterNavigationEvent;
import com.vaadin.flow.router.AfterNavigationObserver;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.PageTitle;
Expand Down Expand Up @@ -97,7 +99,7 @@
@Route(value = "read-flash", layout = MainLayout.class)
@RolesAllowed("ADMIN")
@RequiredArgsConstructor
public class ReadFlashView extends Div implements ResponsiveHeaderDiv, BeforeEnterObserver {
public class ReadFlashView extends Div implements ResponsiveHeaderDiv, AfterNavigationObserver, BeforeEnterObserver {

private final FlashDownloadButtonService flashDownloadButtonService;
private final EsptoolService esptoolService;
Expand All @@ -117,6 +119,7 @@ public class ReadFlashView extends Div implements ResponsiveHeaderDiv, BeforeEnt
* Console output
*/
private final OutPutConsole outPutConsole = new OutPutConsole();
private final Div divColumnItems = new Div();
private final Span spanTotalDevices = new Span("Total devices:");
private final Span spanPortFailure = new Span(PORT_FAILURE);
private final Span spanTotalDevicesValue = new Span();
Expand Down Expand Up @@ -282,13 +285,13 @@ private Div divForConsoleOutput() {
divRowToSecondary.getStyle().set(OVERFLOW_Y, HIDDEN);
divRowToSecondary.getStyle().set("background", "linear-gradient(var(--lumo-shade-5pct), var(--lumo-shade-5pct))");

outPutConsole.getStyle().set("overflow-x", "hidden");
outPutConsole.getDivTextArea().removeClassNames(Left.LARGE, Right.LARGE);
outPutConsole.getButtonClear().addClassName(BOX_SHADOW_VAADIN_BUTTON);
outPutConsole.getButtonDownScroll().addClassName(BOX_SHADOW_VAADIN_BUTTON);

Div divColumnItems = new Div(outPutConsole.getButtonDownScroll(),
outPutConsole.getButtonClear());
// outPutConsole.getStyle().set("overflow-x", "hidden");
// outPutConsole.getDivTextArea().removeClassNames(Left.LARGE, Right.LARGE);
// outPutConsole.getButtonClear().addClassName(BOX_SHADOW_VAADIN_BUTTON);
// outPutConsole.getButtonDownScroll().addClassName(BOX_SHADOW_VAADIN_BUTTON);
//
// Div divColumnItems = new Div(outPutConsole.getButtonDownScroll(),
// outPutConsole.getButtonClear());
divColumnItems.setId("divColumnItems");

divColumnItems.addClassNames(
Expand Down Expand Up @@ -682,6 +685,18 @@ public void beforeEnter(BeforeEnterEvent event) {
});
}

@Override
public void afterNavigation(AfterNavigationEvent event) {
//Ignored listener invocation for terminal-initialized event from the client side for an inert fc-xterm element
if(outPutConsole.isAttached()) {
outPutConsole.getStyle().set("overflow-x", "hidden");
outPutConsole.getDivTextArea().removeClassNames(Left.LARGE, Right.LARGE);
outPutConsole.getButtonClear().addClassName(BOX_SHADOW_VAADIN_BUTTON);
outPutConsole.getButtonDownScroll().addClassName(BOX_SHADOW_VAADIN_BUTTON);
this.divColumnItems.add(outPutConsole.getButtonDownScroll(), outPutConsole.getButtonClear());
}
}

@Override
protected void onDetach(DetachEvent detachEvent) {
super.onDetach(detachEvent);
Expand Down
Loading

0 comments on commit 3b3dba7

Please sign in to comment.