Ensure closing the window exits.
This commit is contained in:
parent
8d5c8e67e2
commit
369e96226f
|
@ -1 +1 @@
|
||||||
version = 0.0.1
|
version = 0.0.2
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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");
|
||||||
} catch (IOException e) {
|
|
||||||
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) -> {
|
services.forEach((item, color) -> {
|
||||||
String service = String.format("_%s._%s.local.", item, "tcp");
|
String service = String.format("_%s._%s.local.", item, "tcp");
|
||||||
NetworkServiceListener networkServiceListener = new NetworkServiceListener(service, observableList, color);
|
NetworkServiceListener networkServiceListener = new NetworkServiceListener(service, observableList, color);
|
||||||
jmdns.addServiceListener(service, networkServiceListener);
|
jmdns.addServiceListener(service, networkServiceListener);
|
||||||
});
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("initialize() - {}", e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue