Skip to content

Commit

Permalink
Merge pull request #16 from BeanVortex/bug_fix
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
BeanVortex authored May 6, 2024
2 parents e0c101b + 53fc1d9 commit 86c0033
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 50 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.5
VERSION: 1.4.6
EXT_VERSION: 1.0
NAME: BitKip
jobs:
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 'io.beanvortex'
version '1.4.5'
version '1.4.6'
sourceCompatibility = '21'
targetCompatibility = '21'
mainClassName = 'io.beanvortex.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.5
Version=1.4.6
Comment=Free download manager
Keywords=download,java,app
Exec=/usr/share/BitKip/bin/BitKip
Expand Down
2 changes: 1 addition & 1 deletion extensions/chrome_based/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon" : "./src/resources/icons/logo.png"
},
"manifest_version": 3,
"version": "1.0",
"version": "1.1",
"description": "Download grabber that works with BitKip application",
"host_permissions": ["*://*/*"],
"permissions": [
Expand Down
6 changes: 4 additions & 2 deletions extensions/chrome_based/src/scripts/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ const postLinks = async (data, isBatch) => {
fetch(URL_TO_POST, {
method: 'POST',
body: JSON.stringify(data),
}).catch(_ => {
}).catch(async _ => {
chrome.notifications.create('', {
title: 'BitKip Extension',
message: "Can't send url to BitKip, Is application running on the same port?",
iconUrl: '../resources/icons/logo.png',
type: 'basic'
});
chrome.downloads.download({url: data.url})
chrome.downloads.onDeterminingFilename.removeListener(triggerDownload)
await chrome.downloads.download({url: data.url})
chrome.downloads.onDeterminingFilename.addListener(triggerDownload)
});
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 3,
"version": "1.0",
"version": "1.1",
"name": "BitKip extension",

"action": {
Expand Down
10 changes: 6 additions & 4 deletions extensions/firefox/src/scripts/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ const postLinks = async (data, isBatch) => {
method: 'POST',
mode: "cors",
body: JSON.stringify(data),
}).catch(_ => {
}).catch(async _ => {
browser.notifications.create('', {
title: 'BitKip Extension',
message: "Can't send url to BitKip, Is application running on the same port?",
iconUrl: '../resources/icons/logo.png',
type: 'basic'
});
browser.downloads.download({url: data.url})
browser.downloads.onCreated.removeListener(triggerDownload)
await browser.downloads.download({url: data.url})
browser.downloads.onCreated.addListener(triggerDownload)
});
}

Expand Down Expand Up @@ -94,12 +96,12 @@ browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
const triggerDownload = (downloadItem) => {
// final url is used when url itself is a redirecting link
updateEnable();
if (!enabled || (downloadItem.mime && downloadItem.mime.includes("image")))
if (!enabled || (downloadItem.mime && downloadItem.mime.includes("image")))
return;
let url = downloadItem.finalUrl || downloadItem.url;
if (isSupportedProtocol(url)) {
let filename = downloadItem.filename;
if (filename.includes('/')){
if (filename.includes('/')) {
const start = downloadItem.filename.lastIndexOf('/');
filename = downloadItem.filename.substring(start === -1 ? 0 : start + 1);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/beanvortex/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.5";
public static final String VERSION = "1.4.6";

public static final String dataPath = System.getProperty("user.home")
+ File.separator + "Documents"
Expand Down Expand Up @@ -61,6 +61,7 @@ public class AppConfigs {
public static boolean addSameDownload = defaultAddSameDownload;
public static final boolean defaultLessCpuIntensive = false;
public static boolean lessCpuIntensive = defaultLessCpuIntensive;
public static String lastSavedDir = null;



Expand Down
23 changes: 15 additions & 8 deletions src/main/java/io/beanvortex/bitkip/controllers/BatchDownload.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.beanvortex.bitkip.controllers;

import io.beanvortex.bitkip.config.AppConfigs;
import io.beanvortex.bitkip.utils.FxUtils;
import io.beanvortex.bitkip.config.observers.QueueObserver;
import io.beanvortex.bitkip.config.observers.QueueSubject;
Expand All @@ -12,10 +13,7 @@
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.stage.Stage;
import org.kordamp.ikonli.javafx.FontIcon;

Expand Down Expand Up @@ -46,7 +44,8 @@ public class BatchDownload implements QueueObserver {
private ComboBox<QueueModel> queueCombo;
@FXML
private TextField chunksField, urlField;

@FXML
private CheckBox lastLocationCheck;

private LinkModel tempLink;
private Stage stage;
Expand Down Expand Up @@ -79,6 +78,7 @@ public void initialize(URL location, ResourceBundle resources) {
queueCombo.setValue(queues.get(0));
errorLabel.setVisible(false);
checkBtn.setDisable(true);
lastLocationCheck.setDisable(true);
Validations.prepareLinkFromClipboard(urlField);
Validations.validateChunksInput(chunksField);
Validations.validateIntInputCheck(startField, 0L, 0, null);
Expand Down Expand Up @@ -109,7 +109,7 @@ public void initialize(URL location, ResourceBundle resources) {
private void onOfflineFieldsChanged() {
if (tempLink != null)
handleError(() -> DownloadUtils.onOfflineFieldsChanged(locationField, tempLink.getName(),
null, queueCombo, null, checkBtn, openLocation, null), errorLabel);
null, queueCombo, null, checkBtn, openLocation, null, lastLocationCheck), errorLabel);

}

Expand All @@ -128,7 +128,7 @@ private void autoFillLocation() {
fileNameLocationFuture
.whenComplete((unused, throwable) ->
handleError(() -> DownloadUtils.checkIfFileIsOKToSave(locationField.getText(),
tempLink.getName(), null, checkBtn, null), errorLabel))
tempLink.getName(), null, checkBtn, null, lastLocationCheck), errorLabel))
.exceptionally(throwable -> {
var errorMsg = throwable.getCause().getLocalizedMessage();
Platform.runLater(() ->
Expand Down Expand Up @@ -231,7 +231,7 @@ private void onSelectLocation(ActionEvent e) {
locationField.setText(path);
if (tempLink != null)
handleError(() -> DownloadUtils.checkIfFileIsOKToSave(locationField.getText(),
tempLink.getName(), null, checkBtn, null), errorLabel);
tempLink.getName(), null, checkBtn, null, lastLocationCheck), errorLabel);
}

@FXML
Expand Down Expand Up @@ -341,6 +341,13 @@ private void onQueueChanged() {
onOfflineFieldsChanged();
}

@FXML
private void onLastLocationCheck() {
if (lastLocationCheck.isSelected())
locationField.setText(AppConfigs.lastSavedDir);
else
setLocation(tempLink.getName());
}
}


25 changes: 17 additions & 8 deletions src/main/java/io/beanvortex/bitkip/controllers/SingleDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.stage.Stage;
import org.kordamp.ikonli.javafx.FontIcon;

Expand All @@ -29,6 +26,8 @@

public class SingleDownload implements QueueObserver {

@FXML
private CheckBox lastLocationCheck;
@FXML
private Label sizeLabel, resumableLabel, errorLabel;
@FXML
Expand Down Expand Up @@ -78,6 +77,7 @@ public void initialize(URL location, ResourceBundle resources) {
refreshBtn.setGraphic(new FontIcon());
refreshBtn.setDisable(true);
refreshBtn.setVisible(false);
lastLocationCheck.setDisable(true);
refreshBtn.setOnAction(e -> {
refreshBtn.setDisable(true);
refreshBtn.setVisible(false);
Expand Down Expand Up @@ -162,14 +162,14 @@ private void autoFillLocationAndSizeAndName() {
var connection = DownloadUtils.connect(url);
var executor = Executors.newVirtualThreadPerTaskExecutor();
var fileNameLocationFuture =
DownloadUtils.prepareFileNameAndFieldsAsync(connection, url, nameField, executor)
DownloadUtils.prepareFileNameAndFieldsAsync(connection, url, nameField, dm, executor)
.thenAccept(this::setLocation);
var sizeFuture = DownloadUtils.prepareFileSizeAndFieldsAsync(connection,
urlField, sizeLabel, resumableLabel, speedField, chunksField, bytesField, dm, executor);
CompletableFuture.allOf(fileNameLocationFuture, sizeFuture)
.whenComplete((unused, throwable) -> {
DownloadUtils.handleError(() -> DownloadUtils.checkIfFileIsOKToSave(locationField.getText(),
nameField.getText(), downloadBtn, addBtn, refreshBtn), errorLabel);
nameField.getText(), downloadBtn, addBtn, refreshBtn, lastLocationCheck), errorLabel);
executor.shutdown();
})
.exceptionally(throwable -> {
Expand All @@ -195,7 +195,15 @@ private void onSelectLocation(ActionEvent e) {
if (path != null)
locationField.setText(path);
DownloadUtils.handleError(() -> DownloadUtils.checkIfFileIsOKToSave(locationField.getText(),
nameField.getText(), downloadBtn, addBtn, refreshBtn), errorLabel);
nameField.getText(), downloadBtn, addBtn, refreshBtn, lastLocationCheck), errorLabel);
}

@FXML
private void onLastLocationCheck() {
if (lastLocationCheck.isSelected())
locationField.setText(AppConfigs.lastSavedDir);
else
setLocation(dm.getName());
}

@FXML
Expand Down Expand Up @@ -314,7 +322,7 @@ private void onQueueChanged() {

private void onOfflineFieldsChanged() {
DownloadUtils.handleError(() -> DownloadUtils.onOfflineFieldsChanged(locationField, nameField.getText(), dm, queueCombo,
downloadBtn, addBtn, openLocation, refreshBtn), errorLabel);
downloadBtn, addBtn, openLocation, refreshBtn, lastLocationCheck), errorLabel);
}


Expand All @@ -323,4 +331,5 @@ public void setUrlModel(SingleURLModel urlModel) {
initAfterUrlModel();
}


}
24 changes: 13 additions & 11 deletions src/main/java/io/beanvortex/bitkip/utils/DownloadUtils.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package io.beanvortex.bitkip.utils;

import io.beanvortex.bitkip.config.AppConfigs;
import io.beanvortex.bitkip.exceptions.DeniedException;
import io.beanvortex.bitkip.models.DownloadModel;
import io.beanvortex.bitkip.models.QueueModel;
import io.beanvortex.bitkip.repo.DownloadsRepo;
import io.beanvortex.bitkip.repo.QueuesRepo;
import javafx.application.Platform;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import org.controlsfx.control.Notifications;
Expand All @@ -35,7 +31,7 @@ public class DownloadUtils {
public static HttpURLConnection connect(String uri) throws IOException {
if (uri.isBlank())
throw new IllegalArgumentException("URL is blank");
uri = fixURIChars(uri);
uri = Validations.fixURIChars(uri);
var url = URI.create(uri).toURL();
var conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(connectionTimeout);
Expand Down Expand Up @@ -168,7 +164,7 @@ public static String extractFileName(String link, HttpURLConnection connection)
}

public static CompletableFuture<String> prepareFileNameAndFieldsAsync(HttpURLConnection connection, String link,
TextField nameField, Executor executor) {
TextField nameField, DownloadModel dm, Executor executor) {
final HttpURLConnection[] finalConnection = {connection};
return CompletableFuture.supplyAsync(() -> {
if (finalConnection[0] == null) {
Expand All @@ -181,6 +177,7 @@ public static CompletableFuture<String> prepareFileNameAndFieldsAsync(HttpURLCon
var fileName = extractFileName(link, finalConnection[0]);
if (nameField != null)
Platform.runLater(() -> nameField.setText(fileName));
dm.setName(fileName);
return fileName;
}, executor);
}
Expand Down Expand Up @@ -235,12 +232,16 @@ public static void initPopOvers(Button[] questionButtons, String[] contents) {
public static String selectLocation(Stage stage) {
var dirChooser = new DirectoryChooser();
dirChooser.setTitle("Select download save location");
dirChooser.setInitialDirectory(new File(AppConfigs.downloadPath));
dirChooser.setInitialDirectory(new File(lastSavedDir));
var selectedDir = dirChooser.showDialog(stage);
if (selectedDir != null) {
var path = selectedDir.getPath();
if (!path.endsWith(File.separator))
path += File.separator;
if (!lastSavedDir.equals(path)) {
lastSavedDir = path;
IOUtils.saveConfigs();
}
return path;
}
Notifications.create()
Expand All @@ -251,7 +252,7 @@ public static String selectLocation(Stage stage) {
}

public static void checkIfFileIsOKToSave(String location, String name, Button downloadBtn,
Button addBtn, Button refreshBtn) throws DeniedException {
Button addBtn, Button refreshBtn, CheckBox lastLocationCheck) throws DeniedException {
var file = new File(location + name);
var chunkFile = new File(location + name + "#0");
if (file.exists() || chunkFile.exists()) {
Expand All @@ -271,6 +272,7 @@ public static void checkIfFileIsOKToSave(String location, String name, Button do
refreshBtn.setDisable(true);
refreshBtn.setVisible(false);
}
lastLocationCheck.setDisable(false);
addBtn.setDisable(false);
}
}
Expand All @@ -297,7 +299,7 @@ public interface ERunnable {

public static void onOfflineFieldsChanged(TextField locationField, String filename, DownloadModel dm,
ComboBox<QueueModel> queueCombo, Button downloadBtn, Button addBtn,
Button openLocation, Button refreshBtn) throws DeniedException {
Button openLocation, Button refreshBtn, CheckBox lastLocationCheck) throws DeniedException {
// when saving outside BitKip folder
var selectedQueue = queueCombo.getSelectionModel().getSelectedItem();
if (!locationField.getText().contains("BitKip")
Expand All @@ -320,7 +322,7 @@ public static void onOfflineFieldsChanged(TextField locationField, String filena
setLocationAndQueue(locationField, filename, dm);
openLocation.setDisable(false);
}
checkIfFileIsOKToSave(locationField.getText(), filename, downloadBtn, addBtn, refreshBtn);
checkIfFileIsOKToSave(locationField.getText(), filename, downloadBtn, addBtn, refreshBtn, lastLocationCheck);
}

public static void disableControlsAndShowError(String error, Label errorLbl,
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/io/beanvortex/bitkip/utils/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public static void saveConfigs() {
.append("immediate_download=").append(String.valueOf(downloadImmediately)).append("\n")
.append("add_same_download=").append(String.valueOf(addSameDownload)).append("\n")
.append("less_cpu_intensive=").append(String.valueOf(lessCpuIntensive)).append("\n")
.append("last_saved_dir=").append(String.valueOf(lastSavedDir)).append("\n")
.append("user_agent_enabled=").append(String.valueOf(userAgentEnabled)).append("\n")
.append("user_agent=").append(userAgent);
writer.flush();
Expand All @@ -310,7 +311,11 @@ public static void readConfig() {
var key = cfg.split("=")[0];
var value = cfg.split("=")[1];
switch (key) {
case "save_location" -> downloadPath = value;
case "save_location" -> {
downloadPath = value;
if (lastSavedDir == null || !lastSavedDir.equals(downloadPath))
lastSavedDir = downloadPath;
}
case "theme" -> theme = value;
case "startup" -> startup = value.equals("true");
case "server_enabled" -> serverEnabled = value.equals("true");
Expand All @@ -325,6 +330,7 @@ public static void readConfig() {
case "immediate_download" -> downloadImmediately = value.equals("true");
case "add_same_download" -> addSameDownload = value.equals("true");
case "less_cpu_intensive" -> lessCpuIntensive = value.equals("true");
case "last_saved_dir" -> lastSavedDir = value;
case "user_agent" -> userAgent = value;
case "user_agent_enabled" -> userAgentEnabled = value.equals("true");
}
Expand Down
Loading

0 comments on commit 86c0033

Please sign in to comment.