Fix ui freeze on file open

This commit is contained in:
Arnaud Vergnet 2021-01-06 10:44:21 +01:00
parent 5f0d2ea7b1
commit a2be9c26dd

View file

@ -13,6 +13,7 @@ import javafx.scene.layout.VBox;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.DateFormat;
import java.util.ResourceBundle;
@ -41,12 +42,7 @@ public class MessageListItemController implements Initializable {
FileMessage fileMessage = ((FileMessage) message);
text += "\n<" + fileMessage.getFileName() + ">";
button.setOnMouseClicked(event -> {
Desktop desktop = Desktop.getDesktop();
try {
desktop.open(new File(fileMessage.getPath()));
} catch (IOException e) {
e.printStackTrace();
}
openFile(fileMessage.getPath());
});
}
button.setText(text);
@ -62,6 +58,18 @@ public class MessageListItemController implements Initializable {
}
}
public void openFile(String path) {
if (Desktop.isDesktopSupported()) {
new Thread(() -> {
try {
Desktop.getDesktop().open(new File(path));
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}
}
/**
* Removes any style applied to the background
*/