mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-20 03:01:52 +08:00
[fix] show truthful signaling recovery state and pin safe retries
This commit is contained in:
@@ -74,10 +74,6 @@ namespace {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Median reconnect to the signal server lands around 7 s on a lossy path, so a
|
||||
// drop shorter than this is almost always already being recovered from.
|
||||
constexpr auto kSignalOfflineGrace = 10s;
|
||||
|
||||
std::optional<std::string> GenerateRandomPassword(std::string_view current) {
|
||||
constexpr std::string_view alphabet =
|
||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
@@ -1890,6 +1886,7 @@ void GuiApplication::Tick() {
|
||||
HandlePasswordChangeResult();
|
||||
HandleCredentialRecovery();
|
||||
if (!peer_) {
|
||||
signal_connection_indicator_.Reset();
|
||||
CreateConnectionPeer();
|
||||
}
|
||||
#ifdef __linux__
|
||||
@@ -2482,20 +2479,9 @@ void GuiApplication::SyncMainWindow() {
|
||||
ui_->main->set_password_change_pending(password_change_pending_);
|
||||
}
|
||||
const bool signal_online = signal_connected_.load();
|
||||
if (signal_online) {
|
||||
signal_lost_at_valid_ = false;
|
||||
} else if (!signal_lost_at_valid_) {
|
||||
signal_lost_at_ = std::chrono::steady_clock::now();
|
||||
signal_lost_at_valid_ = true;
|
||||
}
|
||||
// Reconnects routinely take several seconds on a lossy path; only report
|
||||
// offline once the connection has stayed down long enough to be a real
|
||||
// outage rather than a blip the reconnect is already recovering from.
|
||||
const bool signal_offline =
|
||||
!signal_online && signal_lost_at_valid_ &&
|
||||
std::chrono::steady_clock::now() - signal_lost_at_ >
|
||||
kSignalOfflineGrace;
|
||||
ui_->main->set_signal_connected(!signal_offline);
|
||||
ui_->main->set_signal_connected(signal_online);
|
||||
ui_->main->set_signal_reconnecting(
|
||||
signal_connection_indicator_.Update(signal_online));
|
||||
ui_->main->set_signal_tls_error(signal_status_ ==
|
||||
SignalStatus::SignalTlsCertError);
|
||||
ui_->main->set_update_available(update_available_);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <remote_action.h>
|
||||
|
||||
#include "application/signal_connection_indicator.h"
|
||||
#include "runtime/cursor_state_provider.h"
|
||||
#include "runtime/gui_runtime.h"
|
||||
|
||||
@@ -106,11 +107,7 @@ private:
|
||||
cursor_delivery_states_;
|
||||
uint32_t cursor_state_sequence_ = 0;
|
||||
std::chrono::steady_clock::time_point next_video_frame_time_{};
|
||||
// The signal server is reached over a lossy path that routinely drops for the
|
||||
// few seconds a reconnect takes, so the main window holds its "connected"
|
||||
// indication through a brief blip instead of flickering offline.
|
||||
std::chrono::steady_clock::time_point signal_lost_at_{};
|
||||
bool signal_lost_at_valid_ = false;
|
||||
SignalConnectionIndicator signal_connection_indicator_;
|
||||
#if defined(__linux__) && !defined(__APPLE__)
|
||||
bool use_xwayland_gui_ = false;
|
||||
bool use_x11_custom_titlebar_ = false;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef CROSSDESK_SIGNAL_CONNECTION_INDICATOR_H_
|
||||
#define CROSSDESK_SIGNAL_CONNECTION_INDICATOR_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
namespace crossdesk {
|
||||
|
||||
// Presentation state only. The actual connected flag remains authoritative
|
||||
// for actions and other UI consumers, including the announcement inbox.
|
||||
class SignalConnectionIndicator {
|
||||
public:
|
||||
using Clock = std::chrono::steady_clock;
|
||||
|
||||
bool Update(bool connected, Clock::time_point now = Clock::now()) {
|
||||
if (connected) {
|
||||
disconnected_at_.reset();
|
||||
} else if (was_connected_) {
|
||||
disconnected_at_ = now;
|
||||
}
|
||||
was_connected_ = connected;
|
||||
return disconnected_at_ &&
|
||||
now - *disconnected_at_ < std::chrono::seconds(10);
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
was_connected_ = false;
|
||||
disconnected_at_.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
bool was_connected_ = false;
|
||||
std::optional<Clock::time_point> disconnected_at_;
|
||||
};
|
||||
|
||||
} // namespace crossdesk
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user