Merge pull request #3232 from 21pages/reconnect_btn

add reconnect button on Connection Error
This commit is contained in:
RustDesk
2023-02-16 15:28:15 +08:00
committed by GitHub
35 changed files with 102 additions and 56 deletions

View File

@@ -632,6 +632,7 @@ class CustomAlertDialog extends StatelessWidget {
if (!scopeNode.hasFocus) scopeNode.requestFocus();
});
const double padding = 16;
bool tabTapped = false;
return FocusScope(
node: scopeNode,
autofocus: true,
@@ -641,13 +642,15 @@ class CustomAlertDialog extends StatelessWidget {
onCancel?.call();
}
return KeyEventResult.handled; // avoid TextField exception on escape
} else if (onSubmit != null &&
} else if (!tabTapped &&
onSubmit != null &&
key.logicalKey == LogicalKeyboardKey.enter) {
if (key is RawKeyDownEvent) onSubmit?.call();
return KeyEventResult.handled;
} else if (key.logicalKey == LogicalKeyboardKey.tab) {
if (key is RawKeyDownEvent) {
scopeNode.nextFocus();
tabTapped = true;
}
return KeyEventResult.handled;
}
@@ -676,7 +679,7 @@ class CustomAlertDialog extends StatelessWidget {
void msgBox(String id, String type, String title, String text, String link,
OverlayDialogManager dialogManager,
{bool? hasCancel}) {
{bool? hasCancel, ReconnectHandle? reconnect}) {
dialogManager.dismissAll();
List<Widget> buttons = [];
bool hasOk = false;
@@ -716,6 +719,13 @@ void msgBox(String id, String type, String title, String text, String link,
dialogManager.dismissAll();
}));
}
if (reconnect != null && title == "Connection Error") {
buttons.insert(
0,
dialogButton('Reconnect', isOutline: true, onPressed: () {
reconnect(dialogManager, id, false);
}));
}
if (link.isNotEmpty) {
buttons.insert(0, dialogButton('JumpLink', onPressed: jumplink));
}

View File

@@ -33,6 +33,7 @@ import 'input_model.dart';
import 'platform_model.dart';
typedef HandleMsgBox = Function(Map<String, dynamic> evt, String id);
typedef ReconnectHandle = Function(OverlayDialogManager, String, bool);
final _waitForImage = <String, bool>{};
class FfiModel with ChangeNotifier {
@@ -310,14 +311,12 @@ class FfiModel with ChangeNotifier {
showMsgBox(String id, String type, String title, String text, String link,
bool hasRetry, OverlayDialogManager dialogManager,
{bool? hasCancel}) {
msgBox(id, type, title, text, link, dialogManager, hasCancel: hasCancel);
msgBox(id, type, title, text, link, dialogManager,
hasCancel: hasCancel, reconnect: reconnect);
_timer?.cancel();
if (hasRetry) {
_timer = Timer(Duration(seconds: _reconnects), () {
bind.sessionReconnect(id: id, forceRelay: false);
clearPermissions();
dialogManager.showLoading(translate('Connecting...'),
onCancel: closeConnection);
reconnect(dialogManager, id, false);
});
_reconnects *= 2;
} else {
@@ -325,6 +324,14 @@ class FfiModel with ChangeNotifier {
}
}
void reconnect(
OverlayDialogManager dialogManager, String id, bool forceRelay) {
bind.sessionReconnect(id: id, forceRelay: forceRelay);
clearPermissions();
dialogManager.showLoading(translate('Connecting...'),
onCancel: closeConnection);
}
void showRelayHintDialog(String id, String type, String title, String text,
OverlayDialogManager dialogManager) {
dialogManager.show(tag: '$id-$type', (setState, close) {
@@ -333,13 +340,6 @@ class FfiModel with ChangeNotifier {
close();
}
reconnect(bool forceRelay) {
bind.sessionReconnect(id: id, forceRelay: forceRelay);
clearPermissions();
dialogManager.showLoading(translate('Connecting...'),
onCancel: closeConnection);
}
final style =
ElevatedButton.styleFrom(backgroundColor: Colors.green[700]);
return CustomAlertDialog(
@@ -348,14 +348,16 @@ class FfiModel with ChangeNotifier {
"${translate(text)}\n\n${translate('relay_hint_tip')}"),
actions: [
dialogButton('Close', onPressed: onClose, isOutline: true),
dialogButton('Retry', onPressed: () => reconnect(false)),
dialogButton('Retry',
onPressed: () => reconnect(dialogManager, id, false)),
dialogButton('Connect via relay',
onPressed: () => reconnect(true), buttonStyle: style),
onPressed: () => reconnect(dialogManager, id, true),
buttonStyle: style),
dialogButton('Always connect via relay', onPressed: () {
const option = 'force-always-relay';
bind.sessionPeerOption(
id: id, name: option, value: bool2option(option, true));
reconnect(true);
reconnect(dialogManager, id, true);
}, buttonStyle: style),
],
onCancel: onClose,