make config io in other thread, only save config if favicon changed, launcher: hide empty cells

This commit is contained in:
Bixilon 2020-08-31 22:07:22 +02:00
parent 8f5365f738
commit dd5c864d60
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 29 additions and 12 deletions

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.config;
import de.bixilon.minosoft.Config; import de.bixilon.minosoft.Config;
import de.bixilon.minosoft.gui.main.Server; import de.bixilon.minosoft.gui.main.Server;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.util.mojang.api.MojangAccount; import de.bixilon.minosoft.util.mojang.api.MojangAccount;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
@ -27,7 +28,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class Configuration { public class Configuration {
LinkedHashMap<String, Object> config; final LinkedHashMap<String, Object> config;
public Configuration(String filename) throws IOException { public Configuration(String filename) throws IOException {
@ -171,6 +172,8 @@ public class Configuration {
} }
public void saveToFile(String filename) { public void saveToFile(String filename) {
Thread thread = new Thread(() -> {
Yaml yaml = new Yaml(); Yaml yaml = new Yaml();
FileWriter writer; FileWriter writer;
try { try {
@ -179,8 +182,14 @@ public class Configuration {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
synchronized (config) {
yaml.dump(config, writer); yaml.dump(config, writer);
} }
Log.verbose(String.format("Configuration saved to file %s", filename));
});
thread.setName("IO-Thread");
thread.start();
}
public ArrayList<MojangAccount> getMojangAccounts() { public ArrayList<MojangAccount> getMojangAccounts() {
ArrayList<MojangAccount> accounts = new ArrayList<>(); ArrayList<MojangAccount> accounts = new ArrayList<>();

View File

@ -57,6 +57,8 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
public MenuItem optionsEdit; public MenuItem optionsEdit;
@FXML @FXML
public MenuItem optionsDelete; public MenuItem optionsDelete;
@FXML
public MenuButton optionsMenu;
boolean canConnect = false; boolean canConnect = false;
@FXML @FXML
private Label serverName; private Label serverName;
@ -90,9 +92,11 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
protected void updateItem(Server server, boolean empty) { protected void updateItem(Server server, boolean empty) {
super.updateItem(server, empty); super.updateItem(server, empty);
root.setVisible(!empty);
if (empty) { if (empty) {
return; return;
} }
if (server == null) { if (server == null) {
return; return;
} }
@ -165,9 +169,12 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
} }
motd.setText(ping.getMotd().getRawMessage()); motd.setText(ping.getMotd().getRawMessage());
if (ping.getFavicon() != null) { if (ping.getFavicon() != null) {
icon.setImage(ping.getFavicon());
if (ping.getBase64EncodedFavicon().equals(server.getBase64Favicon())) {
return;
}
server.setBase64Favicon(ping.getBase64EncodedFavicon()); server.setBase64Favicon(ping.getBase64EncodedFavicon());
server.saveToConfig(); server.saveToConfig();
icon.setImage(ping.getFavicon());
} }
})); }));
@ -242,6 +249,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
public void delete() { public void delete() {
listView.getItems().remove(server); listView.getItems().remove(server);
server.delete(); server.delete();
Log.info(String.format("Deleted server (name=\"%s\", address=\"%s\")", server.getName(), server.getAddress()));
} }
public void connect() { public void connect() {

View File

@ -26,7 +26,7 @@
AnchorPane.topAnchor="40.0"/> AnchorPane.topAnchor="40.0"/>
<Label fx:id="version" layoutX="350.0" layoutY="8.0" text="Connecting..." AnchorPane.rightAnchor="110.0" <Label fx:id="version" layoutX="350.0" layoutY="8.0" text="Connecting..." AnchorPane.rightAnchor="110.0"
AnchorPane.topAnchor="5.0"/> AnchorPane.topAnchor="5.0"/>
<MenuButton id="options" layoutX="389.0" layoutY="81.0" mnemonicParsing="false" text="⋮" <MenuButton fx:id="optionsMenu" layoutX="389.0" layoutY="81.0" mnemonicParsing="false" text="⋮"
AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0"> AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
<items> <items>
<MenuItem fx:id="optionsDelete" mnemonicParsing="false" text="Delete"/> <MenuItem fx:id="optionsDelete" mnemonicParsing="false" text="Delete"/>