Skip to content

Commit bca3770

Browse files
committed
improved exceptionhandling
1 parent a8be253 commit bca3770

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = 'dev.codeman'
6-
version = '0.0.5'
6+
version = '0.0.6'
77

88
repositories {
99
mavenCentral()
@@ -20,12 +20,13 @@ java {
2020
}
2121

2222
def nativeDownloadDir = layout.buildDirectory.dir("native-download").get().asFile
23-
def nativeDllFile = nativeDownloadDir.toPath().resolve("SMTC4J.dll").toFile()
23+
def downloadedNativeDllFile = nativeDownloadDir.toPath().resolve("SMTC4J.dll").toFile()
2424
def resourcesNativeDir = layout.buildDirectory.dir("resources/main/native").get().asFile
25+
def nativeDllFile = file("src/main/resources/native/SMTC4J.dll") // for dev environment
2526

2627
tasks.register("downloadNative") {
2728
doLast {
28-
if (nativeDllFile.exists()) {
29+
if (downloadedNativeDllFile.exists() || nativeDllFile.exists()) {
2930
println "Native DLL already exists, skipping download."
3031
return
3132
}
@@ -36,7 +37,7 @@ tasks.register("downloadNative") {
3637
println "Downloading native DLL from $url"
3738

3839
new URL(url).withInputStream { input ->
39-
nativeDllFile.withOutputStream { output ->
40+
downloadedNativeDllFile.withOutputStream { output ->
4041
output << input
4142
}
4243
}
@@ -45,8 +46,9 @@ tasks.register("downloadNative") {
4546

4647
tasks.register("copyNativeIntoResources", Copy) {
4748
dependsOn "downloadNative"
48-
from(nativeDllFile)
49+
from(downloadedNativeDllFile)
4950
into(resourcesNativeDir)
51+
onlyIf { downloadedNativeDllFile.exists() }
5052
}
5153

5254
tasks.named("processResources") {

src/main/java/dev/codeman/smtc4j/SMTC4J.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import com.google.gson.JsonSyntaxException;
56

67
import java.io.*;
78
import java.util.concurrent.Executors;
@@ -107,11 +108,12 @@ public static MediaInfo parsedMediaInfo() {
107108
return new MediaInfo("", "", "", 0, "", "");
108109
}
109110

110-
MediaInfo parsed = GSON.fromJson(info, MediaInfo.class);
111-
if (parsed == null)
111+
try {
112+
return GSON.fromJson(info, MediaInfo.class);
113+
} catch (JsonSyntaxException e) {
114+
System.out.println("Error parsing media info: " + e.getMessage());
112115
return new MediaInfo("", "", "", 0, "", "");
113-
114-
return parsed;
116+
}
115117
}
116118

117119
public static PlaybackState parsedPlaybackState() {
@@ -124,11 +126,12 @@ public static PlaybackState parsedPlaybackState() {
124126
return new PlaybackState(-1, 0);
125127
}
126128

127-
PlaybackState parsed = GSON.fromJson(state, PlaybackState.class);
128-
if (parsed == null)
129+
try {
130+
return GSON.fromJson(state, PlaybackState.class);
131+
} catch (Exception e) {
132+
System.out.println("Error retrieving playback state: " + e.getMessage());
129133
return new PlaybackState(-1, 0);
130-
131-
return parsed;
134+
}
132135
}
133136

134137
public static void pressKey(MediaKey key) {

0 commit comments

Comments
 (0)