Skip to content

Commit

Permalink
Remove explicit and implicit chat auto reconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Dec 31, 2023
1 parent 9bec826 commit a2fae9a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/main/java/com/faforever/client/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class ChatController extends NodeController<AnchorPane> {
public Pane connectingProgressPane;
public VBox noOpenTabsContainer;
public TextField channelNameTextField;
public VBox disconnectedPane;

@Override
protected void onInitialize() {
Expand Down Expand Up @@ -86,7 +87,8 @@ private void onChannelJoined(ChatChannel chatChannel) {

private void onDisconnected() {
fxApplicationThreadExecutor.execute(() -> {
connectingProgressPane.setVisible(true);
disconnectedPane.setVisible(true);
connectingProgressPane.setVisible(false);
tabPane.setVisible(false);
tabPane.getTabs().removeIf(Tab::isClosable);
});
Expand All @@ -95,13 +97,15 @@ private void onDisconnected() {
private void onConnected() {
chatService.getChannels().forEach(this::onChannelJoined);
fxApplicationThreadExecutor.execute(() -> {
disconnectedPane.setVisible(false);
connectingProgressPane.setVisible(false);
tabPane.setVisible(true);
});
}

private void onConnecting() {
fxApplicationThreadExecutor.execute(() -> {
disconnectedPane.setVisible(false);
connectingProgressPane.setVisible(true);
tabPane.setVisible(false);
});
Expand Down Expand Up @@ -167,4 +171,8 @@ public void onJoinChannelButtonClicked() {
chatService.joinChannel(channelName);
channelNameTextField.clear();
}

public void onConnectButtonClicked() {
chatService.connect();
}
}
14 changes: 6 additions & 8 deletions src/main/java/com/faforever/client/chat/KittehChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa
@VisibleForTesting
DefaultClient client;

private boolean autoReconnect;

@Override
public void afterPropertiesSet() {
loginService.loggedInProperty().subscribe(loggedIn -> {
Expand Down Expand Up @@ -541,9 +539,7 @@ private void onDisconnect(ClientConnectionEndedEvent event) {
channels.values().forEach(ChatChannel::clearUsers);
channels.clear();
connectionState.set(ConnectionState.DISCONNECTED);
if (autoReconnect) {
connect();
}
client.shutdown();
}

@Handler
Expand Down Expand Up @@ -579,8 +575,12 @@ private void populateColor(ChatChannelUser chatChannelUser) {

@Override
public void connect() {
if (connectionState.get() != ConnectionState.DISCONNECTED) {
return;
}

connectionState.set(ConnectionState.CONNECTING);
log.info("Connecting to IRC");
autoReconnect = true;
Irc irc = clientProperties.getIrc();
this.defaultChannelName = irc.getDefaultChannel();

Expand Down Expand Up @@ -629,7 +629,6 @@ public void connect() {

@Override
public void disconnect() {
autoReconnect = false;
if (client != null) {
log.info("Disconnecting from IRC");
client.shutdown("Goodbye");
Expand Down Expand Up @@ -731,7 +730,6 @@ public boolean isDefaultChannel(ChatChannel chatChannel) {

@Override
public void destroy() {
autoReconnect = false;
close();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ tutorial.map = Map
tutorial.title = Title
tutorial.length = Length
tutorial.description = Description
chat.connect.message=Connect to chat
chat.connecting.message = Connecting to chat…
updater.binary.taskTitle = Preparing game files
clientUpdateAvailable.notification = Client {0} is available ({1})
Expand Down
13 changes: 11 additions & 2 deletions src/main/resources/theme/chat/chat.fxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.control.Tab?>
Expand All @@ -12,7 +13,7 @@
fx:controller="com.faforever.client.chat.ChatController">
<children>
<TabPane fx:id="tabPane" tabClosingPolicy="ALL_TABS" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" visible="false">
<Tab text="+" closable="false">
<VBox fx:id="noOpenTabsContainer" alignment="CENTER" fillWidth="false">
<children>
Expand All @@ -30,7 +31,7 @@

<VBox fx:id="connectingProgressPane" alignment="CENTER" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" visible="false">
<children>
<ProgressIndicator prefHeight="80.0" prefWidth="80.0"/>
<Label text="%chat.connecting.message">
Expand All @@ -40,5 +41,13 @@
</Label>
</children>
</VBox>

<VBox fx:id="disconnectedPane" alignment="CENTER" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Button text="%chat.connect.message" onAction="#onConnectButtonClicked"/>
</children>
</VBox>
</children>
</AnchorPane>

0 comments on commit a2fae9a

Please sign in to comment.