Skip to content

Commit

Permalink
fix(ui/peers): preprocess peers
Browse files Browse the repository at this point in the history
- remove empty entries
- remove duplicated entries
  • Loading branch information
iwanbk committed Nov 20, 2024
1 parent 5535d86 commit 8dd57a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ class _MyAppState extends State<MyApp> {
return;
}
_peerValidity = '';
final peers = getPeers(textEditController.text);
var peers = getPeers(textEditController.text);
peers = preprocessPeers(peers);

// verify the peers
String? peerError = isValidPeers(peers);
if (peerError != null) {
Expand All @@ -382,6 +384,7 @@ class _MyAppState extends State<MyApp> {
}
// store the peers if verified
storePeers(peers);
textEditController.text = peers.join('\n');
try {
if (!isUseDylib()) {
startVpn(platform, peers, privKey);
Expand Down Expand Up @@ -548,6 +551,14 @@ Future<bool> stopVpn(MethodChannel platform) async {
return stopped;
}

List<String> preprocessPeers(List<String> peers) {
// Remove empty elements
peers.removeWhere((peer) => peer.isEmpty);

// Remove duplicated elements
return peers.toSet().toList();
}

String? isValidPeers(List<String> peers) {
if (peers.isEmpty || (peers.length == 1 && peers[0].isEmpty)) {
return "peers can't be empty";
Expand Down

0 comments on commit 8dd57a7

Please sign in to comment.