Skip to content

Commit 0178937

Browse files
authored
Merge pull request #25 from BeanVortex/1.6.1
1.6.1
2 parents f1a1a71 + 88627e2 commit 0178937

File tree

11 files changed

+98
-14
lines changed

11 files changed

+98
-14
lines changed

.github/workflows/ci_cd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- main
66
env:
7-
VERSION: 1.6.0
7+
VERSION: 1.6.1
88
EXT_VERSION: 1.3
99
NAME: BitKip
1010
jobs:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group 'io.beanvortex'
11-
version '1.6.0'
11+
version '1.6.1'
1212
//sourceCompatibility = '25'
1313
//targetCompatibility = '25'
1414
//mainClassName = 'io.beanvortex.bitkip.BitKip'

builders/linux-installer/application/BitKip.desktop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Desktop Entry]
22
Name=BitKip
3-
Version=1.6.0
3+
Version=1.6.1
44
Comment=Free download manager
55
Keywords=download,java,app
66
Exec=/usr/share/BitKip/bin/BitKip

src/main/java/io/beanvortex/bitkip/BitKip.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.beanvortex.bitkip;
22

33
import io.beanvortex.bitkip.api.BatchService;
4+
import io.beanvortex.bitkip.api.NewInstanceService;
45
import io.beanvortex.bitkip.api.SingleService;
56
import io.beanvortex.bitkip.api.SyncService;
67
import io.beanvortex.bitkip.exceptions.GlobalExceptionHandler;
@@ -41,9 +42,10 @@
4142
public class BitKip extends Application {
4243

4344
private static WebServer server;
44-
45+
private static Stage stage;
4546
@Override
4647
public void start(Stage stage) {
48+
BitKip.stage = stage;
4749
IOUtils.readConfig();
4850
AppConfigs.initPaths();
4951
IOUtils.createSaveLocations();
@@ -75,15 +77,19 @@ private static void trustAllConnections() {
7577
public X509Certificate[] getAcceptedIssuers() {
7678
return new X509Certificate[0];
7779
}
78-
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
79-
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
80+
81+
public void checkClientTrusted(X509Certificate[] certs, String authType) {
82+
}
83+
84+
public void checkServerTrusted(X509Certificate[] certs, String authType) {
85+
}
8086
}
8187
};
8288
SSLContext sc = SSLContext.getInstance("TLS");
8389
sc.init(null, trustAllCerts, new SecureRandom());
8490
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
8591

86-
HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
92+
HttpsURLConnection.setDefaultHostnameVerifier((_, _) -> true);
8793
} catch (Exception e) {
8894
throw new RuntimeException(e);
8995
}
@@ -110,13 +116,16 @@ private void initTray(Stage stage) {
110116
var popup = new PopupMenu();
111117
var openItem = new MenuItem("Open App");
112118
var exitItem = new MenuItem("Exit App");
113-
ActionListener openListener = e -> Platform.runLater(() -> {
119+
ActionListener openListener = _ -> Platform.runLater(() -> {
114120
if (stage.isShowing())
115121
stage.toFront();
116122
else stage.show();
117123
});
124+
if (hideOnStart)
125+
stage.close();
126+
118127
openItem.addActionListener(openListener);
119-
exitItem.addActionListener(e -> stop());
128+
exitItem.addActionListener(_ -> stop());
120129
popup.add(openItem);
121130
popup.add(exitItem);
122131
var trayIcon = new TrayIcon(image, "BitKip", popup);
@@ -136,7 +145,8 @@ private void initTray(Stage stage) {
136145
@Override
137146
public void stop() {
138147
var notObservedDms = new ArrayList<>(currentDownloadings);
139-
notObservedDms.forEach(dm -> dm.getDownloadTask().pause(()->{}));
148+
notObservedDms.forEach(dm -> dm.getDownloadTask().pause(() -> {
149+
}));
140150
startedQueues.clear();
141151
currentSchedules.values().forEach(sm -> {
142152
var startScheduler = sm.getStartScheduler();
@@ -174,6 +184,7 @@ private static void startServer() {
174184
.register("/single", cors, new SingleService())
175185
.register("/batch", cors, new BatchService())
176186
.register("/sync", cors, new SyncService())
187+
.register("/new_instance", cors, new NewInstanceService())
177188
.build();
178189
var jacksonSupport = JacksonSupport.create();
179190
server = WebServer.builder()
@@ -182,7 +193,12 @@ private static void startServer() {
182193
.addRouting(routing)
183194
.addMediaSupport(jacksonSupport)
184195
.build();
196+
185197
server.start().exceptionally(throwable -> {
198+
if (InstanceManager.notifyCurrentInstance()){
199+
Platform.exit();
200+
return null;
201+
}
186202
var header = "Failed to start server. Is there another instance running?\nIf not you may need to change application server port and restart";
187203
log.error(header);
188204
Platform.runLater(() -> {
@@ -198,4 +214,8 @@ private static void startServer() {
198214
public static URL getResource(String path) {
199215
return BitKip.class.getResource(path);
200216
}
217+
218+
public static void show(){
219+
stage.show();
220+
}
201221
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.beanvortex.bitkip;
2+
3+
import io.beanvortex.bitkip.config.AppConfigs;
4+
5+
import java.net.URI;
6+
import java.net.http.HttpClient;
7+
import java.net.http.HttpRequest;
8+
import java.net.http.HttpResponse;
9+
import java.time.Duration;
10+
11+
public class InstanceManager {
12+
public static boolean notifyCurrentInstance() {
13+
try (var client = HttpClient.newBuilder()
14+
.connectTimeout(Duration.ofSeconds(5))
15+
.build()) {
16+
17+
var request = HttpRequest.newBuilder()
18+
.uri(URI.create("http://127.0.0.1:" + AppConfigs.serverPort + "/new_instance"))
19+
.GET()
20+
.timeout(Duration.ofSeconds(5))
21+
.build();
22+
23+
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
24+
return response.statusCode() == 200;
25+
} catch (Exception e) {
26+
27+
return false;
28+
}
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.beanvortex.bitkip.api;
2+
3+
import io.beanvortex.bitkip.BitKip;
4+
import io.helidon.webserver.Routing;
5+
import io.helidon.webserver.ServerRequest;
6+
import io.helidon.webserver.ServerResponse;
7+
import io.helidon.webserver.Service;
8+
import javafx.application.Platform;
9+
10+
public class NewInstanceService implements Service {
11+
@Override
12+
public void update(Routing.Rules rules) {
13+
rules.get("/", this::doGet);
14+
}
15+
16+
private void doGet(ServerRequest req, ServerResponse res) {
17+
Platform.runLater(BitKip::show);
18+
res.status(200);
19+
res.send("OK");
20+
}
21+
}

src/main/java/io/beanvortex/bitkip/config/AppConfigs.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class AppConfigs {
1919

20-
public static final String VERSION = "1.6.0";
20+
public static final String VERSION = "1.6.1";
2121

2222
public static final String dataPath = System.getProperty("user.home")
2323
+ File.separator + "Documents"
@@ -68,6 +68,8 @@ public class AppConfigs {
6868
public static boolean startFastQueue = defaultStartFastQueue;
6969
public static final boolean defaultTrustAllServers = false;
7070
public static boolean trustAllServers = defaultTrustAllServers;
71+
public static final boolean defaultHideOnStart = false;
72+
public static boolean hideOnStart = defaultHideOnStart;
7173

7274

7375

src/main/java/io/beanvortex/bitkip/controllers/SettingsController.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
public class SettingsController implements FXMLController {
4141

4242
@FXML
43-
private CheckBox immediateCheck, startupCheck, triggerOffCheck, agentCheck, addDownCheck,
43+
private CheckBox immediateCheck, startupCheck, hideStartCheck, triggerOffCheck, agentCheck, addDownCheck,
4444
continueCheck, completeDialogCheck, errorNotificationCheck, startFastQueueCheck, trustAllServersCheck, serverCheck, lessCpuCheck;
4545
@FXML
4646
private VBox root, actionArea, queueContainer;
@@ -62,13 +62,13 @@ public void initAfterStage() {
6262
initQueues();
6363
stage.setTitle("Settings");
6464
stage.setResizable(true);
65-
stage.setOnCloseRequest(e -> {
65+
stage.setOnCloseRequest(_ -> {
6666
ThemeSubject.getThemeSubject().removeObserver(this);
6767
QueueSubject.getQueueSubject().removeObserver(queueController);
6868
});
6969
var defaultWidth = stage.getMinWidth() + 50;
7070
var defaultHeight = stage.getMinHeight() + 50;
71-
tabPane.getSelectionModel().selectedIndexProperty().addListener((ob, o, n) -> {
71+
tabPane.getSelectionModel().selectedIndexProperty().addListener((_, _, n) -> {
7272
// if queue tab is selected
7373
if (n.intValue() == 2) {
7474
root.getChildren().remove(actionArea);
@@ -104,6 +104,7 @@ private void initElements() {
104104
lblLocation.setText(AppConfigs.downloadPath);
105105
serverCheck.setSelected(AppConfigs.serverEnabled);
106106
startupCheck.setSelected(AppConfigs.startup);
107+
hideStartCheck.setSelected(AppConfigs.hideOnStart);
107108
triggerOffCheck.setSelected(AppConfigs.triggerTurnOffOnEmptyQueue);
108109
immediateCheck.setSelected(AppConfigs.downloadImmediately);
109110
addDownCheck.setSelected(AppConfigs.addSameDownload);
@@ -314,6 +315,12 @@ private void onStartupCheck() {
314315
initStartup();
315316
}
316317

318+
@FXML
319+
private void onHideStartCheck() {
320+
AppConfigs.hideOnStart = hideStartCheck.isSelected();
321+
IOUtils.saveConfigs();
322+
}
323+
317324
private void initStartup() {
318325
try {
319326
if (AppConfigs.startup && !existsOnStartup())

src/main/java/io/beanvortex/bitkip/utils/IOUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public static void saveConfigs() {
285285
writer.append("save_location=").append(downloadPath).append("\n")
286286
.append("theme=").append(theme).append("\n")
287287
.append("startup=").append(String.valueOf(startup)).append("\n")
288+
.append("hide_on_start=").append(String.valueOf(hideOnStart)).append("\n")
288289
.append("server_enabled=").append(String.valueOf(serverEnabled)).append("\n")
289290
.append("port=").append(String.valueOf(serverPort)).append("\n")
290291
.append("trigger_turn_off_on_empty_queue=").append(String.valueOf(triggerTurnOffOnEmptyQueue)).append("\n")
@@ -326,6 +327,7 @@ public static void readConfig() {
326327
case "save_location" -> downloadPath = value;
327328
case "theme" -> theme = value;
328329
case "startup" -> startup = value.equals("true");
330+
case "hide_on_start" -> hideOnStart = value.equals("true");
329331
case "server_enabled" -> serverEnabled = value.equals("true");
330332
case "port" -> serverPort = Integer.parseInt(value);
331333
case "trigger_turn_off_on_empty_queue" -> triggerTurnOffOnEmptyQueue = value.equals("true");

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
requires java.prefs;
3030
requires com.zaxxer.hikari;
3131
requires context.propagation;
32+
requires java.net.http;
3233

3334
opens io.beanvortex.bitkip to javafx.fxml, javafx.controls;
3435
opens io.beanvortex.bitkip.controllers to javafx.fxml, javafx.base;

0 commit comments

Comments
 (0)