From 21cf2a01c74b00a0cad79831113c79706a8f6ede Mon Sep 17 00:00:00 2001 From: 21pages Date: Tue, 8 Aug 2023 17:22:25 +0800 Subject: [PATCH] update idController when create new connection Signed-off-by: 21pages --- flutter/lib/common.dart | 9 +++++++++ flutter/lib/common/formatter/id_formatter.dart | 7 ++++++- flutter/lib/desktop/pages/connection_page.dart | 1 + flutter/lib/mobile/pages/connection_page.dart | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 17206b8ce..231a91800 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -11,6 +11,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_hbb/common/formatter/id_formatter.dart'; import 'package:flutter_hbb/desktop/widgets/refresh_wrapper.dart'; import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart'; import 'package:flutter_hbb/main.dart'; @@ -1833,6 +1834,14 @@ connect( bool isRDP = false, }) async { if (id == '') return; + if (!isDesktop || desktopType == DesktopType.main) { + try { + if (Get.isRegistered()) { + final idController = Get.find(); + idController.text = formatID(id); + } + } catch (_) {} + } id = id.replaceAll(' ', ''); final oldId = id; id = await bind.mainHandleRelayId(id: id); diff --git a/flutter/lib/common/formatter/id_formatter.dart b/flutter/lib/common/formatter/id_formatter.dart index bd7f76666..c2329d53f 100644 --- a/flutter/lib/common/formatter/id_formatter.dart +++ b/flutter/lib/common/formatter/id_formatter.dart @@ -35,6 +35,11 @@ class IDTextInputFormatter extends TextInputFormatter { String formatID(String id) { String id2 = id.replaceAll(' ', ''); + String suffix = ''; + if (id2.endsWith(r'\r') || id2.endsWith(r'/r')) { + suffix = id2.substring(id2.length - 2, id2.length); + id2 = id2.substring(0, id2.length - 2); + } if (int.tryParse(id2) == null) return id; String newID = ''; if (id2.length <= 3) { @@ -47,7 +52,7 @@ String formatID(String id) { newID += " ${id2.substring(i, i + 3)}"; } } - return newID; + return newID + suffix; } String trimID(String id) { diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index 45181c4a3..e24b9c954 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -68,6 +68,7 @@ class _ConnectionPageState extends State _idController.selection = TextSelection( baseOffset: 0, extentOffset: _idController.value.text.length); }); + Get.put(_idController); windowManager.addListener(this); } diff --git a/flutter/lib/mobile/pages/connection_page.dart b/flutter/lib/mobile/pages/connection_page.dart index 48c56e6a5..25812e8c2 100644 --- a/flutter/lib/mobile/pages/connection_page.dart +++ b/flutter/lib/mobile/pages/connection_page.dart @@ -66,6 +66,7 @@ class _ConnectionPageState extends State { _idController.addListener(() { _idEmpty.value = _idController.text.isEmpty; }); + Get.put(_idController); } @override