mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
make config io in other thread, only save config if favicon changed, launcher: hide empty cells
This commit is contained in:
parent
8f5365f738
commit
dd5c864d60
@ -15,6 +15,7 @@ package de.bixilon.minosoft.config;
|
||||
|
||||
import de.bixilon.minosoft.Config;
|
||||
import de.bixilon.minosoft.gui.main.Server;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.util.mojang.api.MojangAccount;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
@ -27,7 +28,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Configuration {
|
||||
LinkedHashMap<String, Object> config;
|
||||
final LinkedHashMap<String, Object> config;
|
||||
|
||||
public Configuration(String filename) throws IOException {
|
||||
|
||||
@ -171,15 +172,23 @@ public class Configuration {
|
||||
}
|
||||
|
||||
public void saveToFile(String filename) {
|
||||
Yaml yaml = new Yaml();
|
||||
FileWriter writer;
|
||||
try {
|
||||
writer = new FileWriter(Config.homeDir + "config/" + filename);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
yaml.dump(config, writer);
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
Yaml yaml = new Yaml();
|
||||
FileWriter writer;
|
||||
try {
|
||||
writer = new FileWriter(Config.homeDir + "config/" + filename);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
synchronized (config) {
|
||||
yaml.dump(config, writer);
|
||||
}
|
||||
Log.verbose(String.format("Configuration saved to file %s", filename));
|
||||
});
|
||||
thread.setName("IO-Thread");
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public ArrayList<MojangAccount> getMojangAccounts() {
|
||||
|
@ -57,6 +57,8 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
public MenuItem optionsEdit;
|
||||
@FXML
|
||||
public MenuItem optionsDelete;
|
||||
@FXML
|
||||
public MenuButton optionsMenu;
|
||||
boolean canConnect = false;
|
||||
@FXML
|
||||
private Label serverName;
|
||||
@ -90,9 +92,11 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
protected void updateItem(Server server, boolean empty) {
|
||||
super.updateItem(server, empty);
|
||||
|
||||
root.setVisible(!empty);
|
||||
if (empty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
return;
|
||||
}
|
||||
@ -165,9 +169,12 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
}
|
||||
motd.setText(ping.getMotd().getRawMessage());
|
||||
if (ping.getFavicon() != null) {
|
||||
icon.setImage(ping.getFavicon());
|
||||
if (ping.getBase64EncodedFavicon().equals(server.getBase64Favicon())) {
|
||||
return;
|
||||
}
|
||||
server.setBase64Favicon(ping.getBase64EncodedFavicon());
|
||||
server.saveToConfig();
|
||||
icon.setImage(ping.getFavicon());
|
||||
}
|
||||
}));
|
||||
|
||||
@ -242,6 +249,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
public void delete() {
|
||||
listView.getItems().remove(server);
|
||||
server.delete();
|
||||
Log.info(String.format("Deleted server (name=\"%s\", address=\"%s\")", server.getName(), server.getAddress()));
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
|
@ -26,7 +26,7 @@
|
||||
AnchorPane.topAnchor="40.0"/>
|
||||
<Label fx:id="version" layoutX="350.0" layoutY="8.0" text="Connecting..." AnchorPane.rightAnchor="110.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">
|
||||
<items>
|
||||
<MenuItem fx:id="optionsDelete" mnemonicParsing="false" text="Delete"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user