Skip to content

Commit 2339b56

Browse files
authored
Add files via upload
1 parent 99aae09 commit 2339b56

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/main/java/com/example/NtfyClient.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@
88
import java.net.http.HttpRequest;
99
import java.net.http.HttpResponse;
1010

11+
import io.github.cdimascio.dotenv.Dotenv;
1112
import org.json.JSONObject;
1213

1314
public class NtfyClient {
14-
15+
private final String baseUrl;
1516
private final String topic;
1617
private final HttpClient client;
1718

1819
public NtfyClient(String topic) {
20+
21+
Dotenv dotenv = Dotenv.load();
22+
String backendUrl = "https://ntfy.sh/defaulttopic";
23+
this.baseUrl = dotenv.get("BACKEND_URL");
24+
System.out.println("Backend URL: " + backendUrl);
25+
26+
try {
27+
dotenv = Dotenv.load();
28+
if (dotenv.get("BACKEND_URL") != null) {
29+
backendUrl = dotenv.get("BACKEND_URL");
30+
}
31+
} catch (Exception e) {
32+
System.err.println("⚠️ Could not load .env file, using default URL.");
33+
}
34+
1935
this.topic = topic;
2036
this.client = HttpClient.newHttpClient();
2137
}
2238

23-
// ---- SEND ----
39+
2440
public void sendMessage(String username, String message) {
2541
try {
2642
String json = String.format("""
@@ -43,10 +59,10 @@ public void sendMessage(String username, String message) {
4359
}
4460
}
4561

46-
// ---- RECEIVE ----
62+
4763
public void subscribe(MessageHandler handler) {
4864
new Thread(() -> {
49-
while (true) { // reconnect loop for robustness
65+
while (true) {
5066
try {
5167
HttpRequest request = HttpRequest.newBuilder()
5268
.uri(URI.create("https://ntfy.sh/" + topic + "/json"))

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
requires java.net.http;
77
requires jdk.hotspot.agent;
88
requires org.json;
9+
requires io.github.cdimascio.dotenv.java;
910

1011
opens com.example to javafx.fxml;
1112
exports com.example;

src/main/resources/com/example/hello-view.fxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<Font size="13.0" />
2525
</font>
2626
</Button>
27+
<ChoiceBox layoutX="-162.0" layoutY="119.0" prefWidth="150.0" />
2728

2829

2930

0 commit comments

Comments
 (0)