mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 12:29:04 +08:00
Merge pull request #1049 from Kingtous/flutter_desktop
feat: all address book logic
This commit is contained in:
commit
98a01aefa6
@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:contextmenu/contextmenu.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -302,22 +303,39 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
return Image.asset('assets/$platform.png', height: 50);
|
||||
}
|
||||
|
||||
bool hitTag(List<dynamic> selectedTags, List<dynamic> idents) {
|
||||
if (selectedTags.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
if (idents.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
for (final tag in selectedTags) {
|
||||
if (!idents.contains(tag)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Get all the saved peers.
|
||||
Future<Widget> getPeers({RemoteType rType = RemoteType.recently}) async {
|
||||
final space = 8.0;
|
||||
final cards = <Widget>[];
|
||||
var peers;
|
||||
List<Peer> peers;
|
||||
switch (rType) {
|
||||
case RemoteType.recently:
|
||||
peers = gFFI.peers();
|
||||
break;
|
||||
case RemoteType.favorite:
|
||||
peers = await gFFI.bind.mainGetFav().then((peers) async {
|
||||
final peersEntities = await Future.wait(peers.map((id) => gFFI.bind.mainGetPeers(id: id)).toList(growable: false))
|
||||
.then((peers_str){
|
||||
final peersEntities = await Future.wait(peers
|
||||
.map((id) => gFFI.bind.mainGetPeers(id: id))
|
||||
.toList(growable: false))
|
||||
.then((peers_str) {
|
||||
final len = peers_str.length;
|
||||
final ps = List<Peer>.empty(growable: true);
|
||||
for(var i = 0; i< len ; i++){
|
||||
for (var i = 0; i < len; i++) {
|
||||
print("${peers[i]}: ${peers_str[i]}");
|
||||
ps.add(Peer.fromJson(peers[i], jsonDecode(peers_str[i])['info']));
|
||||
}
|
||||
@ -333,7 +351,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
});
|
||||
break;
|
||||
case RemoteType.addressBook:
|
||||
await gFFI.abModel.getAb();
|
||||
peers = gFFI.abModel.peers.map((e) {
|
||||
return Peer.fromJson(e['id'], e);
|
||||
}).toList();
|
||||
@ -343,97 +360,107 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
var deco = Rx<BoxDecoration?>(BoxDecoration(
|
||||
border: Border.all(color: Colors.transparent, width: 1.0),
|
||||
borderRadius: BorderRadius.circular(20)));
|
||||
cards.add(Container(
|
||||
width: 225,
|
||||
height: 150,
|
||||
child: Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20)),
|
||||
child: MouseRegion(
|
||||
onEnter: (evt) {
|
||||
deco.value = BoxDecoration(
|
||||
border: Border.all(color: Colors.blue, width: 1.0),
|
||||
borderRadius: BorderRadius.circular(20));
|
||||
},
|
||||
onExit: (evt) {
|
||||
deco.value = BoxDecoration(
|
||||
border: Border.all(color: Colors.transparent, width: 1.0),
|
||||
borderRadius: BorderRadius.circular(20));
|
||||
},
|
||||
child: Obx(
|
||||
() => Container(
|
||||
decoration: deco.value,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: str2color('${p.id}${p.platform}', 0x7f),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child:
|
||||
getPlatformImage('${p.platform}'),
|
||||
),
|
||||
Row(
|
||||
cards.add(Obx(
|
||||
() => Offstage(
|
||||
offstage: !hitTag(gFFI.abModel.selectedTags, p.tags) &&
|
||||
rType == RemoteType.addressBook,
|
||||
child: Container(
|
||||
width: 225,
|
||||
height: 150,
|
||||
child: Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20)),
|
||||
child: MouseRegion(
|
||||
onEnter: (evt) {
|
||||
deco.value = BoxDecoration(
|
||||
border: Border.all(color: Colors.blue, width: 1.0),
|
||||
borderRadius: BorderRadius.circular(20));
|
||||
},
|
||||
onExit: (evt) {
|
||||
deco.value = BoxDecoration(
|
||||
border:
|
||||
Border.all(color: Colors.transparent, width: 1.0),
|
||||
borderRadius: BorderRadius.circular(20));
|
||||
},
|
||||
child: Obx(
|
||||
() => Container(
|
||||
decoration: deco.value,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
str2color('${p.id}${p.platform}', 0x7f),
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Tooltip(
|
||||
message:
|
||||
'${p.username}@${p.hostname}',
|
||||
child: Text(
|
||||
'${p.username}@${p.hostname}',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: getPlatformImage(
|
||||
'${p.platform}'),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Tooltip(
|
||||
message:
|
||||
'${p.username}@${p.hostname}',
|
||||
child: Text(
|
||||
'${p.username}@${p.hostname}',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
overflow:
|
||||
TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
).paddingAll(4.0),
|
||||
).paddingAll(4.0),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("${p.id}"),
|
||||
InkWell(
|
||||
child: Icon(Icons.more_vert),
|
||||
onTapDown: (e) {
|
||||
final x = e.globalPosition.dx;
|
||||
final y = e.globalPosition.dy;
|
||||
_menuPos = RelativeRect.fromLTRB(x, y, x, y);
|
||||
},
|
||||
onTap: () {
|
||||
showPeerMenu(context, p.id, rType);
|
||||
}),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("${p.id}"),
|
||||
InkWell(
|
||||
child: Icon(Icons.more_vert),
|
||||
onTapDown: (e) {
|
||||
final x = e.globalPosition.dx;
|
||||
final y = e.globalPosition.dy;
|
||||
_menuPos =
|
||||
RelativeRect.fromLTRB(x, y, x, y);
|
||||
},
|
||||
onTap: () {
|
||||
showPeerMenu(context, p.id, rType);
|
||||
}),
|
||||
],
|
||||
).paddingSymmetric(vertical: 8.0, horizontal: 12.0)
|
||||
],
|
||||
).paddingSymmetric(vertical: 8.0, horizontal: 12.0)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
))));
|
||||
))),
|
||||
),
|
||||
));
|
||||
});
|
||||
return SingleChildScrollView(
|
||||
child: Wrap(children: cards, spacing: space, runSpacing: space));
|
||||
@ -450,7 +477,11 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
||||
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
||||
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
||||
rType == RemoteType.addressBook
|
||||
? PopupMenuItem<String>(
|
||||
child: Text(translate('Remove')), value: 'ab-delete')
|
||||
: PopupMenuItem<String>(
|
||||
child: Text(translate('Remove')), value: 'remove'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Unremember Password')),
|
||||
value: 'unremember-password'),
|
||||
@ -459,9 +490,13 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
items.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Remove from Favorites')),
|
||||
value: 'remove-fav'));
|
||||
} else
|
||||
} else if (rType != RemoteType.addressBook) {
|
||||
items.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Add to Favorites')), value: 'add-fav'));
|
||||
} else {
|
||||
items.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Edit Tag')), value: 'ab-edit-tag'));
|
||||
}
|
||||
var value = await showMenu(
|
||||
context: context,
|
||||
position: this._menuPos,
|
||||
@ -475,7 +510,16 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
}();
|
||||
} else if (value == 'file') {
|
||||
connect(id, isFileTransfer: true);
|
||||
} else if (value == 'add-fav') {}
|
||||
} else if (value == 'add-fav') {
|
||||
} else if (value == 'connect') {
|
||||
connect(id, isFileTransfer: false);
|
||||
} else if (value == 'ab-delete') {
|
||||
gFFI.abModel.deletePeer(id);
|
||||
await gFFI.abModel.updateAb();
|
||||
setState(() {});
|
||||
} else if (value == 'ab-edit-tag') {
|
||||
abEditTag(id);
|
||||
}
|
||||
}
|
||||
|
||||
var svcStopped = false.obs;
|
||||
@ -565,6 +609,18 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return _buildAddressBook(context);
|
||||
} else if (snapshot.hasError) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(translate("${snapshot.error}")),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {});
|
||||
},
|
||||
child: Text(translate("Retry")))
|
||||
],
|
||||
);
|
||||
} else {
|
||||
if (model.abLoading) {
|
||||
return Center(
|
||||
@ -572,7 +628,17 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
);
|
||||
} else if (model.abError.isNotEmpty) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(translate("${model.abError}")),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {});
|
||||
},
|
||||
child: Text(translate("Retry")))
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Offstage();
|
||||
@ -601,7 +667,21 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
Text(translate('Tags')),
|
||||
InkWell(
|
||||
child: PopupMenuButton(
|
||||
itemBuilder: (context) => [],
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
child: Text(translate("Add ID")),
|
||||
value: 'add-id',
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text(translate("Add Tag")),
|
||||
value: 'add-tag',
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text(translate("Unselect all tags")),
|
||||
value: 'unset-all-tag',
|
||||
),
|
||||
],
|
||||
onSelected: handleAbOp,
|
||||
child: Icon(Icons.more_vert_outlined)),
|
||||
)
|
||||
],
|
||||
@ -612,9 +692,20 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: MyTheme.darkGray)),
|
||||
child: Wrap(
|
||||
children:
|
||||
gFFI.abModel.tags.map((e) => buildTag(e)).toList(),
|
||||
child: Obx(
|
||||
() => Wrap(
|
||||
children: gFFI.abModel.tags
|
||||
.map((e) => buildTag(e, gFFI.abModel.selectedTags,
|
||||
onTap: () {
|
||||
//
|
||||
if (gFFI.abModel.selectedTags.contains(e)) {
|
||||
gFFI.abModel.selectedTags.remove(e);
|
||||
} else {
|
||||
gFFI.abModel.selectedTags.add(e);
|
||||
}
|
||||
}))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
).marginSymmetric(vertical: 8.0),
|
||||
)
|
||||
@ -622,33 +713,266 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
),
|
||||
),
|
||||
).marginOnly(right: 8.0),
|
||||
Column(
|
||||
children: [
|
||||
FutureBuilder<Widget>(
|
||||
future: getPeers(rType: RemoteType.addressBook),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}),
|
||||
],
|
||||
Expanded(
|
||||
child: FutureBuilder<Widget>(
|
||||
future: getPeers(rType: RemoteType.addressBook),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [Expanded(child: snapshot.data!)],
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
child: Text('${snapshot.error}'));
|
||||
} else {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
child: CircularProgressIndicator());
|
||||
}
|
||||
}),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTag(String tagName) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
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),
|
||||
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(
|
||||
() => Container(
|
||||
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),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// tag operation
|
||||
void handleAbOp(String value) {
|
||||
if (value == 'add-id') {
|
||||
abAddId();
|
||||
} else if (value == 'add-tag') {
|
||||
abAddTag();
|
||||
} else if (value == 'unset-all-tag') {
|
||||
gFFI.abModel.unsetSelectedTags();
|
||||
}
|
||||
}
|
||||
|
||||
void abAddId() async {
|
||||
var field = "";
|
||||
var msg = "";
|
||||
var isInProgress = false;
|
||||
DialogManager.show((setState, close) {
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate("Add ID")),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(translate("whitelist_sep")),
|
||||
SizedBox(
|
||||
height: 8.0,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onChanged: (s) {
|
||||
field = s;
|
||||
},
|
||||
maxLines: null,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
errorText: msg.isEmpty ? null : translate(msg),
|
||||
),
|
||||
controller: TextEditingController(text: field),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 4.0,
|
||||
),
|
||||
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
close();
|
||||
},
|
||||
child: Text(translate("Cancel"))),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
msg = "";
|
||||
isInProgress = true;
|
||||
});
|
||||
field = field.trim();
|
||||
if (field.isEmpty) {
|
||||
// pass
|
||||
} else {
|
||||
final ids = field.trim().split(RegExp(r"[\s,;\n]+"));
|
||||
field = ids.join(',');
|
||||
for (final newId in ids) {
|
||||
if (gFFI.abModel.idContainBy(newId)) {
|
||||
continue;
|
||||
}
|
||||
gFFI.abModel.addId(newId);
|
||||
}
|
||||
await gFFI.abModel.updateAb();
|
||||
this.setState(() {});
|
||||
// final currentPeers
|
||||
}
|
||||
close();
|
||||
},
|
||||
child: Text(translate("OK"))),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void abAddTag() async {
|
||||
var field = "";
|
||||
var msg = "";
|
||||
var isInProgress = false;
|
||||
DialogManager.show((setState, close) {
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate("Add Tag")),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(translate("whitelist_sep")),
|
||||
SizedBox(
|
||||
height: 8.0,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onChanged: (s) {
|
||||
field = s;
|
||||
},
|
||||
maxLines: null,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
errorText: msg.isEmpty ? null : translate(msg),
|
||||
),
|
||||
controller: TextEditingController(text: field),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 4.0,
|
||||
),
|
||||
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
close();
|
||||
},
|
||||
child: Text(translate("Cancel"))),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
msg = "";
|
||||
isInProgress = true;
|
||||
});
|
||||
field = field.trim();
|
||||
if (field.isEmpty) {
|
||||
// pass
|
||||
} else {
|
||||
final tags = field.trim().split(RegExp(r"[\s,;\n]+"));
|
||||
field = tags.join(',');
|
||||
for (final tag in tags) {
|
||||
gFFI.abModel.addTag(tag);
|
||||
}
|
||||
await gFFI.abModel.updateAb();
|
||||
// final currentPeers
|
||||
}
|
||||
close();
|
||||
},
|
||||
child: Text(translate("OK"))),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void abEditTag(String id) {
|
||||
var isInProgress = false;
|
||||
|
||||
final tags = List.of(gFFI.abModel.tags);
|
||||
var selectedTag = gFFI.abModel.getPeerTags(id).obs;
|
||||
|
||||
DialogManager.show((setState, close) {
|
||||
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: () {
|
||||
if (selectedTag.contains(e)) {
|
||||
selectedTag.remove(e);
|
||||
} else {
|
||||
selectedTag.add(e);
|
||||
}
|
||||
}))
|
||||
.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"))),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class AddressBookPage extends StatefulWidget {
|
||||
|
@ -2,13 +2,16 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/models/model.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class AbModel with ChangeNotifier {
|
||||
var abLoading = false;
|
||||
var abError = "";
|
||||
var tags = [];
|
||||
var peers = [];
|
||||
var tags = [].obs;
|
||||
var peers = [].obs;
|
||||
|
||||
var selectedTags = List<String>.empty(growable: true).obs;
|
||||
|
||||
WeakReference<FFI> parent;
|
||||
|
||||
@ -21,23 +24,25 @@ class AbModel with ChangeNotifier {
|
||||
notifyListeners();
|
||||
// request
|
||||
final api = "${await getApiServer()}/api/ab/get";
|
||||
debugPrint("request $api with post ${await _getHeaders()}");
|
||||
final resp = await http.post(Uri.parse(api), headers: await _getHeaders());
|
||||
abLoading = false;
|
||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||
if (json.containsKey('error')) {
|
||||
abError = json['error'];
|
||||
} else if (json.containsKey('data')) {
|
||||
// {"tags":["aaa","bbb"],
|
||||
// "peers":[{"id":"aa1234","username":"selfd",
|
||||
// "hostname":"PC","platform":"Windows","tags":["aaa"]}]}
|
||||
final data = jsonDecode(json['data']);
|
||||
tags = data['tags'];
|
||||
peers = data['peers'];
|
||||
try {
|
||||
final resp =
|
||||
await http.post(Uri.parse(api), headers: await _getHeaders());
|
||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||
if (json.containsKey('error')) {
|
||||
abError = json['error'];
|
||||
} else if (json.containsKey('data')) {
|
||||
final data = jsonDecode(json['data']);
|
||||
tags.value = data['tags'];
|
||||
peers.value = data['peers'];
|
||||
}
|
||||
return resp.body;
|
||||
} catch (err) {
|
||||
abError = err.toString();
|
||||
} finally {
|
||||
abLoading = false;
|
||||
}
|
||||
print(json);
|
||||
notifyListeners();
|
||||
return resp.body;
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> getApiServer() async {
|
||||
@ -53,4 +58,86 @@ class AbModel with ChangeNotifier {
|
||||
Future<Map<String, String>>? _getHeaders() {
|
||||
return _ffi?.getHttpHeaders();
|
||||
}
|
||||
|
||||
///
|
||||
void addId(String id) async {
|
||||
if (idContainBy(id)) {
|
||||
return;
|
||||
}
|
||||
peers.add({"id": id});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addTag(String tag) async {
|
||||
if (tagContainBy(tag)) {
|
||||
return;
|
||||
}
|
||||
tags.add(tag);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void changeTagForPeer(String id, List<dynamic> tags) {
|
||||
final it = peers.where((element) => element['id'] == id);
|
||||
if (it.isEmpty) {
|
||||
return;
|
||||
}
|
||||
it.first['tags'] = tags;
|
||||
}
|
||||
|
||||
Future<void> updateAb() async {
|
||||
abLoading = true;
|
||||
notifyListeners();
|
||||
final api = "${await getApiServer()}/api/ab";
|
||||
var authHeaders = await _getHeaders() ?? Map<String, String>();
|
||||
authHeaders['Content-Type'] = "application/json";
|
||||
final body = jsonEncode({
|
||||
"data": jsonEncode({"tags": tags, "peers": peers})
|
||||
});
|
||||
final resp =
|
||||
await http.post(Uri.parse(api), headers: authHeaders, body: body);
|
||||
abLoading = false;
|
||||
await getAb();
|
||||
notifyListeners();
|
||||
debugPrint("resp: ${resp.body}");
|
||||
}
|
||||
|
||||
bool idContainBy(String id) {
|
||||
return peers.where((element) => element['id'] == id).isNotEmpty;
|
||||
}
|
||||
|
||||
bool tagContainBy(String tag) {
|
||||
return tags.where((element) => element == tag).isNotEmpty;
|
||||
}
|
||||
|
||||
void deletePeer(String id) {
|
||||
peers.removeWhere((element) => element['id'] == id);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void deleteTag(String tag) {
|
||||
tags.removeWhere((element) => element == tag);
|
||||
for (var peer in peers) {
|
||||
if (peer['tags'] == null) {
|
||||
continue;
|
||||
}
|
||||
if (((peer['tags']) as List<dynamic>).contains(tag)) {
|
||||
((peer['tags']) as List<dynamic>).remove(tag);
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void unsetSelectedTags() {
|
||||
selectedTags.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<dynamic> getPeerTags(String id) {
|
||||
final it = peers.where((p0) => p0['id'] == id);
|
||||
if (it.isEmpty) {
|
||||
return [];
|
||||
} else {
|
||||
return it.first['tags'] ?? [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1112,12 +1112,14 @@ class Peer {
|
||||
final String username;
|
||||
final String hostname;
|
||||
final String platform;
|
||||
final List<dynamic> tags;
|
||||
|
||||
Peer.fromJson(String id, Map<String, dynamic> json)
|
||||
: id = id,
|
||||
username = json['username'],
|
||||
hostname = json['hostname'],
|
||||
platform = json['platform'];
|
||||
username = json['username'] ?? '',
|
||||
hostname = json['hostname'] ?? '',
|
||||
platform = json['platform'] ?? '',
|
||||
tags = json['tags'] ?? [];
|
||||
}
|
||||
|
||||
class Display {
|
||||
|
@ -7,21 +7,35 @@ packages:
|
||||
name: _fe_analyzer_shared
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "40.0.0"
|
||||
version: "43.0.0"
|
||||
after_layout:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: after_layout
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
version: "4.3.1"
|
||||
animations:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: animations
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
archive:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: archive
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.3.0"
|
||||
version: "3.3.1"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -56,7 +70,7 @@ packages:
|
||||
name: build_config
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
version: "1.1.0"
|
||||
build_daemon:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -77,7 +91,7 @@ packages:
|
||||
name: build_runner
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.11"
|
||||
version: "2.2.0"
|
||||
build_runner_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -98,7 +112,7 @@ packages:
|
||||
name: built_value
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "8.3.2"
|
||||
version: "8.4.0"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -141,6 +155,13 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
contextmenu:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: contextmenu
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -282,42 +303,42 @@ packages:
|
||||
name: firebase_analytics
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "9.1.9"
|
||||
version: "9.3.0"
|
||||
firebase_analytics_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_analytics_platform_interface
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.1.7"
|
||||
version: "3.3.0"
|
||||
firebase_analytics_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_analytics_web
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.4.0+14"
|
||||
version: "0.4.2"
|
||||
firebase_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_core
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.17.1"
|
||||
version: "1.20.0"
|
||||
firebase_core_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_core_platform_interface
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.4.0"
|
||||
version: "4.5.0"
|
||||
firebase_core_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: firebase_core_web
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.6.4"
|
||||
version: "1.7.1"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -357,7 +378,7 @@ packages:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.6"
|
||||
version: "2.0.7"
|
||||
flutter_rust_bridge:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -373,7 +394,7 @@ packages:
|
||||
name: flutter_smart_dialog
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.5.3+2"
|
||||
version: "4.5.3+7"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@ -390,14 +411,14 @@ packages:
|
||||
name: freezed
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.3+1"
|
||||
version: "2.1.0+1"
|
||||
freezed_annotation:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: freezed_annotation
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
version: "2.1.0"
|
||||
frontend_server_client:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -418,7 +439,7 @@ packages:
|
||||
name: glob
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
version: "2.1.0"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -439,7 +460,7 @@ packages:
|
||||
name: http_multi_server
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.2.0"
|
||||
version: "3.2.1"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -467,7 +488,7 @@ packages:
|
||||
name: image_picker_android
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.8.5"
|
||||
version: "0.8.5+1"
|
||||
image_picker_for_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -481,7 +502,7 @@ packages:
|
||||
name: image_picker_ios
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.8.5+5"
|
||||
version: "0.8.5+6"
|
||||
image_picker_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -516,7 +537,7 @@ packages:
|
||||
name: json_annotation
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.5.0"
|
||||
version: "4.6.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -572,7 +593,7 @@ packages:
|
||||
name: package_config
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
version: "2.1.0"
|
||||
package_info_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -635,14 +656,14 @@ packages:
|
||||
name: path_provider_android
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.14"
|
||||
version: "2.0.16"
|
||||
path_provider_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_ios
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.9"
|
||||
version: "2.0.10"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -705,7 +726,7 @@ packages:
|
||||
name: pool
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.5.0"
|
||||
version: "1.5.1"
|
||||
process:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -819,14 +840,14 @@ packages:
|
||||
name: shelf
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
version: "1.3.1"
|
||||
shelf_web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_web_socket
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "1.0.2"
|
||||
shortid:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -943,7 +964,7 @@ packages:
|
||||
name: url_launcher
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.1.3"
|
||||
version: "6.1.5"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -978,14 +999,14 @@ packages:
|
||||
name: url_launcher_platform_interface
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.5"
|
||||
version: "2.1.0"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.11"
|
||||
version: "2.0.12"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -67,6 +67,7 @@ dependencies:
|
||||
freezed_annotation: ^2.0.3
|
||||
tray_manager: 0.1.7
|
||||
get: ^4.6.5
|
||||
contextmenu: ^3.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: ^0.9.1
|
||||
|
Loading…
Reference in New Issue
Block a user