mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 02:57:22 +00:00
@@ -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,7 +24,6 @@ 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);
|
||||
@@ -32,8 +34,8 @@ class AbModel with ChangeNotifier {
|
||||
// "peers":[{"id":"aa1234","username":"selfd",
|
||||
// "hostname":"PC","platform":"Windows","tags":["aaa"]}]}
|
||||
final data = jsonDecode(json['data']);
|
||||
tags = data['tags'];
|
||||
peers = data['peers'];
|
||||
tags.value = data['tags'];
|
||||
peers.value = data['peers'];
|
||||
}
|
||||
print(json);
|
||||
notifyListeners();
|
||||
@@ -53,4 +55,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 {
|
||||
|
||||
Reference in New Issue
Block a user