captureNow method
Screenshot this device into the ring. Null on failure; never throws, and nothing is recorded when cancelled is true once the shot is taken.
Implementation
Future<Capture?> captureNow(String trigger, {bool Function()? cancelled}) async {
if (_disposed) return null;
final dir = Directory('${Directory.systemTemp.path}/glint-captures/$id');
final path = '${dir.path}/${DateTime.now().millisecondsSinceEpoch}.png';
try {
if (!dir.existsSync()) dir.createSync(recursive: true);
final shot = await CallProgress.during('taking a screenshot', () => backend.screenshot(path), key: 'screenshot');
if (shot.error != null || shot.path == null) return null;
if (cancelled?.call() ?? false) return null;
final c = Capture(
path: shot.path!,
takenAt: DateTime.now(),
trigger: trigger,
lifecycle: lastLifecycle,
width: shot.width,
height: shot.height,
);
captures.add(c);
return c;
} on Object {
return null;
}
}