add ab full check

This commit is contained in:
rustdesk
2023-07-26 20:43:18 +08:00
parent 4fe85cdd4a
commit 791645fa59
38 changed files with 124 additions and 1 deletions

View File

@@ -241,6 +241,9 @@ class _AddressBookState extends State<AddressBook> {
}
void abAddId() async {
if (gFFI.abModel.isFull(true)) {
return;
}
var isInProgress = false;
IDTextEditingController idController = IDTextEditingController(text: '');
TextEditingController aliasController = TextEditingController(text: '');

View File

@@ -644,6 +644,9 @@ abstract class BasePeerCard extends StatelessWidget {
),
proc: () {
() async {
if (gFFI.abModel.isFull(true)) {
return;
}
if (!gFFI.abModel.idContainBy(peer.id)) {
gFFI.abModel.addPeer(peer);
await gFFI.abModel.pushAb();

View File

@@ -29,6 +29,7 @@ class AbModel {
final selectedTags = List<String>.empty(growable: true).obs;
var initialized = false;
var licensedDevices = 0;
WeakReference<FFI> parent;
@@ -52,6 +53,10 @@ class AbModel {
if (json.containsKey('error')) {
abError.value = json['error'];
} else if (json.containsKey('data')) {
try {
gFFI.abModel.licensedDevices = json['licensed_devices'];
// ignore: empty_catches
} catch (e) {}
final data = jsonDecode(json['data']);
if (data != null) {
tags.clear();
@@ -94,6 +99,15 @@ class AbModel {
peers.add(peer);
}
bool isFull(bool warn) {
final res = licensedDevices > 0 && peers.length >= licensedDevices;
if (res && warn) {
BotToast.showText(
contentColor: Colors.red, text: translate("exceed_max_devices"));
}
return res;
}
void addPeer(Peer peer) {
peers.removeWhere((e) => e.id == peer.id);
peers.add(peer);