Skip to content

Commit 4122593

Browse files
AutumnRiveraintrofog
authored andcommitted
Rewrote running command to use native JavaFx javafx.concurrent.Task instead of java.lang.Thread
Signed-off-by: Autumn Rivera <[email protected]>
1 parent 70a163a commit 4122593

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/main/java/com/github/introfog/gitwave/controller/main/MainController.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.github.introfog.gitwave.model.dto.ParameterDto;
2626

2727
import java.io.File;
28+
import javafx.concurrent.Task;
2829
import javafx.fxml.FXML;
2930
import javafx.scene.control.Button;
3031
import javafx.scene.control.ButtonType;
@@ -121,14 +122,8 @@ protected void runCommand() {
121122
}
122123
AppConfig.getInstance().setLastRunFolder(directoryToRunIn.getAbsolutePath());
123124

124-
new Thread(() -> {
125-
// TODO #8 rewrite using javafx.concurrent.Task, because it is a native JavaFx way to do smth in background
126-
switchRunButton(true);
127-
final File scriptFile = CommandExecutor.searchGitRepositoriesAndCreateScriptFile(directoryToRunIn,
128-
commandTabController.getCommandWithParameters());
129-
switchRunButton(false);
130-
CommandExecutor.executeScriptFileWithCommand(scriptFile);
131-
}).start();
125+
Task<Void> runCommandTask = createRunCommandTask(directoryToRunIn);
126+
new Thread(runCommandTask).start();
132127
}
133128
}
134129

@@ -156,4 +151,17 @@ private void switchRunButton(boolean inProgress) {
156151
run.setDisable(inProgress);
157152
runProgress.setVisible(inProgress);
158153
}
154+
155+
private Task<Void> createRunCommandTask(File directoryToRunIn) {
156+
return new Task<Void>() {
157+
@Override protected Void call() {
158+
switchRunButton(true);
159+
final File scriptFile = CommandExecutor.searchGitRepositoriesAndCreateScriptFile(directoryToRunIn,
160+
commandTabController.getCommandWithParameters());
161+
switchRunButton(false);
162+
CommandExecutor.executeScriptFileWithCommand(scriptFile);
163+
return null;
164+
}
165+
};
166+
}
159167
}

0 commit comments

Comments
 (0)