Fix bug displaying the double amount of unread messages
Additionally remove ChangeHandlers in SettingsItem and show StatusTrayIcon whenever supported
This commit is contained in:
parent
db28f02505
commit
98f59c1383
@ -147,6 +147,7 @@ public final class LocalDB implements EventListener {
|
||||
throw new IllegalStateException("Client user is null, cannot initialize user storage");
|
||||
userFile = new File(dbDir, user.getID() + ".db");
|
||||
try (var in = new ObjectInputStream(new FileInputStream(userFile))) {
|
||||
Chat.getTotalUnreadAmount().set(0);
|
||||
chats = FXCollections.observableList((List<Chat>) in.readObject());
|
||||
|
||||
// Some chats have changed and should not be overwritten by the saved values
|
||||
|
@ -1,7 +1,6 @@
|
||||
package envoy.client.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
@ -17,8 +16,6 @@ public final class SettingsItem<T> implements Serializable {
|
||||
private T value;
|
||||
private String userFriendlyName, description;
|
||||
|
||||
private transient Consumer<T> changeHandler;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
@ -52,8 +49,6 @@ public final class SettingsItem<T> implements Serializable {
|
||||
* @since Envoy Client v0.3-alpha
|
||||
*/
|
||||
public void set(T value) {
|
||||
if (changeHandler != null && value != this.value)
|
||||
changeHandler.accept(value);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@ -82,16 +77,4 @@ public final class SettingsItem<T> implements Serializable {
|
||||
* @since Envoy Client v0.3-alpha
|
||||
*/
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
/**
|
||||
* Sets a {@code ChangeHandler} for this {@link SettingsItem}. It will be invoked with the
|
||||
* current value once during the registration and every time when the value changes.
|
||||
*
|
||||
* @param changeHandler the changeHandler to set
|
||||
* @since Envoy Client v0.3-alpha
|
||||
*/
|
||||
public void setChangeHandler(Consumer<T> changeHandler) {
|
||||
this.changeHandler = changeHandler;
|
||||
changeHandler.accept(value);
|
||||
}
|
||||
}
|
||||
|
@ -237,17 +237,9 @@ public final class Startup extends Application {
|
||||
e.consume();
|
||||
});
|
||||
|
||||
if (StatusTrayIcon.isSupported()) {
|
||||
|
||||
// Initialize status tray icon
|
||||
final var trayIcon = new StatusTrayIcon(stage);
|
||||
Settings.getInstance().getItems().get("hideOnClose").setChangeHandler(c -> {
|
||||
if ((Boolean) c)
|
||||
trayIcon.show();
|
||||
else
|
||||
trayIcon.hide();
|
||||
});
|
||||
}
|
||||
// Initialize status tray icon
|
||||
if (StatusTrayIcon.isSupported())
|
||||
new StatusTrayIcon(stage).show();
|
||||
|
||||
// Start auto save thread
|
||||
localDB.initAutoSave();
|
||||
|
@ -16,7 +16,7 @@ import envoy.data.Message;
|
||||
import envoy.data.User.UserStatus;
|
||||
|
||||
import envoy.client.data.*;
|
||||
import envoy.client.event.OwnStatusChange;
|
||||
import envoy.client.event.*;
|
||||
import envoy.client.helper.ShutdownHelper;
|
||||
import envoy.client.util.*;
|
||||
|
||||
@ -82,10 +82,7 @@ public final class StatusTrayIcon implements EventListener {
|
||||
|
||||
// Adding the logout menu item
|
||||
final var logoutMenuItem = new MenuItem("Logout");
|
||||
logoutMenuItem.addActionListener(evt -> {
|
||||
hide();
|
||||
Platform.runLater(UserUtil::logout);
|
||||
});
|
||||
logoutMenuItem.addActionListener(evt -> Platform.runLater(UserUtil::logout));
|
||||
popup.add(logoutMenuItem);
|
||||
|
||||
// Adding the status change items
|
||||
@ -137,6 +134,7 @@ public final class StatusTrayIcon implements EventListener {
|
||||
*
|
||||
* @since Envoy Client v0.2-beta
|
||||
*/
|
||||
@Event(eventType = Logout.class)
|
||||
public void hide() {
|
||||
SystemTray.getSystemTray().remove(trayIcon);
|
||||
}
|
||||
|
@ -27,15 +27,15 @@ public final class GeneralSettingsPane extends SettingsPane {
|
||||
final var settingsItems = settings.getItems();
|
||||
|
||||
// Add hide on close if supported
|
||||
if (StatusTrayIcon.isSupported()) {
|
||||
final var hideOnCloseCheckbox =
|
||||
new SettingsCheckbox((SettingsItem<Boolean>) settingsItems.get("hideOnClose"));
|
||||
final var hideOnCloseTooltip = new Tooltip(
|
||||
"If selected, Envoy will still be present in the task bar when closed.");
|
||||
hideOnCloseTooltip.setWrapText(true);
|
||||
hideOnCloseCheckbox.setTooltip(hideOnCloseTooltip);
|
||||
getChildren().add(hideOnCloseCheckbox);
|
||||
}
|
||||
final var hideOnCloseCheckbox =
|
||||
new SettingsCheckbox((SettingsItem<Boolean>) settingsItems.get("hideOnClose"));
|
||||
final var hideOnCloseTooltip = new Tooltip(StatusTrayIcon.isSupported()
|
||||
? "If selected, Envoy will still be present in the task bar when closed."
|
||||
: "status tray icon is not supported on your system.");
|
||||
hideOnCloseTooltip.setWrapText(true);
|
||||
hideOnCloseCheckbox.setTooltip(hideOnCloseTooltip);
|
||||
hideOnCloseCheckbox.setDisable(!StatusTrayIcon.isSupported());
|
||||
getChildren().add(hideOnCloseCheckbox);
|
||||
|
||||
final var enterToSendCheckbox =
|
||||
new SettingsCheckbox((SettingsItem<Boolean>) settingsItems.get("enterToSend"));
|
||||
|
Reference in New Issue
Block a user