From 892c06163373450a15292a0d56019bacefef3bb7 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Tue, 14 May 2024 14:57:08 +0200 Subject: [PATCH] store raw screenshots --- .gitignore | 2 +- screenshots/models/screenshot_args.dart | 1 + test_driver/screenshot_driver.dart | 133 ++---------------------- 3 files changed, 10 insertions(+), 126 deletions(-) diff --git a/.gitignore b/.gitignore index 7d5f96c..f8353b3 100644 --- a/.gitignore +++ b/.gitignore @@ -63,4 +63,4 @@ ios/Runner/GoogleService-Info.plist coverage/ test/coverage_helper_test.dart **/failures/*.png -screenshots/generated/ \ No newline at end of file +screenshots/generated/raw/ \ No newline at end of file diff --git a/screenshots/models/screenshot_args.dart b/screenshots/models/screenshot_args.dart index ef11379..96d779d 100644 --- a/screenshots/models/screenshot_args.dart +++ b/screenshots/models/screenshot_args.dart @@ -15,6 +15,7 @@ class ScreenshotArgs { required this.isDark, }); + String toPathRaw() => 'screenshots/generated/raw/$platformFolder/$deviceName/$name.png'; String toPath() => 'screenshots/generated/$platformFolder/$deviceName/$name.png'; @override diff --git a/test_driver/screenshot_driver.dart b/test_driver/screenshot_driver.dart index 44dc107..d4e485d 100644 --- a/test_driver/screenshot_driver.dart +++ b/test_driver/screenshot_driver.dart @@ -4,139 +4,22 @@ import 'dart:typed_data'; import 'package:image/image.dart'; import 'package:integration_test/integration_test_driver_extended.dart'; -import '../screenshots/devices_config.dart'; -import '../screenshots/screenshot_args.dart'; -import '../screenshots/screenshot_config.dart'; -import 'utils/grant_camera_permission.dart'; +import '../screenshots/convert_to_store_screenshot.dart'; +import '../screenshots/models/screenshot_args.dart'; +import '../screenshots/models/screenshot_layout.dart'; Future main() async { - await grantCameraPermission(); await integrationDriver( onScreenshot: (name, bytes, [_]) async { final screenshotArgs = ScreenshotArgs.fromString(name); - final backgroundColor = ColorRgba8( - screenshotArgs.backgroundColor.r, - screenshotArgs.backgroundColor.g, - screenshotArgs.backgroundColor.b, - screenshotArgs.backgroundColor.a, + final file = await File(screenshotArgs.toPathRaw()).create(recursive: true); + final screenshot = decodePng(Uint8List.fromList(bytes))!.convertToStoreScreenshot( + args: screenshotArgs, + layout: ScreenshotLayout.iphone65inch, ); - final platform = - screenshotArgs.platformFolder == 'ios' ? ScreenshotDevicePlatform.ios : ScreenshotDevicePlatform.ios; - final deviceName = screenshotArgs.deviceName; - final file = await File(screenshotArgs.toPath()).create(recursive: true); - // switch (platform) { - // case ScreenshotDevicePlatform.ios: - // final device = screenshotDevicesIos.firstWhere( - // (device) => device.name == deviceName, - // orElse: () => ScreenshotDevice(name: '', platform: platform), - // ); - // Image screenshot = decodePng(Uint8List.fromList(bytes))!; - // screenshot = screenshot.addSystemOverlay(device, isDark: screenshotArgs.isDark); - // screenshot = screenshot.addDeviceFrame(device, backgroundColor); - // file.writeAsBytesSync(encodePng(screenshot)); - // case ScreenshotDevicePlatform.android: - // file.writeAsBytesSync(bytes); - // } - - file.writeAsBytesSync(bytes); + file.writeAsBytesSync(encodePng(screenshot)); return true; }, ); } - -extension ScreenshotImage on Image { - Image addSystemOverlay(ScreenshotDevice device, {required bool isDark}) { - final path = isDark ? device.systemOverlayPathDark : device.systemOverlayPathLight; - final statusBar = copyResize( - decodePng(File(path).readAsBytesSync())!, - width: width, - ); - return compositeImage(this, statusBar); - } - - Image addDeviceFrame(ScreenshotDevice device, Color backgroundColor) { - final screenshotRounded = copyCrop( - this, - x: 0, - y: 0, - width: width, - height: height, - ); - - final frame = decodePng(File(device.deviceFramePath).readAsBytesSync())!; - final expandedScreenshot = copyExpandCanvas( - copyExpandCanvas( - screenshotRounded, - newWidth: screenshotRounded.width + device.screenshotFrameOffset.dx, - newHeight: screenshotRounded.height + device.screenshotFrameOffset.dy, - position: ExpandCanvasPosition.bottomRight, - backgroundColor: backgroundColor, - ), - newWidth: frame.width, - newHeight: frame.height, - position: ExpandCanvasPosition.topLeft, - backgroundColor: backgroundColor, - ); - - return compositeImage(expandedScreenshot, frame); - } - - Image applyLayout(ScreenshotLayout layout) { - final scaledScreenshot = copyResize( - this, - width: layout.size.width - (layout.contentPadding.left + layout.contentPadding.right), - ); - - return copyExpandCanvas( - copyExpandCanvas( - scaledScreenshot, - newWidth: scaledScreenshot.width + layout.contentPadding.right, - newHeight: scaledScreenshot.height + layout.contentPadding.bottom, - position: ExpandCanvasPosition.topLeft, - backgroundColor: getPixel(0, 0), - ), - newWidth: layout.size.width, - newHeight: layout.size.height, - position: ExpandCanvasPosition.bottomRight, - backgroundColor: getPixel(0, 0), - ); - } - - Image addText(ScreenshotLayout layout, String title, String subtitle) { - final titleFont = BitmapFont.fromZip(File(layout.titleFontPath).readAsBytesSync()); - final subtitleFont = BitmapFont.fromZip(File(layout.subtitleFontPath).readAsBytesSync()); - final textImage = fill( - Image( - height: titleFont.lineHeight + 36 + subtitleFont.lineHeight * 2, - width: layout.size.width - (layout.contentPadding.left + layout.contentPadding.right), - ), - color: getPixel(0, 0), - ); - - drawString( - textImage, - title, - font: titleFont, - y: 0, - ); - - int subtitleDy = titleFont.lineHeight + 36; - subtitle.split('\n').forEach((line) { - drawString( - textImage, - line, - font: subtitleFont, - y: subtitleDy, - ); - subtitleDy += subtitleFont.lineHeight; - }); - - return compositeImage( - this, - textImage, - dstX: layout.contentPadding.left, - dstY: layout.contentPadding.top, - ); - } -}