Ensure closing the window exits.
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Mark Nellemann 2023-08-14 20:03:50 +02:00
parent 8d5c8e67e2
commit 369e96226f
4 changed files with 15 additions and 52 deletions

View file

@ -1 +1 @@
version = 0.0.1 version = 0.0.2

View file

@ -16,16 +16,14 @@ import java.io.IOException;
public class App extends Application { public class App extends Application {
@Override
public void init() {
Platform.setImplicitExit(true);
}
@Override @Override
public void start(Stage primaryStage) throws IOException { public void start(Stage primaryStage) throws IOException {
// Make all stages close and the app exit when the primary stage is closed // Make all stages close and the app exit when the primary stage is closed
primaryStage.setOnCloseRequest(e -> Platform.exit()); Platform.setImplicitExit(true);
primaryStage.setOnCloseRequest(e -> {
System.exit(0);
});
// Set icon on the application bar // Set icon on the application bar
var appIcon = new Image("/icon.png"); var appIcon = new Image("/icon.png");
@ -51,11 +49,6 @@ public class App extends Application {
} }
@Override
public void stop() {
}
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }

View file

@ -38,17 +38,9 @@ public class MainPresenter {
@FXML @FXML
public void initialize() { public void initialize() {
log.info("initialize()"); log.info("initialize()");
view.addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, event -> {
log.info("Window closing");
discoveryService.destroy();
});
discoveryService = new DiscoveryService();
discoveryService.initialize();
discoveryService.setObservableList(devicesList);
listView.setItems(devicesList); listView.setItems(devicesList);
listView.setCellFactory(p -> new NetworkServiceCell()); listView.setCellFactory(p -> new NetworkServiceCell());
discoveryService = new DiscoveryService(devicesList);
} }

View file

@ -20,16 +20,10 @@ public class DiscoveryService {
private final static Logger log = LoggerFactory.getLogger(DiscoveryService.class); private final static Logger log = LoggerFactory.getLogger(DiscoveryService.class);
private ObservableList<NetworkService> observableList; private final ObservableList<NetworkService> observableList;
private JmDNS jmdns; private JmDNS jmdns;
/*private final HashMap<String, Color> services = HashMap<>({
"http", "https", "upnp", "ssh", "sip", "rdp", "ntp", "rdp", "rtsp",
"ntp", "smb", "nfs", "llrp", "ftp", "ep", "daap", "ipp", "ipps",
"googlecast", "sonos", "airplay", "smartenergy", "skype", "bittorrent"
);*/
// From: http://www.dns-sd.org/serviceTypes.html + // From: http://www.dns-sd.org/serviceTypes.html +
// https://jonathanmumm.com/tech-it/mdns-bonjour-bible-common-service-strings-for-various-vendors/ + some guesses // https://jonathanmumm.com/tech-it/mdns-bonjour-bible-common-service-strings-for-various-vendors/ + some guesses
private final Map<String, Color> services = new HashMap<>() {{ private final Map<String, Color> services = new HashMap<>() {{
@ -68,36 +62,20 @@ public class DiscoveryService {
//put("rdlink", Color.KHAKI); //put("rdlink", Color.KHAKI);
}}; }};
public DiscoveryService(ObservableList<NetworkService> list) {
log.info("DiscoveryService()");
this.observableList = list;
public void initialize() {
log.info("initialize()");
try { try {
jmdns = JmDNS.create(InetAddress.getByName("0.0.0.0"), "mdnsExplorer"); jmdns = JmDNS.create(InetAddress.getByName("0.0.0.0"), "mdnsExplorer");
services.forEach((item, color) -> {
String service = String.format("_%s._%s.local.", item, "tcp");
NetworkServiceListener networkServiceListener = new NetworkServiceListener(service, observableList, color);
jmdns.addServiceListener(service, networkServiceListener);
});
} catch (IOException e) { } catch (IOException e) {
log.error("initialize() - {}", e.getMessage()); log.error("initialize() - {}", e.getMessage());
} }
} }
public void destroy() {
if(jmdns != null) {
try {
jmdns.close();
} catch (IOException e) {
log.error("destroy() - {}", e.getMessage());
}
}
}
public void setObservableList(ObservableList<NetworkService> list) {
this.observableList = list;
services.forEach((item, color) -> {
String service = String.format("_%s._%s.local.", item, "tcp");
NetworkServiceListener networkServiceListener = new NetworkServiceListener(service, observableList, color);
jmdns.addServiceListener(service, networkServiceListener);
});
}
} }