ensureDeviceHid function

Future<String> ensureDeviceHid({
  1. BytesFetcher? fetch,
})

The helper's path, downloading this version's release asset when no copy exists; throws DeviceHidError kind missing.

Implementation

Future<String> ensureDeviceHid({BytesFetcher? fetch}) async {
  final found = locateDeviceHid();
  if (found != null) return found;
  if (Platform.environment[noBridgeDownloadEnv] != null) {
    throw DeviceHidError(DeviceHidFailure.missing, 'no glint-devicehid helper and $noBridgeDownloadEnv is set');
  }
  final dest = cachedDeviceHidPath();
  try {
    await downloadReleaseAsset(deviceHidAssetName, dest, executable: true, fetch: fetch);
  } on BridgeDownloadError catch (e) {
    throw DeviceHidError(DeviceHidFailure.missing, 'could not download glint-devicehid: ${e.message}');
  }
  return dest;
}