Commit ef8535f0 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer 🎼
Browse files

add Stoppable interface for Controller which run background subProcess. The...

add Stoppable interface for Controller which run background subProcess. The subProcess can now be killed when the app close
parent 59725166
Pipeline #141868 passed with stages
in 11 minutes and 3 seconds
......@@ -22,6 +22,7 @@ import ecorp.easy.installer.EasyInstaller;
import ecorp.easy.installer.controllers.stepControllers.CustomExecutableController;
import ecorp.easy.installer.controllers.stepControllers.CustomStepController;
import ecorp.easy.installer.controllers.stepControllers.StepController;
import ecorp.easy.installer.controllers.stepControllers.Stoppable;
import ecorp.easy.installer.models.Phone;
import ecorp.easy.installer.models.steps.IStep;
import ecorp.easy.installer.tasks.CommandRunnerService;
......@@ -67,6 +68,8 @@ public class MainWindowController implements Initializable {
Phone device; //Object encapsulating data about the device to flash
private boolean isFlashed = false; // True when /e/ OS installed on device
private String currentStepKey = "f0";
private Object subController;
/**
* Initializes the controller class.
......@@ -342,6 +345,7 @@ public class MainWindowController implements Initializable {
if(controller != null){
loader.setController(controller);
subController = controller;
}
try{
......@@ -353,7 +357,14 @@ public class MainWindowController implements Initializable {
}
if(controller == null){
final Object ctrl = loader.getController();
if(ctrl != null && ctrl instanceof AbstractSubController) ((AbstractSubController)ctrl).setParentController(this);
if(ctrl != null){
subController = ctrl;
if( ctrl instanceof AbstractSubController )
{
((AbstractSubController)ctrl).setParentController(this);
}
}
}
return loader;
}
......@@ -402,6 +413,9 @@ public class MainWindowController implements Initializable {
*/
public void onStop(){
logger.debug("onStop()");
if(subController != null && subController instanceof Stoppable){
((Stoppable) subController).stop();
}
}
/**
......
......@@ -42,7 +42,7 @@ import javafx.scene.layout.VBox;
* my need. But If you find a way please implement it!
* @author vincent Bourgmayer
*/
public class CustomExecutableController extends StepController<CustomExecutableStep>{
public class CustomExecutableController extends StepController<CustomExecutableStep> implements Stoppable{
protected final ResourceBundle IMG_BUNDLE = ResourceBundle.getBundle("instructions.imageName",
new Locale.Builder()
......@@ -171,4 +171,10 @@ public class CustomExecutableController extends StepController<CustomExecutableS
((VBox)uiRoot).setAlignment(Pos.TOP_CENTER);
((VBox)uiRoot).getChildren().add(tryAgainBtn);
}
@Override
public void stop() {
logger.debug("CustomExecutableController.stop()");
backgroundService.cancel();
}
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ import javafx.util.Duration;
*
* @author vincent Bourgmayer
*/
public class LoadStepController extends StepController<LoadStep>{
public class LoadStepController extends StepController<LoadStep> implements Stoppable{
@FXML private ProgressBar taskProgressBar;
@FXML private Label titleLbl;
......@@ -118,4 +118,10 @@ public class LoadStepController extends StepController<LoadStep>{
((VBox)uiRoot).setAlignment(Pos.TOP_CENTER);
((VBox)uiRoot).getChildren().add(tryAgainBtn);
}
@Override
public void stop() {
logger.debug("LoadStepController.stop()");
service.cancel();
}
}
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package ecorp.easy.installer.controllers.stepControllers;
/**
*
* @author vincent
*/
public interface Stoppable {
public void stop();
}
......@@ -50,18 +50,11 @@ public class FlashSceneController {
@FXML HBox globalProgressIndicator;
private FlashGlobalProgressManager globalProgressMgr;
// node relative to Log
@FXML ScrollPane logScrollPane;
@FXML TextFlow logFlow;
@FXML Button showHideLogBtn;
@FXML Button sendLogBtn;
private final static Logger logger = LoggerFactory.getLogger(FlashSceneController.class);
public void initialize(URL location, ResourceBundle resources) {
logFlow.heightProperty().addListener(observable -> logScrollPane.setVvalue(1.0));
}
/**
......@@ -74,8 +67,8 @@ public class FlashSceneController {
Thread thread = parentController.getThreadFactory().buildFlashThread(null/*this*/, null);
if(thread!= null){
globalProgressMgr = new FlashGlobalProgressManager(0/*thread.getCommandsSize()*/);
globalProgressIndicator.getChildren().addAll(globalProgressMgr.getSegments());
//globalProgressMgr = new FlashGlobalProgressManager(0/*thread.getCommandsSize()*/);
//globalProgressIndicator.getChildren().addAll(globalProgressMgr.getSegments());
thread.start();
}
......@@ -130,58 +123,5 @@ public class FlashSceneController {
}
/**
* enable/disable log displaying
*/
public void showHideLog(){
ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
GUIAppender appender = (GUIAppender) rootLogger.getAppender("GUI");
final String text = showHideLogBtn.getText();
if(text.equals(">")){
showHideLogBtn.setText("V");
UiUtils.hideNode(logScrollPane);
logFlow.getChildren().clear();
appender.setContainer(null);
}else{
showHideLogBtn.setText(">");
UiUtils.showNode(logScrollPane);
logFlow.getChildren().addAll(appender.getLogsList());
appender.setContainer(logFlow);
}
}
/**
* Send log to support, in special ecloud.global folder
* @return
*/
public boolean sendLogToSupport(){
//if (thread != null){
String filePath = LogPathPropertyDefiner.getLogFilePath();
if(filePath != null){
UploadToEcloudTask uploadTask = new UploadToEcloudTask(AppConstants.LOG_STORAGE_URL, filePath);
uploadTask.setOnSucceeded(eh -> {
if( (Boolean) eh.getSource().getValue() ){ //if success
sendLogBtn.setDisable(true);
//sendLogBtn.setText(i18n.getString("install_btn_sendLogSuccess"));
logger.info("sendLogToSupport(), sending log: success");
}
else{
//sendLogBtn.setText(i18n.getString("install_btn_sendLogAgain"));
logger.warn("sendLogToSupport(), sending log: failure");
}
});
uploadTask.setOnFailed(eh->{
//sendLogBtn.setText(i18n.getString("install_btn_sendLogAgain"));
logger.warn("sendLogToSupport(), sending log: failure, error = {}",eh.getSource().getException().toString() );
});
Thread uploadTaskThread = new Thread(uploadTask);
uploadTaskThread.setDaemon(true);
uploadTaskThread.start();
}
return false;
}
}
\ No newline at end of file
......@@ -65,6 +65,7 @@ public class CommandRunnerService extends Service<Boolean>{
try{
cmd.execAndReadOutput();
}catch( IOException | InterruptedException e){
cmd.cancel();
logger.error("cmd.execAndReadOutput(), error = {}", e.toString() );
return false;
}
......@@ -95,7 +96,11 @@ public class CommandRunnerService extends Service<Boolean>{
}
};
task.setOnCancelled(eh->{
logger.debug("CommandRunnerService.task.onCancelled()");
cmd.cancel();
});
return task;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment