use method

Future<({List<LiveApp> candidates, String error})?> use(
  1. String query
)

Picks the app commands run on: a number from devices, a device name, all for every app, or auto to use the only running app.

Returns why nothing was picked, with the apps to choose from, or null.

Implementation

Future<({String error, List<LiveApp> candidates})?> use(String query) async {
  final String wanted = query.trim();
  if (wanted == 'all' || wanted == 'auto') {
    _all = wanted == 'all';
    _chosenUri = null;
    _chosenDevice = null;
    if (_all) await _refreshQuietly();
    onChange?.call();
    return null;
  }

  LiveTargetSelection<LiveApp> selection = _select(device: wanted);
  if (!selection.isSuccess) {
    await _refreshQuietly();
    selection = _select(device: wanted);
  }
  if (!selection.isSuccess) {
    return (error: selection.error!, candidates: selection.candidates);
  }
  final LiveApp app = selection.targets.single;
  _all = false;
  _chosenUri = app.uri.toString();
  _chosenDevice = app.device;
  onChange?.call();
  return null;
}