diff --git a/pubspec.lock b/pubspec.lock index 8832cb3d6..ca1b5b6bc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -157,10 +157,10 @@ packages: dependency: transitive description: name: camera_android_camerax - sha256: "294b02ae027ad9edc98414a25f5e958d2dc6c65e9f102f21e2b36f0f558751eb" + sha256: "47aa7c2963ceb8db4fc3dfbba0f9195da3741f3d11e80f0e29472d46bf4c2e66" url: "https://pub.dev" source: hosted - version: "0.7.4+4" + version: "0.7.4+6" camera_avfoundation: dependency: transitive description: @@ -801,7 +801,7 @@ packages: source: hosted version: "4.1.2" image: - dependency: transitive + dependency: "direct dev" description: name: image sha256: "6300175e00616bbc832e2fc91bfa4d776af5402c81c7151bee6905bb08473c52" diff --git a/pubspec.yaml b/pubspec.yaml index 616a0d74c..e9aa3222c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -107,6 +107,8 @@ dev_dependencies: flutter_lints: ^6.0.0 flutter_native_splash: ^2.4.8 freezed: ^3.2.0 + # Used to strip the alpha channel from the generated store screenshots + image: ^4.9.1 json_serializable: ^6.14.1 mockito: ^5.6.4 network_image_mock: ^2.1.1 diff --git a/test_driver/screenshot_driver.dart b/test_driver/screenshot_driver.dart index cca70d233..84d8d687b 100644 --- a/test_driver/screenshot_driver.dart +++ b/test_driver/screenshot_driver.dart @@ -1,7 +1,27 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + // ignore_for_file: avoid_print import 'dart:io'; +import 'dart:typed_data'; +import 'package:image/image.dart' as img; import 'package:integration_test/integration_test_driver_extended.dart'; // cf. https://dev.to/mjablecnik/take-screenshot-during-flutter-integration-tests-435k @@ -10,7 +30,7 @@ Future main() async { await integrationDriver( onScreenshot: (String screenshotName, List screenshotBytes, [_]) async { final File image = await File(screenshotName).create(recursive: true); - image.writeAsBytesSync(screenshotBytes); + image.writeAsBytesSync(_withoutAlpha(screenshotBytes)); return true; }, ); @@ -18,3 +38,17 @@ Future main() async { print('An error occurred: $e'); } } + +/// Re-encodes a PNG as opaque 8 bit RGB +/// +/// The App Store rejects screenshots with an alpha channel. Returns the +/// input unchanged if it can't be decoded. +List _withoutAlpha(List bytes) { + final decoded = img.decodePng(Uint8List.fromList(bytes)); + if (decoded == null) { + print('Could not decode the screenshot, writing it out unchanged'); + return bytes; + } + + return img.encodePng(decoded.convert(format: img.Format.uint8, numChannels: 3)); +}