💄 Better ws reconnect experience

This commit is contained in:
2025-12-24 22:33:28 +08:00
parent 78a3cd6dd2
commit 1716afd66c
2 changed files with 9 additions and 10 deletions

View File

@@ -156,6 +156,7 @@ class WebSocketService {
} }
void manualReconnect() { void manualReconnect() {
_statusStreamController.sink.add(WebSocketState.connecting());
talker.info('[WebSocket] Manual reconnect triggered by user'); talker.info('[WebSocket] Manual reconnect triggered by user');
_reconnectTimer?.cancel(); _reconnectTimer?.cancel();
_reconnectTimer = Timer(const Duration(milliseconds: 500), () { _reconnectTimer = Timer(const Duration(milliseconds: 500), () {

View File

@@ -531,7 +531,7 @@ class _WebSocketIndicator extends HookConsumerWidget {
Color indicatorColor; Color indicatorColor;
String indicatorText; String indicatorText;
Widget indicatorIcon; Widget indicatorIcon;
bool isInteractive = false; bool isInteractive = true;
double opacity = 0.0; double opacity = 0.0;
if (websocketState == WebSocketState.connected()) { if (websocketState == WebSocketState.connected()) {
@@ -544,6 +544,7 @@ class _WebSocketIndicator extends HookConsumerWidget {
size: 16, size: 16,
); );
opacity = 0.0; opacity = 0.0;
isInteractive = false;
} else if (websocketState == WebSocketState.connecting()) { } else if (websocketState == WebSocketState.connecting()) {
indicatorColor = Colors.teal; indicatorColor = Colors.teal;
indicatorText = 'connectionReconnecting'; indicatorText = 'connectionReconnecting';
@@ -558,6 +559,7 @@ class _WebSocketIndicator extends HookConsumerWidget {
), ),
); );
opacity = 1.0; opacity = 1.0;
isInteractive = false;
} else if (websocketState == WebSocketState.serverDown()) { } else if (websocketState == WebSocketState.serverDown()) {
indicatorColor = Colors.red; indicatorColor = Colors.red;
indicatorText = 'connectionServerDown'; indicatorText = 'connectionServerDown';
@@ -579,6 +581,7 @@ class _WebSocketIndicator extends HookConsumerWidget {
size: 16, size: 16,
); );
opacity = 1.0; opacity = 1.0;
isInteractive = false;
} }
return Positioned( return Positioned(
@@ -599,15 +602,10 @@ class _WebSocketIndicator extends HookConsumerWidget {
? 0 ? 0
: 4, : 4,
borderRadius: BorderRadius.circular(999), borderRadius: BorderRadius.circular(999),
child: InkWell( child: GestureDetector(
onTap: isInteractive onTap: () {
? () { ref.read(websocketStateProvider.notifier).manualReconnect();
ref },
.read(websocketStateProvider.notifier)
.manualReconnect();
}
: null,
borderRadius: BorderRadius.circular(999),
child: Container( child: Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration( decoration: BoxDecoration(