From a7163c6a04e794744d20ecff6ccf5a74f89edf48 Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 18 Aug 2023 15:49:15 +0800 Subject: [PATCH 1/2] when connecting with ab, if recent peer's alias is empty, set it to ab's alias Signed-off-by: 21pages --- flutter/lib/common/widgets/peer_card.dart | 42 ++++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/flutter/lib/common/widgets/peer_card.dart b/flutter/lib/common/widgets/peer_card.dart index 31116b0dd..71b63d975 100644 --- a/flutter/lib/common/widgets/peer_card.dart +++ b/flutter/lib/common/widgets/peer_card.dart @@ -27,11 +27,13 @@ final peerCardUiType = PeerUiType.grid.obs; class _PeerCard extends StatefulWidget { final Peer peer; + final PeerTabIndex tab; final Function(BuildContext, String) connect; final PopupMenuEntryBuilder popupMenuEntryBuilder; const _PeerCard( {required this.peer, + required this.tab, required this.connect, required this.popupMenuEntryBuilder, Key? key}) @@ -71,10 +73,14 @@ class _PeerCardState extends State<_PeerCard> if (peerTabModel.multiSelectionMode) { peerTabModel.select(peer); } else { - if (!isWebDesktop) connect(context, peer.id); + if (!isWebDesktop) { + connectInPeerTab(context, peer.id, widget.tab); + } } }, - onDoubleTap: isWebDesktop ? () => connect(context, peer.id) : null, + onDoubleTap: isWebDesktop + ? () => connectInPeerTab(context, peer.id, widget.tab) + : null, onLongPress: () { peerTabModel.select(peer); }, @@ -443,7 +449,9 @@ abstract class BasePeerCard extends StatelessWidget { Widget build(BuildContext context) { return _PeerCard( peer: peer, - connect: (BuildContext context, String id) => connect(context, id), + tab: tab, + connect: (BuildContext context, String id) => + connectInPeerTab(context, id, tab), popupMenuEntryBuilder: _buildPopupMenuEntry, ); } @@ -477,9 +485,10 @@ abstract class BasePeerCard extends StatelessWidget { style: style, ), proc: () { - connect( + connectInPeerTab( context, peer.id, + tab, isFileTransfer: isFileTransfer, isTcpTunneling: isTcpTunneling, isRDP: isRDP, @@ -552,7 +561,7 @@ abstract class BasePeerCard extends StatelessWidget { ], )), proc: () { - connect(context, id, isRDP: true); + connectInPeerTab(context, id, tab, isRDP: true); }, padding: menuPadding, dismissOnClicked: true, @@ -1309,3 +1318,26 @@ class TagPainter extends CustomPainter { return true; } } + +void connectInPeerTab(BuildContext context, String id, PeerTabIndex tab, + {bool isFileTransfer = false, + bool isTcpTunneling = false, + bool isRDP = false}) async { + if (tab == PeerTabIndex.ab) { + // If recent peer's alias is empty, set it to ab's alias + // Because the platform is not set, it may not take effect, but it is more important not to display if the connection is not successful + Peer? p = gFFI.abModel.find(id); + if (p != null && + p.alias.isNotEmpty && + (await bind.mainGetPeerOption(id: id, key: "alias")).isEmpty) { + await bind.mainSetPeerAlias( + id: id, + alias: p.alias, + ); + } + } + connect(context, id, + isFileTransfer: isFileTransfer, + isTcpTunneling: isTcpTunneling, + isRDP: isRDP); +} From 979203cbdb0a0c1c1800321d492a96d432f22777 Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 18 Aug 2023 16:13:24 +0800 Subject: [PATCH 2/2] replace offstage with if-else for LinearProgressIndicator in dialog Signed-off-by: 21pages --- flutter/lib/common/widgets/address_book.dart | 9 +++-- flutter/lib/common/widgets/dialog.dart | 18 ++++----- flutter/lib/common/widgets/login.dart | 23 +++++++---- flutter/lib/common/widgets/peer_tab_page.dart | 40 +++++++++---------- .../desktop/pages/desktop_setting_page.dart | 6 +-- flutter/lib/desktop/pages/install_page.dart | 13 +++--- flutter/lib/mobile/widgets/dialog.dart | 5 +-- 7 files changed, 59 insertions(+), 55 deletions(-) diff --git a/flutter/lib/common/widgets/address_book.dart b/flutter/lib/common/widgets/address_book.dart index 4aa1326bf..86a5b2c55 100644 --- a/flutter/lib/common/widgets/address_book.dart +++ b/flutter/lib/common/widgets/address_book.dart @@ -46,6 +46,7 @@ class _AddressBookState extends State { } return Column( children: [ + // NOT use Offstage to wrap LinearProgressIndicator if (gFFI.abModel.retrying.value) LinearProgressIndicator(), _buildErrorBanner( err: gFFI.abModel.pullError, @@ -397,8 +398,8 @@ class _AddressBookState extends State { const SizedBox( height: 4.0, ), - Offstage( - offstage: !isInProgress, child: const LinearProgressIndicator()) + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), ], ), actions: [ @@ -463,8 +464,8 @@ class _AddressBookState extends State { const SizedBox( height: 4.0, ), - Offstage( - offstage: !isInProgress, child: const LinearProgressIndicator()) + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), ], ), actions: [ diff --git a/flutter/lib/common/widgets/dialog.dart b/flutter/lib/common/widgets/dialog.dart index 40f0901aa..ce4b68ae0 100644 --- a/flutter/lib/common/widgets/dialog.dart +++ b/flutter/lib/common/widgets/dialog.dart @@ -156,8 +156,8 @@ void changeIdDialog() { }).toList(), )).marginOnly(bottom: 8) : SizedBox.shrink(), - Offstage( - offstage: !isInProgress, child: const LinearProgressIndicator()) + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), ], ), actions: [ @@ -202,8 +202,8 @@ void changeWhiteList({Function()? callback}) async { const SizedBox( height: 4.0, ), - Offstage( - offstage: !isInProgress, child: const LinearProgressIndicator()) + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), ], ), actions: [ @@ -1435,8 +1435,8 @@ void editAbTagDialog( .toList(growable: false), ), ), - Offstage( - offstage: !isInProgress, child: const LinearProgressIndicator()) + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), ], ), actions: [ @@ -1496,9 +1496,9 @@ void renameDialog( ), ), ), - Obx(() => Offstage( - offstage: isInProgress.isFalse, - child: const LinearProgressIndicator())), + // NOT use Offstage to wrap LinearProgressIndicator + Obx(() => + isInProgress.value ? const LinearProgressIndicator() : Offstage()) ], ), actions: [ diff --git a/flutter/lib/common/widgets/login.dart b/flutter/lib/common/widgets/login.dart index d7037e58f..7c17e9dea 100644 --- a/flutter/lib/common/widgets/login.dart +++ b/flutter/lib/common/widgets/login.dart @@ -12,7 +12,15 @@ import 'package:url_launcher/url_launcher.dart'; import '../../common.dart'; import './dialog.dart'; -const kOpSvgList = ['github', 'google', 'apple', 'okta', 'facebook', 'azure', 'auth0']; +const kOpSvgList = [ + 'github', + 'google', + 'apple', + 'okta', + 'facebook', + 'azure', + 'auth0' +]; class _IconOP extends StatelessWidget { final String op; @@ -27,7 +35,8 @@ class _IconOP extends StatelessWidget { @override Widget build(BuildContext context) { - final svgFile = kOpSvgList.contains(op.toLowerCase()) ? op.toLowerCase() : 'default'; + final svgFile = + kOpSvgList.contains(op.toLowerCase()) ? op.toLowerCase() : 'default'; return Container( margin: margin, child: icon == null @@ -345,9 +354,8 @@ class LoginWidgetUserPass extends StatelessWidget { autoFocus: false, errorText: passMsg, ), - Offstage( - offstage: !isInProgress, - child: const LinearProgressIndicator()), + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), const SizedBox(height: 12.0), FittedBox( child: @@ -664,9 +672,8 @@ Future verificationCodeDialog(UserPayload? user) async { }, ), */ - Offstage( - offstage: !isInProgress, - child: const LinearProgressIndicator()), + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), ], ), onCancel: close, diff --git a/flutter/lib/common/widgets/peer_tab_page.dart b/flutter/lib/common/widgets/peer_tab_page.dart index c05eb6243..b4c9b4018 100644 --- a/flutter/lib/common/widgets/peer_tab_page.dart +++ b/flutter/lib/common/widgets/peer_tab_page.dart @@ -208,28 +208,26 @@ class _PeerTabPageState extends State } Widget _createRefresh() { + if (gFFI.peerTabModel.currentTab < 3) return Offstage(); final textColor = Theme.of(context).textTheme.titleLarge?.color; - return Offstage( - offstage: gFFI.peerTabModel.currentTab < 3, // local tab can't see effect - child: Container( - padding: EdgeInsets.all(4.0), - child: AnimatedRotationWidget( - onPressed: () { - if (gFFI.peerTabModel.currentTab < entries.length) { - entries[gFFI.peerTabModel.currentTab].load(); - } - }, - spinning: gFFI.abModel.abLoading, - child: RotatedBox( - quarterTurns: 2, - child: Tooltip( - message: translate('Refresh'), - child: Icon( - Icons.refresh, - size: 18, - color: textColor, - )))), - ), + return Container( + padding: EdgeInsets.all(4.0), + child: AnimatedRotationWidget( + onPressed: () { + if (gFFI.peerTabModel.currentTab < entries.length) { + entries[gFFI.peerTabModel.currentTab].load(); + } + }, + spinning: gFFI.abModel.abLoading, + child: RotatedBox( + quarterTurns: 2, + child: Tooltip( + message: translate('Refresh'), + child: Icon( + Icons.refresh, + size: 18, + color: textColor, + )))), ); } diff --git a/flutter/lib/desktop/pages/desktop_setting_page.dart b/flutter/lib/desktop/pages/desktop_setting_page.dart index b868042a4..f158efb82 100644 --- a/flutter/lib/desktop/pages/desktop_setting_page.dart +++ b/flutter/lib/desktop/pages/desktop_setting_page.dart @@ -2065,9 +2065,9 @@ void changeSocks5Proxy() async { ), ], ), - Offstage( - offstage: !isInProgress, - child: const LinearProgressIndicator().marginOnly(top: 8)) + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) + const LinearProgressIndicator().marginOnly(top: 8), ], ), ), diff --git a/flutter/lib/desktop/pages/install_page.dart b/flutter/lib/desktop/pages/install_page.dart index 871030e15..44ba06263 100644 --- a/flutter/lib/desktop/pages/install_page.dart +++ b/flutter/lib/desktop/pages/install_page.dart @@ -182,8 +182,8 @@ class _InstallPageBodyState extends State<_InstallPageBody> .marginOnly(bottom: em), InkWell( hoverColor: Colors.transparent, - onTap: () => - launchUrlString('https://rustdesk.com/privacy.html'), + onTap: () => launchUrlString( + 'https://rustdesk.com/privacy.html'), child: Tooltip( message: 'https://rustdesk.com/privacy.html', child: Row(children: [ @@ -204,11 +204,10 @@ class _InstallPageBodyState extends State<_InstallPageBody> Row( children: [ Expanded( - child: Obx(() => Offstage( - offstage: !showProgress.value, - child: - LinearProgressIndicator().marginOnly(right: 10), - )), + // NOT use Offstage to wrap LinearProgressIndicator + child: Obx(() => showProgress.value + ? LinearProgressIndicator().marginOnly(right: 10) + : Offstage()), ), Obx( () => OutlinedButton.icon( diff --git a/flutter/lib/mobile/widgets/dialog.dart b/flutter/lib/mobile/widgets/dialog.dart index 8c321e785..550b37d72 100644 --- a/flutter/lib/mobile/widgets/dialog.dart +++ b/flutter/lib/mobile/widgets/dialog.dart @@ -223,9 +223,8 @@ void showServerSettingsWithValue( labelText: 'Key', ), ), - Offstage( - offstage: !isInProgress, - child: LinearProgressIndicator()) + // NOT use Offstage to wrap LinearProgressIndicator + if (isInProgress) const LinearProgressIndicator(), ])), actions: [ dialogButton('Cancel', onPressed: () {