2022-07-29 16:47:24 +08:00
|
|
|
import 'package:contextmenu/contextmenu.dart';
|
2022-07-27 22:56:28 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-26 11:35:28 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2022-07-27 22:56:28 +08:00
|
|
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
import '../../common.dart';
|
|
|
|
import '../../models/model.dart';
|
|
|
|
import '../../models/peer_model.dart';
|
2022-08-23 17:21:50 +08:00
|
|
|
import '../../models/platform_model.dart';
|
2022-07-27 22:56:28 +08:00
|
|
|
|
2022-07-28 14:06:02 +08:00
|
|
|
typedef PopupMenuItemsFunc = Future<List<PopupMenuItem<String>>> Function();
|
2022-08-03 22:03:31 +08:00
|
|
|
|
2022-07-29 12:03:24 +08:00
|
|
|
enum PeerType { recent, fav, discovered, ab }
|
2022-07-28 14:06:02 +08:00
|
|
|
|
2022-08-23 17:21:50 +08:00
|
|
|
enum PeerUiType { grid, list }
|
|
|
|
|
|
|
|
final peerCardUiType = PeerUiType.grid.obs;
|
|
|
|
|
2022-07-27 22:56:28 +08:00
|
|
|
class _PeerCard extends StatefulWidget {
|
|
|
|
final Peer peer;
|
2022-07-28 14:06:02 +08:00
|
|
|
final PopupMenuItemsFunc popupMenuItemsFunc;
|
2022-07-29 12:03:24 +08:00
|
|
|
final PeerType type;
|
2022-07-27 22:56:28 +08:00
|
|
|
|
2022-08-03 22:03:31 +08:00
|
|
|
_PeerCard(
|
|
|
|
{required this.peer,
|
|
|
|
required this.popupMenuItemsFunc,
|
|
|
|
Key? key,
|
|
|
|
required this.type})
|
2022-07-27 22:56:28 +08:00
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PeerCardState createState() => _PeerCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// State for the connection page.
|
2022-07-29 16:47:24 +08:00
|
|
|
class _PeerCardState extends State<_PeerCard>
|
|
|
|
with AutomaticKeepAliveClientMixin {
|
2022-08-26 13:02:15 +08:00
|
|
|
var _menuPos = RelativeRect.fill;
|
2022-08-24 11:01:58 +08:00
|
|
|
final double _cardRadis = 20;
|
|
|
|
final double _borderWidth = 2;
|
2022-08-26 13:02:15 +08:00
|
|
|
final RxBool _iconMoreHover = false.obs;
|
2022-07-27 22:56:28 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-07-29 16:47:24 +08:00
|
|
|
super.build(context);
|
2022-07-27 22:56:28 +08:00
|
|
|
final peer = super.widget.peer;
|
|
|
|
var deco = Rx<BoxDecoration?>(BoxDecoration(
|
2022-08-24 11:01:58 +08:00
|
|
|
border: Border.all(color: Colors.transparent, width: _borderWidth),
|
2022-08-23 17:21:50 +08:00
|
|
|
borderRadius: peerCardUiType.value == PeerUiType.grid
|
2022-08-24 11:01:58 +08:00
|
|
|
? BorderRadius.circular(_cardRadis)
|
2022-08-23 17:21:50 +08:00
|
|
|
: null));
|
|
|
|
return MouseRegion(
|
|
|
|
onEnter: (evt) {
|
|
|
|
deco.value = BoxDecoration(
|
2022-08-24 11:01:58 +08:00
|
|
|
border: Border.all(color: MyTheme.button, width: _borderWidth),
|
2022-08-23 17:21:50 +08:00
|
|
|
borderRadius: peerCardUiType.value == PeerUiType.grid
|
2022-08-24 11:01:58 +08:00
|
|
|
? BorderRadius.circular(_cardRadis)
|
2022-08-23 17:21:50 +08:00
|
|
|
: null);
|
|
|
|
},
|
|
|
|
onExit: (evt) {
|
|
|
|
deco.value = BoxDecoration(
|
2022-08-24 11:01:58 +08:00
|
|
|
border: Border.all(color: Colors.transparent, width: _borderWidth),
|
2022-08-23 17:21:50 +08:00
|
|
|
borderRadius: peerCardUiType.value == PeerUiType.grid
|
2022-08-24 11:01:58 +08:00
|
|
|
? BorderRadius.circular(_cardRadis)
|
2022-08-23 17:21:50 +08:00
|
|
|
: null);
|
|
|
|
},
|
|
|
|
child: GestureDetector(
|
2022-08-26 13:02:15 +08:00
|
|
|
onDoubleTap: () => _connect(peer.id),
|
2022-08-23 17:21:50 +08:00
|
|
|
child: Obx(() => peerCardUiType.value == PeerUiType.grid
|
|
|
|
? _buildPeerCard(context, peer, deco)
|
|
|
|
: _buildPeerTile(context, peer, deco))),
|
|
|
|
);
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
|
2022-08-03 22:03:31 +08:00
|
|
|
Widget _buildPeerTile(
|
|
|
|
BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
|
2022-08-24 11:01:58 +08:00
|
|
|
final greyStyle =
|
|
|
|
TextStyle(fontSize: 12, color: MyTheme.color(context).lighterText);
|
2022-07-27 22:56:28 +08:00
|
|
|
return Obx(
|
2022-08-03 22:03:31 +08:00
|
|
|
() => Container(
|
2022-08-24 11:01:58 +08:00
|
|
|
foregroundDecoration: deco.value,
|
2022-08-23 17:21:50 +08:00
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
2022-07-27 22:56:28 +08:00
|
|
|
children: [
|
2022-08-23 17:21:50 +08:00
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: str2color('${peer.id}${peer.platform}', 0x7f),
|
|
|
|
),
|
|
|
|
alignment: Alignment.center,
|
2022-08-24 11:01:58 +08:00
|
|
|
child: _getPlatformImage('${peer.platform}', 30).paddingAll(6),
|
2022-08-23 17:21:50 +08:00
|
|
|
),
|
2022-07-27 22:56:28 +08:00
|
|
|
Expanded(
|
|
|
|
child: Container(
|
2022-08-24 11:01:58 +08:00
|
|
|
decoration: BoxDecoration(color: MyTheme.color(context).bg),
|
2022-07-27 22:56:28 +08:00
|
|
|
child: Row(
|
2022-08-23 17:21:50 +08:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2022-07-27 22:56:28 +08:00
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
2022-08-23 17:21:50 +08:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
2022-07-27 22:56:28 +08:00
|
|
|
children: [
|
2022-08-23 17:21:50 +08:00
|
|
|
Row(children: [
|
|
|
|
Padding(
|
2022-08-24 11:01:58 +08:00
|
|
|
padding: EdgeInsets.fromLTRB(0, 4, 4, 4),
|
2022-08-23 17:21:50 +08:00
|
|
|
child: CircleAvatar(
|
|
|
|
radius: 5,
|
|
|
|
backgroundColor: peer.online
|
|
|
|
? Colors.green
|
|
|
|
: Colors.yellow)),
|
2022-08-24 11:01:58 +08:00
|
|
|
Text(
|
|
|
|
'${peer.id}',
|
|
|
|
style: TextStyle(fontWeight: FontWeight.w400),
|
|
|
|
),
|
2022-08-23 17:21:50 +08:00
|
|
|
]),
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: FutureBuilder<String>(
|
|
|
|
future: bind.mainGetPeerOption(
|
|
|
|
id: peer.id, key: 'alias'),
|
|
|
|
builder: (_, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
final name = snapshot.data!.isEmpty
|
|
|
|
? '${peer.username}@${peer.hostname}'
|
|
|
|
: snapshot.data!;
|
|
|
|
return Tooltip(
|
|
|
|
message: name,
|
2022-08-24 11:01:58 +08:00
|
|
|
waitDuration: Duration(seconds: 1),
|
2022-08-23 17:21:50 +08:00
|
|
|
child: Text(
|
|
|
|
name,
|
|
|
|
style: greyStyle,
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// alias has not arrived
|
|
|
|
return Text(
|
|
|
|
'${peer.username}@${peer.hostname}',
|
|
|
|
style: greyStyle,
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-07-27 22:56:28 +08:00
|
|
|
),
|
|
|
|
],
|
2022-08-23 17:21:50 +08:00
|
|
|
),
|
2022-07-27 22:56:28 +08:00
|
|
|
),
|
2022-08-26 13:02:15 +08:00
|
|
|
_actionMore(peer),
|
2022-07-27 22:56:28 +08:00
|
|
|
],
|
2022-08-24 11:01:58 +08:00
|
|
|
).paddingSymmetric(horizontal: 4.0),
|
2022-07-27 22:56:28 +08:00
|
|
|
),
|
2022-08-23 17:21:50 +08:00
|
|
|
)
|
2022-07-27 22:56:28 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-23 17:21:50 +08:00
|
|
|
Widget _buildPeerCard(
|
|
|
|
BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
|
|
|
|
return Card(
|
2022-08-24 11:01:58 +08:00
|
|
|
color: Colors.transparent,
|
|
|
|
elevation: 0,
|
|
|
|
margin: EdgeInsets.zero,
|
2022-08-24 14:57:41 +08:00
|
|
|
child: Obx(
|
|
|
|
() => Container(
|
2022-08-24 11:01:58 +08:00
|
|
|
foregroundDecoration: deco.value,
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(_cardRadis - _borderWidth),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
2022-08-24 14:57:41 +08:00
|
|
|
color: str2color('${peer.id}${peer.platform}', 0x7f),
|
2022-08-24 11:01:58 +08:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.all(6),
|
|
|
|
child:
|
|
|
|
_getPlatformImage('${peer.platform}', 60),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder<String>(
|
|
|
|
future: bind.mainGetPeerOption(
|
|
|
|
id: peer.id, key: 'alias'),
|
|
|
|
builder: (_, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
final name = snapshot.data!.isEmpty
|
|
|
|
? '${peer.username}@${peer.hostname}'
|
|
|
|
: snapshot.data!;
|
|
|
|
return Tooltip(
|
|
|
|
message: name,
|
|
|
|
waitDuration: Duration(seconds: 1),
|
|
|
|
child: Text(
|
|
|
|
name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white70,
|
|
|
|
fontSize: 12),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// alias has not arrived
|
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
'${peer.username}@${peer.hostname}',
|
2022-08-24 14:57:41 +08:00
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white70,
|
|
|
|
fontSize: 12),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
2022-08-24 11:01:58 +08:00
|
|
|
));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2022-08-24 14:57:41 +08:00
|
|
|
),
|
2022-08-24 11:01:58 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).paddingAll(4.0),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-08-24 14:57:41 +08:00
|
|
|
),
|
|
|
|
),
|
2022-08-24 11:01:58 +08:00
|
|
|
Container(
|
|
|
|
color: MyTheme.color(context).bg,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Row(children: [
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0, 4, 8, 4),
|
|
|
|
child: CircleAvatar(
|
|
|
|
radius: 5,
|
|
|
|
backgroundColor: peer.online
|
|
|
|
? Colors.green
|
|
|
|
: Colors.yellow)),
|
|
|
|
Text('${peer.id}')
|
2022-08-26 13:02:15 +08:00
|
|
|
]).paddingSymmetric(vertical: 8),
|
|
|
|
_actionMore(peer),
|
2022-08-24 11:01:58 +08:00
|
|
|
],
|
2022-08-26 13:02:15 +08:00
|
|
|
).paddingSymmetric(horizontal: 12.0),
|
2022-08-24 11:01:58 +08:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-08-24 14:57:41 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-08-23 17:21:50 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-26 13:02:15 +08:00
|
|
|
Widget _actionMore(Peer peer) => Listener(
|
|
|
|
onPointerDown: (e) {
|
|
|
|
final x = e.position.dx;
|
|
|
|
final y = e.position.dy;
|
|
|
|
_menuPos = RelativeRect.fromLTRB(x, y, x, y);
|
|
|
|
},
|
|
|
|
onPointerUp: (_) => _showPeerMenu(context, peer.id),
|
|
|
|
child: MouseRegion(
|
|
|
|
onEnter: (_) => _iconMoreHover.value = true,
|
|
|
|
onExit: (_) => _iconMoreHover.value = false,
|
|
|
|
child: CircleAvatar(
|
|
|
|
radius: 14,
|
|
|
|
backgroundColor: _iconMoreHover.value
|
|
|
|
? MyTheme.color(context).grayBg!
|
|
|
|
: MyTheme.color(context).bg!,
|
|
|
|
child: Icon(Icons.more_vert,
|
|
|
|
size: 18,
|
|
|
|
color: _iconMoreHover.value
|
|
|
|
? MyTheme.color(context).text
|
|
|
|
: MyTheme.color(context).lightText))));
|
|
|
|
|
2022-07-27 22:56:28 +08:00
|
|
|
/// Connect to a peer with [id].
|
|
|
|
/// If [isFileTransfer], starts a session only for file transfer.
|
2022-08-26 11:35:28 +08:00
|
|
|
/// If [isTcpTunneling], starts a session only for tcp tunneling.
|
|
|
|
/// If [isRDP], starts a session only for rdp.
|
|
|
|
void _connect(String id,
|
|
|
|
{bool isFileTransfer = false,
|
|
|
|
bool isTcpTunneling = false,
|
|
|
|
bool isRDP = false}) async {
|
2022-07-27 22:56:28 +08:00
|
|
|
if (id == '') return;
|
|
|
|
id = id.replaceAll(' ', '');
|
2022-08-26 11:35:28 +08:00
|
|
|
assert(!(isFileTransfer && isTcpTunneling && isRDP),
|
|
|
|
"more than one connect type");
|
2022-07-27 22:56:28 +08:00
|
|
|
if (isFileTransfer) {
|
|
|
|
await rustDeskWinManager.new_file_transfer(id);
|
2022-08-26 11:35:28 +08:00
|
|
|
} else if (isTcpTunneling || isRDP) {
|
|
|
|
await rustDeskWinManager.new_port_forward(id, isRDP);
|
2022-07-27 22:56:28 +08:00
|
|
|
} else {
|
|
|
|
await rustDeskWinManager.new_remote_desktop(id);
|
|
|
|
}
|
|
|
|
FocusScopeNode currentFocus = FocusScope.of(context);
|
|
|
|
if (!currentFocus.hasPrimaryFocus) {
|
|
|
|
currentFocus.unfocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Show the peer menu and handle user's choice.
|
|
|
|
/// User might remove the peer or send a file to the peer.
|
|
|
|
void _showPeerMenu(BuildContext context, String id) async {
|
|
|
|
var value = await showMenu(
|
|
|
|
context: context,
|
2022-08-26 13:02:15 +08:00
|
|
|
position: _menuPos,
|
2022-07-28 14:06:02 +08:00
|
|
|
items: await super.widget.popupMenuItemsFunc(),
|
2022-07-27 22:56:28 +08:00
|
|
|
elevation: 8,
|
|
|
|
);
|
2022-08-26 11:35:28 +08:00
|
|
|
if (value == 'connect') {
|
|
|
|
_connect(id);
|
|
|
|
} else if (value == 'file') {
|
|
|
|
_connect(id, isFileTransfer: true);
|
|
|
|
} else if (value == 'tcp-tunnel') {
|
|
|
|
_connect(id, isTcpTunneling: true);
|
|
|
|
} else if (value == 'RDP') {
|
|
|
|
_connect(id, isRDP: true);
|
|
|
|
} else if (value == 'remove') {
|
2022-08-10 10:42:59 +08:00
|
|
|
await bind.mainRemovePeer(id: id);
|
|
|
|
removePreference(id);
|
|
|
|
Get.forceAppUpdate(); // TODO use inner model / state
|
2022-08-03 22:03:31 +08:00
|
|
|
} else if (value == 'add-fav') {
|
2022-08-16 17:14:59 +08:00
|
|
|
final favs = (await bind.mainGetFav()).toList();
|
|
|
|
if (favs.indexOf(id) < 0) {
|
|
|
|
favs.add(id);
|
|
|
|
bind.mainStoreFav(favs: favs);
|
|
|
|
}
|
|
|
|
} else if (value == 'remove-fav') {
|
|
|
|
final favs = (await bind.mainGetFav()).toList();
|
|
|
|
if (favs.remove(id)) {
|
|
|
|
bind.mainStoreFav(favs: favs);
|
|
|
|
Get.forceAppUpdate(); // TODO use inner model / state
|
|
|
|
}
|
2022-07-27 22:56:28 +08:00
|
|
|
} else if (value == 'ab-delete') {
|
|
|
|
gFFI.abModel.deletePeer(id);
|
|
|
|
await gFFI.abModel.updateAb();
|
|
|
|
setState(() {});
|
|
|
|
} else if (value == 'ab-edit-tag') {
|
|
|
|
_abEditTag(id);
|
2022-07-29 12:03:24 +08:00
|
|
|
} else if (value == 'rename') {
|
|
|
|
_rename(id);
|
2022-07-29 16:47:24 +08:00
|
|
|
} else if (value == 'unremember-password') {
|
2022-08-03 22:03:31 +08:00
|
|
|
await bind.mainForgetPassword(id: id);
|
2022-08-25 14:35:08 +08:00
|
|
|
} else if (value == 'force-always-relay') {
|
|
|
|
String value;
|
|
|
|
String oldValue =
|
|
|
|
await bind.mainGetPeerOption(id: id, key: 'force-always-relay');
|
|
|
|
if (oldValue.isEmpty) {
|
|
|
|
value = 'Y';
|
|
|
|
} else {
|
|
|
|
value = '';
|
|
|
|
}
|
|
|
|
await bind.mainSetPeerOption(
|
|
|
|
id: id, key: 'force-always-relay', value: value);
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildTag(String tagName, RxList<dynamic> rxTags,
|
|
|
|
{Function()? onTap}) {
|
|
|
|
return ContextMenuArea(
|
|
|
|
width: 100,
|
|
|
|
builder: (context) => [
|
|
|
|
ListTile(
|
|
|
|
title: Text(translate("Delete")),
|
|
|
|
onTap: () {
|
|
|
|
gFFI.abModel.deleteTag(tagName);
|
|
|
|
gFFI.abModel.updateAb();
|
|
|
|
Future.delayed(Duration.zero, () => Get.back());
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: onTap,
|
|
|
|
child: Obx(
|
2022-08-03 22:03:31 +08:00
|
|
|
() => Container(
|
2022-07-27 22:56:28 +08:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: rxTags.contains(tagName) ? Colors.blue : null,
|
|
|
|
border: Border.all(color: MyTheme.darkGray),
|
|
|
|
borderRadius: BorderRadius.circular(10)),
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 4.0, vertical: 8.0),
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
|
|
|
|
child: Text(
|
|
|
|
tagName,
|
|
|
|
style: TextStyle(
|
|
|
|
color: rxTags.contains(tagName) ? MyTheme.white : null),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the image for the current [platform].
|
2022-08-24 11:01:58 +08:00
|
|
|
Widget _getPlatformImage(String platform, double size) {
|
2022-07-27 22:56:28 +08:00
|
|
|
platform = platform.toLowerCase();
|
|
|
|
if (platform == 'mac os')
|
|
|
|
platform = 'mac';
|
|
|
|
else if (platform != 'linux' && platform != 'android') platform = 'win';
|
2022-08-24 11:01:58 +08:00
|
|
|
return Image.asset('assets/$platform.png', height: size, width: size);
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void _abEditTag(String id) {
|
|
|
|
var isInProgress = false;
|
|
|
|
|
|
|
|
final tags = List.of(gFFI.abModel.tags);
|
|
|
|
var selectedTag = gFFI.abModel.getPeerTags(id).obs;
|
|
|
|
|
2022-08-12 18:42:02 +08:00
|
|
|
gFFI.dialogManager.show((setState, close) {
|
2022-07-27 22:56:28 +08:00
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Edit Tag")),
|
|
|
|
content: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
|
|
|
child: Wrap(
|
|
|
|
children: tags
|
|
|
|
.map((e) => _buildTag(e, selectedTag, onTap: () {
|
2022-08-03 22:03:31 +08:00
|
|
|
if (selectedTag.contains(e)) {
|
|
|
|
selectedTag.remove(e);
|
|
|
|
} else {
|
|
|
|
selectedTag.add(e);
|
|
|
|
}
|
|
|
|
}))
|
2022-07-27 22:56:28 +08:00
|
|
|
.toList(growable: false),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
setState(() {
|
|
|
|
isInProgress = true;
|
|
|
|
});
|
|
|
|
gFFI.abModel.changeTagForPeer(id, selectedTag);
|
|
|
|
await gFFI.abModel.updateAb();
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2022-07-29 12:03:24 +08:00
|
|
|
|
|
|
|
void _rename(String id) async {
|
|
|
|
var isInProgress = false;
|
2022-08-08 17:53:51 +08:00
|
|
|
var name = await bind.mainGetPeerOption(id: id, key: 'alias');
|
2022-08-28 21:43:18 +08:00
|
|
|
var controller = TextEditingController(text: name);
|
2022-07-29 12:03:24 +08:00
|
|
|
if (widget.type == PeerType.ab) {
|
|
|
|
final peer = gFFI.abModel.peers.firstWhere((p) => id == p['id']);
|
|
|
|
if (peer == null) {
|
|
|
|
// this should not happen
|
|
|
|
} else {
|
|
|
|
name = peer['alias'] ?? "";
|
|
|
|
}
|
|
|
|
}
|
2022-08-12 18:42:02 +08:00
|
|
|
gFFI.dialogManager.show((setState, close) {
|
2022-07-29 12:03:24 +08:00
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Rename")),
|
|
|
|
content: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
|
|
|
child: Form(
|
|
|
|
child: TextFormField(
|
2022-08-28 21:43:18 +08:00
|
|
|
controller: controller,
|
2022-07-29 12:03:24 +08:00
|
|
|
decoration: InputDecoration(border: OutlineInputBorder()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
setState(() {
|
|
|
|
isInProgress = true;
|
|
|
|
});
|
2022-08-28 21:43:18 +08:00
|
|
|
name = controller.text;
|
|
|
|
await bind.mainSetPeerOption(id: id, key: 'alias', value: name);
|
|
|
|
if (widget.type == PeerType.ab) {
|
|
|
|
gFFI.abModel.setPeerOption(id, 'alias', name);
|
|
|
|
await gFFI.abModel.updateAb();
|
|
|
|
} else {
|
|
|
|
Future.delayed(Duration.zero, () {
|
|
|
|
this.setState(() {});
|
|
|
|
});
|
2022-07-29 12:03:24 +08:00
|
|
|
}
|
2022-08-28 21:43:18 +08:00
|
|
|
close();
|
2022-07-29 12:03:24 +08:00
|
|
|
setState(() {
|
|
|
|
isInProgress = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2022-07-29 16:47:24 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract class BasePeerCard extends StatelessWidget {
|
|
|
|
final Peer peer;
|
2022-07-29 12:03:24 +08:00
|
|
|
final PeerType type;
|
|
|
|
|
|
|
|
BasePeerCard({required this.peer, required this.type, Key? key})
|
|
|
|
: super(key: key);
|
2022-07-27 22:56:28 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-07-29 12:03:24 +08:00
|
|
|
return _PeerCard(
|
|
|
|
peer: peer,
|
|
|
|
popupMenuItemsFunc: _getPopupMenuItems,
|
|
|
|
type: type,
|
|
|
|
);
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@protected
|
2022-07-28 14:06:02 +08:00
|
|
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems();
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class RecentPeerCard extends BasePeerCard {
|
2022-07-29 12:03:24 +08:00
|
|
|
RecentPeerCard({required Peer peer, Key? key})
|
|
|
|
: super(peer: peer, key: key, type: PeerType.recent);
|
2022-07-27 22:56:28 +08:00
|
|
|
|
2022-07-28 14:06:02 +08:00
|
|
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
2022-08-26 11:35:28 +08:00
|
|
|
var items = [
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Connect')), value: 'connect'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Transfer File')), value: 'file'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
2022-08-25 14:35:08 +08:00
|
|
|
await _forceAlwaysRelayMenuItem(peer.id),
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
|
|
|
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Unremember Password')),
|
|
|
|
value: 'unremember-password'),
|
2022-08-16 17:14:59 +08:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
2022-07-27 22:56:28 +08:00
|
|
|
];
|
2022-08-26 11:35:28 +08:00
|
|
|
if (peer.platform == 'Windows') {
|
|
|
|
items.insert(3, _rdpMenuItem(peer.id));
|
|
|
|
}
|
|
|
|
return items;
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FavoritePeerCard extends BasePeerCard {
|
|
|
|
FavoritePeerCard({required Peer peer, Key? key})
|
2022-07-29 12:03:24 +08:00
|
|
|
: super(peer: peer, key: key, type: PeerType.fav);
|
2022-07-27 22:56:28 +08:00
|
|
|
|
2022-07-28 14:06:02 +08:00
|
|
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
2022-08-26 11:35:28 +08:00
|
|
|
var items = [
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Connect')), value: 'connect'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Transfer File')), value: 'file'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
2022-08-25 14:35:08 +08:00
|
|
|
await _forceAlwaysRelayMenuItem(peer.id),
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
|
|
|
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Unremember Password')),
|
|
|
|
value: 'unremember-password'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Remove from Favorites')), value: 'remove-fav'),
|
|
|
|
];
|
2022-08-26 11:35:28 +08:00
|
|
|
if (peer.platform == 'Windows') {
|
|
|
|
items.insert(3, _rdpMenuItem(peer.id));
|
|
|
|
}
|
|
|
|
return items;
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DiscoveredPeerCard extends BasePeerCard {
|
|
|
|
DiscoveredPeerCard({required Peer peer, Key? key})
|
2022-07-29 12:03:24 +08:00
|
|
|
: super(peer: peer, key: key, type: PeerType.discovered);
|
2022-07-27 22:56:28 +08:00
|
|
|
|
2022-07-28 14:06:02 +08:00
|
|
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
2022-08-26 11:35:28 +08:00
|
|
|
var items = [
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Connect')), value: 'connect'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Transfer File')), value: 'file'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
2022-08-25 14:35:08 +08:00
|
|
|
await _forceAlwaysRelayMenuItem(peer.id),
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
|
|
|
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Unremember Password')),
|
|
|
|
value: 'unremember-password'),
|
2022-08-16 17:14:59 +08:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
2022-07-27 22:56:28 +08:00
|
|
|
];
|
2022-08-26 11:35:28 +08:00
|
|
|
if (peer.platform == 'Windows') {
|
|
|
|
items.insert(3, _rdpMenuItem(peer.id));
|
|
|
|
}
|
|
|
|
return items;
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AddressBookPeerCard extends BasePeerCard {
|
|
|
|
AddressBookPeerCard({required Peer peer, Key? key})
|
2022-07-29 12:03:24 +08:00
|
|
|
: super(peer: peer, key: key, type: PeerType.ab);
|
2022-07-27 22:56:28 +08:00
|
|
|
|
2022-07-28 14:06:02 +08:00
|
|
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
2022-08-26 11:35:28 +08:00
|
|
|
var items = [
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Connect')), value: 'connect'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Transfer File')), value: 'file'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
2022-08-25 14:35:08 +08:00
|
|
|
await _forceAlwaysRelayMenuItem(peer.id),
|
2022-07-27 22:56:28 +08:00
|
|
|
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Remove')), value: 'ab-delete'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Unremember Password')),
|
|
|
|
value: 'unremember-password'),
|
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
2022-07-29 12:03:24 +08:00
|
|
|
PopupMenuItem<String>(
|
|
|
|
child: Text(translate('Edit Tag')), value: 'ab-edit-tag'),
|
2022-07-27 22:56:28 +08:00
|
|
|
];
|
2022-08-26 11:35:28 +08:00
|
|
|
if (peer.platform == 'Windows') {
|
|
|
|
items.insert(3, _rdpMenuItem(peer.id));
|
|
|
|
}
|
|
|
|
return items;
|
2022-07-27 22:56:28 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-25 14:35:08 +08:00
|
|
|
|
|
|
|
Future<PopupMenuItem<String>> _forceAlwaysRelayMenuItem(String id) async {
|
|
|
|
bool force_always_relay =
|
|
|
|
(await bind.mainGetPeerOption(id: id, key: 'force-always-relay'))
|
|
|
|
.isNotEmpty;
|
|
|
|
return PopupMenuItem<String>(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Offstage(
|
|
|
|
offstage: !force_always_relay,
|
|
|
|
child: Icon(Icons.check),
|
|
|
|
),
|
|
|
|
Text(translate('Always connect via relay')),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
value: 'force-always-relay');
|
|
|
|
}
|
2022-08-26 11:35:28 +08:00
|
|
|
|
|
|
|
PopupMenuItem<String> _rdpMenuItem(String id) {
|
|
|
|
return PopupMenuItem<String>(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text('RDP'),
|
|
|
|
SizedBox(width: 20),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.edit),
|
|
|
|
onPressed: () => _rdpDialog(id),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
value: 'RDP');
|
|
|
|
}
|
|
|
|
|
|
|
|
void _rdpDialog(String id) async {
|
|
|
|
final portController = TextEditingController(
|
|
|
|
text: await bind.mainGetPeerOption(id: id, key: 'rdp_port'));
|
|
|
|
final userController = TextEditingController(
|
|
|
|
text: await bind.mainGetPeerOption(id: id, key: 'rdp_username'));
|
|
|
|
final passwordContorller = TextEditingController(
|
|
|
|
text: await bind.mainGetPeerOption(id: id, key: 'rdp_password'));
|
|
|
|
RxBool secure = true.obs;
|
|
|
|
|
|
|
|
gFFI.dialogManager.show((setState, close) {
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text('RDP ' + translate('Settings')),
|
|
|
|
content: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 500),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text(
|
|
|
|
"${translate('Port')}:",
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
).marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
inputFormatters: [
|
|
|
|
FilteringTextInputFormatter.allow(RegExp(
|
|
|
|
r'^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$'))
|
|
|
|
],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(), hintText: '3389'),
|
|
|
|
controller: portController,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text(
|
|
|
|
"${translate('Username')}:",
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
).marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
decoration: InputDecoration(border: OutlineInputBorder()),
|
|
|
|
controller: userController,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Password')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Obx(() => TextField(
|
|
|
|
obscureText: secure.value,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
onPressed: () => secure.value = !secure.value,
|
|
|
|
icon: Icon(secure.value
|
|
|
|
? Icons.visibility_off
|
|
|
|
: Icons.visibility))),
|
|
|
|
controller: passwordContorller,
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
await bind.mainSetPeerOption(
|
|
|
|
id: id, key: 'rdp_port', value: portController.text.trim());
|
|
|
|
await bind.mainSetPeerOption(
|
|
|
|
id: id, key: 'rdp_username', value: userController.text);
|
|
|
|
await bind.mainSetPeerOption(
|
|
|
|
id: id, key: 'rdp_password', value: passwordContorller.text);
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|