Servers experiment and manager #214

Merged
dan merged 10 commits from server into trunk 2021-11-02 22:26:10 +00:00
1 changed files with 65 additions and 0 deletions
Showing only changes of commit 562c05183b - Show all commits

65
lib/models/servers.dart Normal file
View File

@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
class ServerListState extends ChangeNotifier {
List<ServerInfoState> _servers = [];
void replace(Iterable<ServerInfoState> newServers) {
_servers.clear();
_servers.addAll(newServers);
notifyListeners();
}
void clear() {
_servers.clear();
}
ServerInfoState? getServer(String onion) {
int idx = _servers.indexWhere((element) => element.onion == onion);
return idx >= 0 ? _servers[idx] : null;
}
void add(String onion, String serverBundle, bool running, String description, bool autoStart, bool isEncrypted) {
print("servers.add desc:$description autostart: $autoStart");
_servers.add(ServerInfoState(onion: onion, serverBundle: serverBundle, running: running, description: description, autoStart: autoStart, isEncrypted: isEncrypted));
notifyListeners();
}
void updateServer(String onion, String serverBundle, bool running, String description, bool autoStart, bool isEncrypted) {
int idx = _servers.indexWhere((element) => element.onion == onion);
if (idx >= 0) {
_servers[idx] = ServerInfoState(onion: onion, serverBundle: serverBundle, running: running, description: description, autoStart: autoStart, isEncrypted: isEncrypted);
} else {
print("Tried to update server list without a starting state...this is probably an error");
}
notifyListeners();
}
List<ServerInfoState> get servers => _servers.sublist(0); //todo: copy?? dont want caller able to bypass changenotifier
}
class ServerInfoState extends ChangeNotifier {
dan marked this conversation as resolved
Review

You've changed the semantics of this class and moved the actual use of this class into a different class. This is bad. It makes reviewing this PR much more difficult than it needed to be.

You've changed the semantics of this class and moved the actual use of this class into a different class. This is bad. It makes reviewing this PR much more difficult than it needed to be.
String onion;
String serverBundle;
String description;
bool running;
bool autoStart;
bool isEncrypted;
ServerInfoState({required this.onion, required this.serverBundle, required this.running, required this.description, required this.autoStart, required this.isEncrypted});
void setAutostart(bool val) {
autoStart = val;
notifyListeners();
}
void setRunning(bool val) {
running = val;
notifyListeners();
}
void setDescription(String val) {
description = val;
notifyListeners();
}
}