refresh method
Finds running apps and connects to new ones, keeping the connections to apps that are still running. Returns the apps discovery had to skip.
Implementation
Future<List<LiveSkippedApp>> refresh() async {
if (_closed) return const [];
final Uri? address = uri;
final LiveDiscoveryResult found = address == null
? await runner.discover(LiveOptions(timeout: timeout))
: LiveDiscoveryResult([
await LiveApp.connect(
address,
device: address.hasPort
? '${address.host}:${address.port}'
: address.host,
package: runner.project.packageName,
timeout: timeout,
),
], const []);
final Set<String> running = {
for (final LiveApp app in found.apps) app.uri.toString(),
};
for (final LiveApp app in List<LiveApp>.of(_apps)) {
if (!running.contains(app.uri.toString()) || app.client.isClosed) {
await _drop(app);
}
}
for (final LiveApp fresh in found.apps) {
final LiveApp? known = _find(fresh.uri);
if (known != null) {
known.status = fresh.status;
await fresh.close();
continue;
}
_apps.add(fresh);
await _watch(fresh);
}
_updatePolling();
onChange?.call();
return found.skipped;
}