Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const UI = {
inhibitReconnect: true,
reconnectCallback: null,
reconnectPassword: null,
firstReconnectTime: null,

async start(options={}) {
UI.customSettings = options.settings || {};
Expand Down Expand Up @@ -961,6 +962,9 @@ const UI = {
UI.closePowerPanel();
}
},
resetFirstReconnection() {
UI.firstReconnectTime = null;
},

/* ------^-------
* /POWER
Expand Down Expand Up @@ -1121,6 +1125,23 @@ const UI = {

reconnect() {
UI.reconnectCallback = null;
const MAX_RECONNECT_TIME_SECONDS = 10 * 60; // 10 * 60s
const MAX_TIME_IN_MS = MAX_RECONNECT_TIME_SECONDS * 1000;

// Initialize first reconnect time if it's the first attempt
if (UI.firstReconnectTime === null) {
Comment thread
Ankit8969 marked this conversation as resolved.
UI.firstReconnectTime = Date.now();
}

// Check if we've exceeded the max reconnect time
if ((Date.now() - UI.firstReconnectTime) >= MAX_TIME_IN_MS) {
// hiding the previous status message
UI.hideStatus();
// Showing this message for long time, because if the connection is unstable and user is not around to see the message when the connection is lost, they will be able to see it when they will come back. (Showing for 3 hours)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the rest of the file avoids long lines like this one.

UI.showStatus(_("Maximum reconnect attempts reached. Failed to connect to the server."), 'error', 180 * 60 * 1000);
UI.updateVisualState('disconnected');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be UI.cancelReconnect() to avoid ending up in a broken state after reaching the maximum reconnect attempts.

return;
}

// if reconnect has been disabled in the meantime, do nothing.
if (UI.inhibitReconnect) {
Expand Down Expand Up @@ -1154,6 +1175,7 @@ const UI = {
}
UI.showStatus(msg);
UI.updateVisualState('connected');
UI.resetFirstReconnection();

UI.updateBeforeUnload();

Expand Down
2 changes: 1 addition & 1 deletion defaults.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
Loading