Merge pull request 'support for server metrics' (#259) from serverMetrics into trunk
continuous-integration/drone/push Build is passing Details

Reviewed-on: #259
Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
Sarah Jamie Lewis 2021-12-15 20:21:44 +00:00
commit 9a7ce2afc7
5 changed files with 70 additions and 10 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

@ -266,4 +266,4 @@
"newBulletinLabel": "Nouveau bulletin",
"createGroupBtn": "Créer",
"createGroupTitle": "Créer un groupe"
}
}

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

View File

@ -114,7 +114,7 @@ class _ContactsViewState extends State<ContactsView> {
}));
// Manage known Servers
if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) {
if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment) || Provider.of<Settings>(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) {
actions.add(IconButton(
icon: Icon(CwtchIcons.dns_24px),
tooltip: AppLocalizations.of(context)!.manageKnownServersButton,