add a screenshot command
diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart
index d005f32..6d676ca 100644
--- a/packages/flutter_tools/lib/src/ios/devices.dart
+++ b/packages/flutter_tools/lib/src/ios/devices.dart
@@ -250,6 +250,18 @@
@override
void clearLogs() {
}
+
+ @override
+ bool get supportsScreenshot => false;
+
+ @override
+ Future<bool> takeScreenshot(File outputFile) {
+ // We could use idevicescreenshot here (installed along with the brew
+ // ideviceinstaller tools). It however requires a developer disk image on
+ // the device.
+
+ return new Future<bool>.value(false);
+ }
}
class _IOSDeviceLogReader extends DeviceLogReader {
diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart
index 151f808..2703232 100644
--- a/packages/flutter_tools/lib/src/ios/simulators.dart
+++ b/packages/flutter_tools/lib/src/ios/simulators.dart
@@ -615,6 +615,49 @@
if (!logFile.existsSync())
logFile.writeAsBytesSync(<int>[]);
}
+
+ @override
+ bool get supportsScreenshot => true;
+
+ @override
+ Future<bool> takeScreenshot(File outputFile) async {
+ String homeDirPath = Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'];
+ Directory desktopDir = new Directory(path.join(homeDirPath, 'Desktop'));
+
+ // 'Simulator Screen Shot Mar 25, 2016, 2.59.43 PM.png'
+
+ Set<File> getScreenshots() {
+ return new Set<File>.from(desktopDir.listSync().where((FileSystemEntity entity) {
+ String name = path.basename(entity.path);
+ return entity is File && name.startsWith('Simulator') && name.endsWith('.png');
+ }));
+ };
+
+ Set<File> existingScreenshots = getScreenshots();
+
+ runSync(<String>[
+ 'osascript',
+ '-e',
+ 'activate application "Simulator"\n'
+ 'tell application "System Events" to keystroke "s" using command down'
+ ]);
+
+ // There is some latency here from the applescript call.
+ await new Future<Null>.delayed(new Duration(seconds: 1));
+
+ Set<File> shots = getScreenshots().difference(existingScreenshots);
+
+ if (shots.isEmpty) {
+ printError('Unable to locate the screenshot file.');
+ return false;
+ }
+
+ File shot = shots.first;
+ outputFile.writeAsBytesSync(shot.readAsBytesSync());
+ shot.delete();
+
+ return true;
+ }
}
class _IOSSimulatorLogReader extends DeviceLogReader {