filteredConfig static method

Future<String?> filteredConfig(
  1. String? config
)

Sometimes config script has too many Remotes, it cause ANR in several devices, This happened because the plugin check every remote and somehow affected the UI to freeze

Use this function if you wanted to force user to use 1 remote by randomize the remotes provided

Implementation

static Future<String?> filteredConfig(String? config) async {
  List<String> remotes = [];
  List<String> output = [];
  if (config == null) return null;
  var raw = config.split("\n");

  for (var item in raw) {
    if (item.trim().toLowerCase().startsWith("remote ")) {
      if (!output.contains("REMOTE_HERE")) {
        output.add("REMOTE_HERE");
      }
      remotes.add(item);
    } else {
      output.add(item);
    }
  }
  String fastestServer = remotes[Random().nextInt(remotes.length - 1)];
  int indexRemote = output.indexWhere((element) => element == "REMOTE_HERE");
  output.removeWhere((element) => element == "REMOTE_HERE");
  output.insert(indexRemote, fastestServer);
  return output.join("\n");
}