Merge pull request #6125 from 21pages/reconnect
show reconnect timeout and dismiss all dialog when show reconnecting
This commit is contained in:
		
						commit
						2408758360
					
				| @ -958,7 +958,7 @@ class CustomAlertDialog extends StatelessWidget { | |||||||
| 
 | 
 | ||||||
| void msgBox(SessionID sessionId, String type, String title, String text, | void msgBox(SessionID sessionId, String type, String title, String text, | ||||||
|     String link, OverlayDialogManager dialogManager, |     String link, OverlayDialogManager dialogManager, | ||||||
|     {bool? hasCancel, ReconnectHandle? reconnect}) { |     {bool? hasCancel, ReconnectHandle? reconnect, int? reconnectTimeout}) { | ||||||
|   dialogManager.dismissAll(); |   dialogManager.dismissAll(); | ||||||
|   List<Widget> buttons = []; |   List<Widget> buttons = []; | ||||||
|   bool hasOk = false; |   bool hasOk = false; | ||||||
| @ -998,13 +998,13 @@ void msgBox(SessionID sessionId, String type, String title, String text, | |||||||
|           dialogManager.dismissAll(); |           dialogManager.dismissAll(); | ||||||
|         })); |         })); | ||||||
|   } |   } | ||||||
|   if (reconnect != null && title == "Connection Error") { |   if (reconnect != null && | ||||||
|  |       title == "Connection Error" && | ||||||
|  |       reconnectTimeout != null) { | ||||||
|     // `enabled` is used to disable the dialog button once the button is clicked. |     // `enabled` is used to disable the dialog button once the button is clicked. | ||||||
|     final enabled = true.obs; |     final enabled = true.obs; | ||||||
|     final button = Obx( |     final button = Obx(() => _ReconnectCountDownButton( | ||||||
|       () => dialogButton( |           second: reconnectTimeout, | ||||||
|         'Reconnect', |  | ||||||
|         isOutline: true, |  | ||||||
|           onPressed: enabled.isTrue |           onPressed: enabled.isTrue | ||||||
|               ? () { |               ? () { | ||||||
|                   // Disable the button |                   // Disable the button | ||||||
| @ -1012,8 +1012,7 @@ void msgBox(SessionID sessionId, String type, String title, String text, | |||||||
|                   reconnect(dialogManager, sessionId, false); |                   reconnect(dialogManager, sessionId, false); | ||||||
|                 } |                 } | ||||||
|               : null, |               : null, | ||||||
|       ), |         )); | ||||||
|     ); |  | ||||||
|     buttons.insert(0, button); |     buttons.insert(0, button); | ||||||
|   } |   } | ||||||
|   if (link.isNotEmpty) { |   if (link.isNotEmpty) { | ||||||
| @ -2745,3 +2744,56 @@ parseParamScreenRect(Map<String, dynamic> params) { | |||||||
|   } |   } | ||||||
|   return screenRect; |   return screenRect; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | class _ReconnectCountDownButton extends StatefulWidget { | ||||||
|  |   _ReconnectCountDownButton({ | ||||||
|  |     Key? key, | ||||||
|  |     required this.second, | ||||||
|  |     required this.onPressed, | ||||||
|  |   }) : super(key: key); | ||||||
|  |   final VoidCallback? onPressed; | ||||||
|  |   final int second; | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   State<_ReconnectCountDownButton> createState() => | ||||||
|  |       _ReconnectCountDownButtonState(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class _ReconnectCountDownButtonState extends State<_ReconnectCountDownButton> { | ||||||
|  |   late int _countdownSeconds = widget.second; | ||||||
|  | 
 | ||||||
|  |   Timer? _timer; | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   void initState() { | ||||||
|  |     super.initState(); | ||||||
|  |     _startCountdownTimer(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   void dispose() { | ||||||
|  |     _timer?.cancel(); | ||||||
|  |     super.dispose(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   void _startCountdownTimer() { | ||||||
|  |     _timer = Timer.periodic(Duration(seconds: 1), (timer) { | ||||||
|  |       if (_countdownSeconds <= 0) { | ||||||
|  |         timer.cancel(); | ||||||
|  |       } else { | ||||||
|  |         setState(() { | ||||||
|  |           _countdownSeconds--; | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   Widget build(BuildContext context) { | ||||||
|  |     return dialogButton( | ||||||
|  |       '${translate('Reconnect')} (${_countdownSeconds}s)', | ||||||
|  |       onPressed: widget.onPressed, | ||||||
|  |       isOutline: true, | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | |||||||
| @ -512,7 +512,9 @@ class FfiModel with ChangeNotifier { | |||||||
|       String link, bool hasRetry, OverlayDialogManager dialogManager, |       String link, bool hasRetry, OverlayDialogManager dialogManager, | ||||||
|       {bool? hasCancel}) { |       {bool? hasCancel}) { | ||||||
|     msgBox(sessionId, type, title, text, link, dialogManager, |     msgBox(sessionId, type, title, text, link, dialogManager, | ||||||
|         hasCancel: hasCancel, reconnect: reconnect); |         hasCancel: hasCancel, | ||||||
|  |         reconnect: reconnect, | ||||||
|  |         reconnectTimeout: hasRetry ? _reconnects : null); | ||||||
|     _timer?.cancel(); |     _timer?.cancel(); | ||||||
|     if (hasRetry) { |     if (hasRetry) { | ||||||
|       _timer = Timer(Duration(seconds: _reconnects), () { |       _timer = Timer(Duration(seconds: _reconnects), () { | ||||||
| @ -528,6 +530,7 @@ class FfiModel with ChangeNotifier { | |||||||
|       bool forceRelay) { |       bool forceRelay) { | ||||||
|     bind.sessionReconnect(sessionId: sessionId, forceRelay: forceRelay); |     bind.sessionReconnect(sessionId: sessionId, forceRelay: forceRelay); | ||||||
|     clearPermissions(); |     clearPermissions(); | ||||||
|  |     dialogManager.dismissAll(); | ||||||
|     dialogManager.showLoading(translate('Connecting...'), |     dialogManager.showLoading(translate('Connecting...'), | ||||||
|         onCancel: closeConnection); |         onCancel: closeConnection); | ||||||
|   } |   } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user