Skip to content

Commit 54ed099

Browse files
committed
Unregister SpotifyConnect when closing
1 parent 3e1b299 commit 54ed099

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/core/ZeroconfServer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ private ZeroconfServer(Session.Inner inner, Configuration conf) throws IOExcepti
127127

128128
if (atLeastOne) LOGGER.info("SpotifyConnect service registered successfully!");
129129
else throw new IllegalStateException("Could not register the service anywhere!");
130+
131+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
132+
try {
133+
System.out.println(this);
134+
close();
135+
} catch (IOException ignored) {
136+
}
137+
}));
130138
}
131139

132140
@NotNull
@@ -187,8 +195,9 @@ private static InetAddress[] getAllInterfacesAddresses() throws SocketException
187195

188196
@Override
189197
public void close() throws IOException {
190-
for (JmDNS instance : instances)
191-
instance.unregisterAllServices();
198+
for (JmDNS instance : instances) {
199+
if (instance != null) instance.unregisterAllServices();
200+
}
192201

193202
LOGGER.trace("SpotifyConnect service unregistered successfully.");
194203
runner.close();

0 commit comments

Comments
 (0)