Skip to content

Commit

Permalink
Merge pull request #14 from DarkDeveloper-arch/revertVirtualThreads
Browse files Browse the repository at this point in the history
revertVirtualThreads
  • Loading branch information
BeanVortex authored Oct 12, 2023
2 parents a43db15 + f65a82a commit df97803
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- main
env:
VERSION: 1.4.0
VERSION: 1.4.1
NAME: BitKip
jobs:
build-windows:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'ir.darkdeveloper'
version '1.4.0'
version '1.4.1'
sourceCompatibility = '21'
targetCompatibility = '21'
mainClassName = 'ir.darkdeveloper.bitkip.BitKip'
Expand Down
2 changes: 1 addition & 1 deletion builders/linux-installer/application/BitKip.desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Desktop Entry]
Name=BitKip
Version=1.4.0
Version=1.4.1
Comment=Free download manager
Keywords=download,java,app
Exec=/usr/share/BitKip/bin/BitKip
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ir/darkdeveloper/bitkip/config/AppConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class AppConfigs {

public static final String VERSION = "1.4.0";
public static final String VERSION = "1.4.1";

public static final String dataPath = System.getProperty("user.home")
+ File.separator + "Documents"
Expand Down Expand Up @@ -57,6 +57,8 @@ public class AppConfigs {
public static boolean downloadImmediately = defaultDownloadImmediately;
public static final boolean defaultAddSameDownload = true;
public static boolean addSameDownload = defaultAddSameDownload;
public static final boolean defaultLessCpuIntensive = false;
public static boolean lessCpuIntensive = defaultLessCpuIntensive;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void initialize(URL location, ResourceBundle resources) {
checkBtn.setDisable(true);
Validations.prepareLinkFromClipboard(urlField);
Validations.validateChunksInput(chunksField);
Validations.validateIntInputCheck(startField, 0L);
Validations.validateIntInputCheck(endField, 0L);
Validations.validateIntInputCheck(startField, 0L, 0, null);
Validations.validateIntInputCheck(endField, 0L, 0, null);
var questionBtns = new Button[]{questionBtnUrl, questionBtnChunks};
var contents = new String[]{
"You want to download several files, clarify where urls are different by $ sign." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class DetailsController implements FXMLController {
private Button controlBtn, openFolderBtn;

private Stage stage;
private DownloadModel downloadModel;
private DownloadModel dm;
private boolean isComplete = false;
private final BooleanProperty isPaused = new SimpleBooleanProperty(true);
private final PopOver linkPopover = new PopOver();
Expand All @@ -93,41 +93,41 @@ public Stage getStage() {
return stage;
}

public void setDownloadModel(DownloadModel downloadModel) {
this.downloadModel = downloadModel;
public void setDownloadModel(DownloadModel dm) {
this.dm = dm;
initDownloadData();
initDownloadListeners();
}

private void initDownloadData() {
Validations.validateInputChecks(null, bytesField, speedField, downloadModel);
var byteLimit = String.valueOf(downloadModel.getByteLimit());
Validations.validateInputChecks(null, bytesField, speedField, dm);
var byteLimit = String.valueOf(dm.getByteLimit());
if (byteLimit.equals("0"))
byteLimit = String.valueOf(downloadModel.getSize());
byteLimit = String.valueOf(dm.getSize());
bytesField.setText(byteLimit);
bytesField.setDisable(downloadModel.getSize() < 0 || !downloadModel.isResumable());
speedField.setDisable(!downloadModel.isResumable());
var mbOfBytes = IOUtils.getMbOfBytes(downloadModel.getSpeedLimit());
speedField.setText(downloadModel.getSpeedLimit() == 0 ? "0.0" : String.valueOf(mbOfBytes));
downloadedBytes.setText(String.valueOf(downloadModel.getDownloaded()));
link.setText(downloadModel.getUrl());
locationLbl.setText("Path: " + new File(downloadModel.getFilePath()).getParentFile().getAbsolutePath());
var end = downloadModel.getName().length();
bytesField.setDisable(dm.getSize() < 0 || !dm.isResumable());
speedField.setDisable(!dm.isResumable());
var mbOfBytes = IOUtils.getMbOfBytes(dm.getSpeedLimit());
speedField.setText(dm.getSpeedLimit() == 0 ? "0.0" : String.valueOf(mbOfBytes));
downloadedBytes.setText(String.valueOf(dm.getDownloaded()));
link.setText(dm.getUrl());
locationLbl.setText("Path: " + new File(dm.getFilePath()).getParentFile().getAbsolutePath());
var end = dm.getName().length();
if (end > 60)
end = 60;
stage.setTitle(downloadModel.getName().substring(0, end));
nameLbl.setText("Name: " + downloadModel.getName());
var queues = QueuesRepo.findQueuesOfADownload(downloadModel.getId()).toString();
stage.setTitle(dm.getName().substring(0, end));
nameLbl.setText("Name: " + dm.getName());
var queues = QueuesRepo.findQueuesOfADownload(dm.getId()).toString();
queueLbl.setText("Queues: " + queues.substring(1, queues.length() - 1));
statusLbl.setText("Status: " + downloadModel.getDownloadStatus().name());
statusLbl.setText("Status: " + dm.getDownloadStatus().name());
var downloadOf = "%s / %s"
.formatted(IOUtils.formatBytes(downloadModel.getDownloaded()),
IOUtils.formatBytes(downloadModel.getSize()));
.formatted(IOUtils.formatBytes(dm.getDownloaded()),
IOUtils.formatBytes(dm.getSize()));
downloadedOfLbl.setText(downloadOf);
progressLbl.setText("Progress: %.2f%%".formatted(downloadModel.getProgress()));
downloadProgress.setProgress(downloadModel.getProgress() / 100);
chunksLbl.setText("Chunks: " + downloadModel.getChunks());
var resumable = downloadModel.isResumable();
progressLbl.setText("Progress: %.2f%%".formatted(dm.getProgress()));
downloadProgress.setProgress(dm.getProgress() / 100);
chunksLbl.setText("Chunks: " + dm.getChunks());
var resumable = dm.isResumable();
if (resumable) {
resumableLbl.getStyleClass().add("yes");
resumableLbl.getStyleClass().remove("no");
Expand All @@ -138,10 +138,10 @@ private void initDownloadData() {
resumableLbl.setText("No");
}
controlBtn.setText(isPaused.get() ? (resumable ? "Resume" : "Restart") : "Pause");
openSwitch.setSelected(downloadModel.isOpenAfterComplete());
showSwitch.setSelected(downloadModel.isShowCompleteDialog());
onComplete(downloadModel);
turnOffCombo.getSelectionModel().select(downloadModel.getTurnOffMode());
openSwitch.setSelected(dm.isOpenAfterComplete());
showSwitch.setSelected(dm.isShowCompleteDialog());
onComplete(dm);
turnOffCombo.getSelectionModel().select(dm.getTurnOffMode());
}

public void initDownloadListeners() {
Expand All @@ -156,13 +156,13 @@ public void initDownloadListeners() {

private DownloadTask getDownloadTask() {
return currentDownloadings.stream()
.filter(dm -> dm.equals(downloadModel))
.filter(dm -> dm.equals(this.dm))
.findFirst()
.map(DownloadModel::getDownloadTask).orElse(null);
}

private void bytesDownloadedListener(DownloadTask dt) {
if (downloadModel.getSize() != -1)
if (dm.getSize() != -1)
dt.valueProperty().addListener((ob, o, bytes) -> {
if (!isPaused.get()) {
if (o == null)
Expand All @@ -171,22 +171,22 @@ private void bytesDownloadedListener(DownloadTask dt) {

downloadedBytes.setText(String.valueOf(bytes));
if (bytes == 0) {
downloadedBytes.setText(String.valueOf(downloadModel.getDownloaded()));
downloadedBytes.setText(String.valueOf(dm.getDownloaded()));
speed = 0;
} else
downloadModel.setDownloaded(bytes);
dm.setDownloaded(bytes);

downloadModel.setSpeed(speed);
downloadModel.setDownloadStatus(Downloading);
dm.setSpeed(speed);
dm.setDownloadStatus(Downloading);

speedLbl.setText(IOUtils.formatBytes(speed));
statusLbl.setText("Status: " + Downloading);
var downloadOf = "%s / %s"
.formatted(IOUtils.formatBytes(bytes),
IOUtils.formatBytes(downloadModel.getSize()));
IOUtils.formatBytes(dm.getSize()));
downloadedOfLbl.setText(downloadOf);
if (speed > 0) {
long delta = downloadModel.getSize() - bytes;
long delta = dm.getSize() - bytes;
var remaining = DurationFormatUtils.formatDuration((delta / speed) * 1000, "dd:HH:mm:ss");
remainingLbl.setText("Remaining: " + remaining);
}
Expand All @@ -195,8 +195,8 @@ private void bytesDownloadedListener(DownloadTask dt) {
else
dt.valueProperty().addListener((ob, o, bytes) -> {
if (!isPaused.get()) {
downloadModel.setDownloadStatus(Downloading);
downloadModel.setDownloaded(bytes);
dm.setDownloadStatus(Downloading);
dm.setDownloaded(bytes);
statusLbl.setText("Status: " + Downloading);
var downloadOf = "%s / %s".formatted(IOUtils.formatBytes(bytes), IOUtils.formatBytes(0));
downloadedOfLbl.setText(downloadOf);
Expand All @@ -222,12 +222,12 @@ public void initialize(URL location, ResourceBundle resources) {
else updatePause(newValue);
});
openSwitch.selectedProperty().addListener((o, old, newVal) -> {
downloadModel.setOpenAfterComplete(newVal);
DownloadsRepo.updateDownloadOpenAfterComplete(downloadModel);
dm.setOpenAfterComplete(newVal);
DownloadsRepo.updateDownloadOpenAfterComplete(dm);
});
showSwitch.selectedProperty().addListener((o, old, newVal) -> {
downloadModel.setShowCompleteDialog(newVal);
DownloadsRepo.updateDownloadShowCompleteDialog(downloadModel);
dm.setShowCompleteDialog(newVal);
DownloadsRepo.updateDownloadShowCompleteDialog(dm);
});
linkPopover.setAnimated(true);
linkPopover.setContentNode(new Label("Copied"));
Expand All @@ -243,22 +243,22 @@ public void initialize(URL location, ResourceBundle resources) {
}

private void updatePause(Boolean paused) {
if (downloadModel.getDownloadStatus() == DownloadStatus.Completed)
if (dm.getDownloadStatus() == DownloadStatus.Completed)
return;
controlBtn.setDisable(false);

controlBtn.setText(paused ? (downloadModel.isResumable() ? "Resume" : "Restart") : "Pause");
controlBtn.setText(paused ? (dm.isResumable() ? "Resume" : "Restart") : "Pause");
if (paused)
remainingLbl.setText("Remaining: Paused");
if (downloadModel.getDownloadStatus() == DownloadStatus.Merging) {
if (dm.getDownloadStatus() == DownloadStatus.Merging) {
setPauseButtonDisable(true);
updateLabels("Status: " + DownloadStatus.Merging.name(), "Remaining: Merging");
downloadProgress.setProgress(ProgressBar.INDETERMINATE_PROGRESS);
} else
statusLbl.setText("Status: " + (paused ? DownloadStatus.Paused : Downloading));
var downloadOf = "%s / %s"
.formatted(IOUtils.formatBytes(downloadModel.getDownloaded()),
IOUtils.formatBytes(downloadModel.getSize()));
.formatted(IOUtils.formatBytes(dm.getDownloaded()),
IOUtils.formatBytes(dm.getSize()));
downloadedOfLbl.setText(downloadOf);

}
Expand All @@ -271,15 +271,15 @@ private void onClose() {
@FXML
private void onControl() {
if (isComplete) {
openFile(downloadModel);
openFile(dm);
stage.close();
return;
}

if (isPaused.get()) {
statusLbl.setText("Status: " + DownloadStatus.Trying);
controlBtn.setDisable(true);
DownloadOpUtils.resumeDownloads(List.of(downloadModel),
DownloadOpUtils.resumeDownloads(List.of(dm),
getBytesFromString(speedField.getText()), Long.parseLong(bytesField.getText()));
controlBtn.setDisable(false);
isPaused.set(false);
Expand Down Expand Up @@ -319,8 +319,8 @@ public void onComplete(DownloadModel download) {
statusLbl.setText("Status: Complete");
progressLbl.setText("Progress: 100%");
var downloadOf = "%s / %s"
.formatted(IOUtils.formatBytes(downloadModel.getSize()),
IOUtils.formatBytes(downloadModel.getSize()));
.formatted(IOUtils.formatBytes(dm.getSize()),
IOUtils.formatBytes(dm.getSize()));
downloadedOfLbl.setText(downloadOf);
bytesField.setDisable(true);
speedField.setDisable(true);
Expand All @@ -341,25 +341,25 @@ public void closeStage() {
}

public DownloadModel getDownloadModel() {
return downloadModel;
return dm;
}


@FXML
private void onFolderOpen() {
DownloadOpUtils.openContainingFolder(downloadModel);
DownloadOpUtils.openContainingFolder(dm);
stage.close();
}

@FXML
private void onTurnOffChanged() {
var value = turnOffCombo.getValue();
downloadModel.setTurnOffMode(value);
var downloadTask = downloadModel.getDownloadTask();
dm.setTurnOffMode(value);
var downloadTask = dm.getDownloadTask();
if (downloadTask != null)
downloadTask.setDownloadModel(downloadModel);
downloadTask.setDownloadModel(dm);
DatabaseHelper.updateCol(COL_TURNOFF_MODE,
value.toString(), DOWNLOADS_TABLE_NAME, downloadModel.getId());
value.toString(), DOWNLOADS_TABLE_NAME, dm.getId());
if (value != NOTHING) {
Notifications.create()
.title("Turn off mode changed")
Expand All @@ -370,11 +370,11 @@ private void onTurnOffChanged() {

@FXML
private void onSpeedApplied() {
var dmTask = downloadModel.getDownloadTask();
var dmTask = dm.getDownloadTask();
if (dmTask instanceof ChunksDownloadTask cdt) {
var speed = getBytesFromString(speedField.getText());
downloadModel.setSpeed(speed);
downloadModel.setSpeedLimit(speed);
dm.setSpeed(speed);
dm.setSpeedLimit(speed);
cdt.setSpeedLimit(speed);
speedApplyBtn.setDisable(true);
speedApplyBtn.setVisible(false);
Expand All @@ -383,7 +383,7 @@ private void onSpeedApplied() {

@FXML
private void onAllBytes() {
bytesField.setText(String.valueOf(downloadModel.getSize()));
bytesField.setText(String.valueOf(dm.getSize()));
allBytesBtn.setVisible(false);
allBytesBtn.setDisable(true);
}
Expand All @@ -394,17 +394,17 @@ private void onBytesChanged() {
return;
if (!text.matches("\\d*"))
text = text.replaceAll("\\D", "");
if (Long.parseLong(text) < downloadModel.getSize()) {
if (Long.parseLong(text) < dm.getSize()) {
allBytesBtn.setVisible(true);
allBytesBtn.setDisable(false);
}
if (Long.parseLong(text) < downloadModel.getDownloaded())
bytesField.setText(String.valueOf(downloadModel.getDownloaded()));
if (Long.parseLong(text) < dm.getDownloaded())
bytesField.setText(String.valueOf(dm.getDownloaded()));

}

private void onSpeedChanged() {
var isDownloading = downloadModel.getDownloadStatus() == Downloading;
var isDownloading = dm.getDownloadStatus() == Downloading;
var isZero = speedField.getText().equals("0");
speedApplyBtn.setVisible(isDownloading && !isZero);
speedApplyBtn.setDisable(isDownloading && isZero);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void initInputs() {
Validations.validateTimePickerInputs(startHourSpinner, startMinuteSpinner, startSecondSpinner);
Validations.validateTimePickerInputs(stopHourSpinner, stopMinuteSpinner, stopSecondSpinner);
Validations.validateSpeedInput(speedField);
Validations.validateIntInputCheck(simulDownloadSpinner.getEditor(), 1, 1, 5);
Validations.validateIntInputCheck(simulDownloadSpinner.getEditor(), 1L, 1, 5);


datePicker.setDayCellFactory(dp -> new DateCell() {
Expand Down
Loading

0 comments on commit df97803

Please sign in to comment.