support for server metrics

This commit is contained in:
Dan Ballard 2021-11-25 18:13:36 -08:00
parent 62b70713fb
commit 2d66e42624
4 changed files with 69 additions and 8 deletions

View File

@ -79,6 +79,12 @@ class CwtchNotifier {
server.setRunning(data["Intent"] == "running");
}
break;
case "ServerStatsUpdate":
EnvironmentConfig.debugLog("ServerStatsUpdate $data");
var totalMessages = int.parse(data["TotalMessages"]);
var connections = int.parse(data["Connections"]);
serverListState.updateServerStats(data["Identity"], totalMessages, connections);
break;
case "GroupCreated":
// Retrieve Server Status from Cache...
String status = "";

View File

@ -8,6 +8,7 @@
"serverConnectionsLabel": "Connexion",
"manageKnownServersShort": "Serveurs",
"manageKnownServersLong": "Gérer les serveurs connus",
"displayNameTooltip": "Veuillez entrer un nom d'usage s'il vous plaît",
"manageKnownServersButton": "Gérer les serveurs connus",
"importLocalServerSelectText": "Sélectionnez le serveur local",
"importLocalServerLabel": "Importer un serveur hébergé localement",

View File

@ -39,11 +39,34 @@ class ServerListState extends ChangeNotifier {
notifyListeners();
}
void updateServerStats(String onion, int newTotalMessages, int newConnections) {
var server = getServer(onion);
if (server != null) {
server.setStats(newTotalMessages, newConnections);
resort();
notifyListeners();
}
}
void delete(String onion) {
_servers.removeWhere((element) => element.onion == onion);
notifyListeners();
}
void resort() {
_servers.sort((ServerInfoState a, ServerInfoState b) {
// return -1 = a first in list
// return 1 = b first in list
if (a.totalMessages > b.totalMessages) {
return -1;
} else if (b.totalMessages > a.totalMessages) {
return 1;
}
return 0;
});
}
List<ServerInfoState> get servers => _servers.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier
}
@ -55,6 +78,8 @@ class ServerInfoState extends ChangeNotifier {
bool running;
bool autoStart;
bool isEncrypted;
int totalMessages = 0;
int connections = 0;
ServerInfoState({required this.onion, required this.serverBundle, required this.running, required this.description, required this.autoStart, required this.isEncrypted});
@ -72,4 +97,10 @@ class ServerInfoState extends ChangeNotifier {
description = val;
notifyListeners();
}
void setStats(int newTotalMessages, int newConnections) {
totalMessages = newTotalMessages;
connections = newConnections;
notifyListeners();
}
}

View File

@ -81,20 +81,14 @@ class _AddEditServerViewState extends State<AddEditServerView> {
child: Form(
key: _formKey,
child: Container(
margin: EdgeInsets.fromLTRB(30, 0, 30, 10),
padding: EdgeInsets.fromLTRB(20, 0, 20, 10),
margin: EdgeInsets.fromLTRB(30, 5, 30, 10),
padding: EdgeInsets.fromLTRB(20, 5, 20, 10),
child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
// Onion
Visibility(
visible: serverInfoState.onion.isNotEmpty,
child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
SizedBox(
height: 20,
),
CwtchLabel(label: AppLocalizations.of(context)!.serverAddress),
SizedBox(
height: 20,
),
SelectableText(serverInfoState.onion)
])),
@ -156,6 +150,35 @@ class _AddEditServerViewState extends State<AddEditServerView> {
secondary: Icon(CwtchIcons.favorite_24dp, color: settings.current().mainTextColor()),
),
// metrics
Visibility(
visible: serverInfoState.onion.isNotEmpty,
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
SizedBox(
height: 20,
),
Text(AppLocalizations.of(context)!.serverMetricsLabel, style: Provider.of<FlwtchState>(context).biggerFont),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row( crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(AppLocalizations.of(context)!.serverTotalMessagesLabel),
]),
Text(serverInfoState.totalMessages.toString())
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row( crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(AppLocalizations.of(context)!.serverConnectionsLabel),
]),
Text(serverInfoState.connections.toString())
]),
])),
// ***** Password *****
// use password toggle