Skip to content

Commit

Permalink
Run "dart format --line-length=100 ." to make the diff smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Dec 23, 2023
1 parent c69c639 commit 65ba227
Show file tree
Hide file tree
Showing 207 changed files with 1,218 additions and 2,515 deletions.
46 changes: 16 additions & 30 deletions flatpak/scripts/flatpak_packager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void main(List<String> arguments) async {
'You must run this script with a metadata file argument, using the --meta flag.');
}
if (arguments.length == metaIndex + 1) {
throw Exception(
'The --meta flag must be followed by the path to the metadata file.');
throw Exception('The --meta flag must be followed by the path to the metadata file.');
}

final metaFile = File(arguments[metaIndex + 1]);
Expand All @@ -31,18 +30,14 @@ void main(List<String> arguments) async {

final fetchFromGithub = arguments.contains('--github');

final outputDir =
Directory('${Directory.current.path}/flatpak_generator_exports');
final outputDir = Directory('${Directory.current.path}/flatpak_generator_exports');
outputDir.createSync();

final packageGenerator =
PackageGenerator(inputDir: metaFile.parent, meta: meta);
final packageGenerator = PackageGenerator(inputDir: metaFile.parent, meta: meta);

packageGenerator.generatePackage(
outputDir,
PackageGenerator.runningOnARM()
? CPUArchitecture.aarch64
: CPUArchitecture.x86_64,
PackageGenerator.runningOnARM() ? CPUArchitecture.aarch64 : CPUArchitecture.x86_64,
fetchFromGithub,
);
}
Expand All @@ -54,8 +49,8 @@ class PackageGenerator {

PackageGenerator({required this.inputDir, required this.meta});

Future<void> generatePackage(Directory outputDir, CPUArchitecture arch,
bool fetchReleasesFromGithub) async {
Future<void> generatePackage(
Directory outputDir, CPUArchitecture arch, bool fetchReleasesFromGithub) async {
final tempDir = outputDir.createTempSync('flutter_generator_temp');
final appId = meta.appId;

Expand Down Expand Up @@ -90,8 +85,7 @@ class PackageGenerator {
}

final editedAppDataContent = AppDataModifier.replaceVersions(
origAppDataFile.readAsStringSync(),
await meta.getReleases(fetchReleasesFromGithub));
origAppDataFile.readAsStringSync(), await meta.getReleases(fetchReleasesFromGithub));

final editedAppDataFile = File('${tempDir.path}/$appId.appdata.xml');
editedAppDataFile.writeAsStringSync(editedAppDataContent);
Expand All @@ -107,21 +101,17 @@ class PackageGenerator {
final destDir = Directory('${tempDir.path}/bin');
destDir.createSync();

final baseFileName =
'${meta.lowercaseAppName}-linux-${arch.flatpakArchCode}';
final baseFileName = '${meta.lowercaseAppName}-linux-${arch.flatpakArchCode}';

final packagePath = '${outputDir.absolute.path}/$baseFileName.tar.gz';
Process.runSync(
'cp', ['-r', '${buildDir.absolute.path}/.', destDir.absolute.path]);
Process.runSync('tar', ['-czvf', packagePath, '.'],
workingDirectory: tempDir.absolute.path);
Process.runSync('cp', ['-r', '${buildDir.absolute.path}/.', destDir.absolute.path]);
Process.runSync('tar', ['-czvf', packagePath, '.'], workingDirectory: tempDir.absolute.path);
print('Generated $packagePath');

final preShasum = Process.runSync('shasum', ['-a', '256', packagePath]);
final sha256 = preShasum.stdout.toString().split(' ').first;

final shaFile = await File('${outputDir.path}/$baseFileName.sha256')
.writeAsString(sha256);
final shaFile = await File('${outputDir.path}/$baseFileName.sha256').writeAsString(sha256);
print('Generated ${shaFile.path}');

shaByArch.putIfAbsent(arch, () => sha256);
Expand All @@ -138,21 +128,17 @@ class PackageGenerator {

// updates releases in ${appName}.appdata.xml
class AppDataModifier {
static String replaceVersions(
String origAppDataContent, List<Release> versions) {
final joinedReleases = versions
.map((v) => '\t\t<release version="${v.version}" date="${v.date}" />')
.join('\n');
final releasesSection =
'<releases>\n$joinedReleases\n\t</releases>'; //todo check this
static String replaceVersions(String origAppDataContent, List<Release> versions) {
final joinedReleases =
versions.map((v) => '\t\t<release version="${v.version}" date="${v.date}" />').join('\n');
final releasesSection = '<releases>\n$joinedReleases\n\t</releases>'; //todo check this
if (origAppDataContent.contains('<releases')) {
return origAppDataContent
.replaceAll('\n', '<~>')
.replaceFirst(RegExp('<releases.*</releases>'), releasesSection)
.replaceAll('<~>', '\n');
} else {
return origAppDataContent.replaceFirst(
'</component>', '\n\t$releasesSection\n</component>');
return origAppDataContent.replaceFirst('</component>', '\n\t$releasesSection\n</component>');
}
}
}
55 changes: 18 additions & 37 deletions flatpak/scripts/flatpak_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class Icon {
_fileExtension = path.split('.').last;
}

String getFilename(String appId) => (type == _symbolicType)
? '$appId-symbolic.$_fileExtension'
: '$appId.$_fileExtension';
String getFilename(String appId) =>
(type == _symbolicType) ? '$appId-symbolic.$_fileExtension' : '$appId.$_fileExtension';
}

class GithubReleases {
Expand Down Expand Up @@ -74,8 +73,7 @@ class GithubReleases {
final releaseJsonContent = (await http.get(Uri(
scheme: 'https',
host: 'api.github.com',
path:
'/repos/$githubReleaseOrganization/$githubReleaseProject/releases')))
path: '/repos/$githubReleaseOrganization/$githubReleaseProject/releases')))
.body;
final decodedJson = jsonDecode(releaseJsonContent) as List;

Expand All @@ -86,10 +84,8 @@ class GithubReleases {
await Future.forEach<dynamic>(decodedJson, (dynamic releaseDynamic) async {
final releaseMap = releaseDynamic as Map;

final releaseDateAndTime =
DateTime.parse(releaseMap['published_at'] as String);
final releaseDateString =
releaseDateAndTime.toIso8601String().split('T').first;
final releaseDateAndTime = DateTime.parse(releaseMap['published_at'] as String);
final releaseDateString = releaseDateAndTime.toIso8601String().split('T').first;

if (latestReleaseAssetDate == null ||
(latestReleaseAssetDate?.compareTo(releaseDateAndTime) == -1)) {
Expand All @@ -100,8 +96,7 @@ class GithubReleases {
}
}

releases.add(Release(
version: releaseMap['name'] as String, date: releaseDateString));
releases.add(Release(version: releaseMap['name'] as String, date: releaseDateString));
});

if (releases.isNotEmpty) {
Expand All @@ -120,8 +115,7 @@ class GithubReleases {
final downloadUrl = amMap['browser_download_url'] as String;
final filename = amMap['name'] as String;
final fileExtension = filename.substring(filename.indexOf('.') + 1);
final filenameWithoutExtension =
filename.substring(0, filename.indexOf('.'));
final filenameWithoutExtension = filename.substring(0, filename.indexOf('.'));

final arch = filenameWithoutExtension.endsWith('aarch64')
? CPUArchitecture.aarch64
Expand Down Expand Up @@ -218,8 +212,7 @@ class FlatpakMeta {
: _localReleases = localReleases,
_localReleaseAssets = localReleaseAssets {
if (githubReleaseOrganization != null && githubReleaseProject != null) {
_githubReleases =
GithubReleases(githubReleaseOrganization!, githubReleaseProject!);
_githubReleases = GithubReleases(githubReleaseOrganization!, githubReleaseProject!);
}
}

Expand All @@ -232,15 +225,13 @@ class FlatpakMeta {
return await _githubReleases!.getReleases();
} else {
if (_localReleases == null) {
throw Exception(
'Metadata must include releases if not fetching releases from Github.');
throw Exception('Metadata must include releases if not fetching releases from Github.');
}
return _localReleases!;
}
}

Future<List<ReleaseAsset>?> getReleaseAssets(
bool fetchReleasesFromGithub) async {
Future<List<ReleaseAsset>?> getReleaseAssets(bool fetchReleasesFromGithub) async {
if (fetchReleasesFromGithub) {
if (_githubReleases == null) {
throw Exception(
Expand All @@ -249,8 +240,7 @@ class FlatpakMeta {
return _githubReleases!.getLatestReleaseAssets();
} else {
if (_localReleases == null) {
throw Exception(
'Metadata must include releases if not fetching releases from Github.');
throw Exception('Metadata must include releases if not fetching releases from Github.');
}
return _localReleaseAssets;
}
Expand All @@ -262,17 +252,13 @@ class FlatpakMeta {
return FlatpakMeta(
appId: json['appId'] as String,
lowercaseAppName: json['lowercaseAppName'] as String,
githubReleaseOrganization:
json['githubReleaseOrganization'] as String?,
githubReleaseOrganization: json['githubReleaseOrganization'] as String?,
githubReleaseProject: json['githubReleaseProject'] as String?,
localReleases: (json['localReleases'] as List?)?.map((dynamic r) {
final rMap = r as Map;
return Release(
version: rMap['version'] as String,
date: rMap['date'] as String);
return Release(version: rMap['version'] as String, date: rMap['date'] as String);
}).toList(),
localReleaseAssets:
(json['localReleaseAssets'] as List?)?.map((dynamic ra) {
localReleaseAssets: (json['localReleaseAssets'] as List?)?.map((dynamic ra) {
final raMap = ra as Map;
final archString = raMap['arch'] as String;
final arch = (archString == CPUArchitecture.x86_64.flatpakArchCode)
Expand All @@ -284,10 +270,8 @@ class FlatpakMeta {
throw Exception(
'Architecture must be either "${CPUArchitecture.x86_64.flatpakArchCode}" or "${CPUArchitecture.aarch64.flatpakArchCode}"');
}
final tarballPath =
'${jsonFile.parent.path}/${raMap['tarballPath'] as String}';
final preShasum =
Process.runSync('shasum', ['-a', '256', tarballPath]);
final tarballPath = '${jsonFile.parent.path}/${raMap['tarballPath'] as String}';
final preShasum = Process.runSync('shasum', ['-a', '256', tarballPath]);
final shasum = preShasum.stdout.toString().split(' ').first;
if (preShasum.exitCode != 0) {
throw Exception(preShasum.stderr);
Expand All @@ -302,17 +286,14 @@ class FlatpakMeta {
appDataPath: json['appDataPath'] as String,
desktopPath: json['desktopPath'] as String,
icons: (json['icons'] as Map).entries.map((mapEntry) {
return Icon(
type: mapEntry.key as String, path: mapEntry.value as String);
return Icon(type: mapEntry.key as String, path: mapEntry.value as String);
}).toList(),
freedesktopRuntime: json['freedesktopRuntime'] as String,
buildCommandsAfterUnpack: (json['buildCommandsAfterUnpack'] as List?)
?.map((dynamic bc) => bc as String)
.toList(),
extraModules: json['extraModules'] as List?,
finishArgs: (json['finishArgs'] as List)
.map((dynamic fa) => fa as String)
.toList());
finishArgs: (json['finishArgs'] as List).map((dynamic fa) => fa as String).toList());
} catch (e) {
throw Exception('Could not parse JSON file, due to this error:\n$e');
}
Expand Down
18 changes: 6 additions & 12 deletions flatpak/scripts/manifest_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ void main(List<String> arguments) async {
'You must run this script with a metadata file argument, using the --meta flag.');
}
if (arguments.length == metaIndex + 1) {
throw Exception(
'The --meta flag must be followed by the path to the metadata file.');
throw Exception('The --meta flag must be followed by the path to the metadata file.');
}

final metaFile = File(arguments[metaIndex + 1]);
Expand All @@ -27,20 +26,17 @@ void main(List<String> arguments) async {

final fetchFromGithub = arguments.contains('--github');

final outputDir =
Directory('${Directory.current.path}/flatpak_generator_exports');
final outputDir = Directory('${Directory.current.path}/flatpak_generator_exports');
outputDir.createSync();

final manifestGenerator = FlatpakManifestGenerator(meta);
final manifestContent =
await manifestGenerator.generateFlatpakManifest(fetchFromGithub);
final manifestContent = await manifestGenerator.generateFlatpakManifest(fetchFromGithub);
final manifestPath = '${outputDir.path}/${meta.appId}.json';
final manifestFile = File(manifestPath);
manifestFile.writeAsStringSync(manifestContent);
print('Generated $manifestPath');

final flathubJsonContent =
await manifestGenerator.generateFlathubJson(fetchFromGithub);
final flathubJsonContent = await manifestGenerator.generateFlathubJson(fetchFromGithub);
if (flathubJsonContent != null) {
final flathubJsonPath = '${outputDir.path}/flathub.json';
final flathubJsonFile = File(flathubJsonPath);
Expand Down Expand Up @@ -119,8 +115,7 @@ class FlatpakManifestGenerator {

const encoder = JsonEncoder.withIndent(' ');

final onlyArchListInput =
fetchFromGithub ? _githubArchSupport! : _localArchSupport!;
final onlyArchListInput = fetchFromGithub ? _githubArchSupport! : _localArchSupport!;

final onlyArchList = List<String>.empty(growable: true);
for (final e in onlyArchListInput.entries) {
Expand All @@ -136,8 +131,7 @@ class FlatpakManifestGenerator {
}
}

void _lazyGenerateArchSupportMap(
bool fetchFromGithub, List<ReleaseAsset> assets) {
void _lazyGenerateArchSupportMap(bool fetchFromGithub, List<ReleaseAsset> assets) {
if (fetchFromGithub) {
if (_githubArchSupport == null) {
_githubArchSupport = <CPUArchitecture, bool>{
Expand Down
9 changes: 3 additions & 6 deletions integration_test/1_dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,17 @@ Widget createDashboardScreen({locale = 'en'}) {
}
]
};
when(mockWorkoutProvider.fetchSessionData())
.thenAnswer((a) => Future.value(logs));
when(mockWorkoutProvider.fetchSessionData()).thenAnswer((a) => Future.value(logs));

final mockNutritionProvider = MockNutritionPlansProvider();
when(mockNutritionProvider.currentPlan)
.thenAnswer((realInvocation) => getNutritionalPlan());
when(mockNutritionProvider.currentPlan).thenAnswer((realInvocation) => getNutritionalPlan());
when(mockNutritionProvider.items).thenReturn([getNutritionalPlan()]);

final mockWeightProvider = MockBodyWeightProvider();
when(mockWeightProvider.items).thenReturn(getWeightEntries());

final mockMeasurementProvider = MockMeasurementProvider();
when(mockMeasurementProvider.categories)
.thenReturn(getMeasurementCategories());
when(mockMeasurementProvider.categories).thenReturn(getMeasurementCategories());

return MultiProvider(
providers: [
Expand Down
3 changes: 1 addition & 2 deletions integration_test/2_workout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Widget createWorkoutDetailScreen({locale = 'en'}) {
final mockWorkoutProvider = MockWorkoutPlansProvider();
final workout = getWorkout();
when(mockWorkoutProvider.activePlan).thenReturn(workout);
when(mockWorkoutProvider.fetchAndSetWorkoutPlanFull(1))
.thenAnswer((_) => Future.value(workout));
when(mockWorkoutProvider.fetchAndSetWorkoutPlanFull(1)).thenAnswer((_) => Future.value(workout));

return MultiProvider(
providers: [
Expand Down
6 changes: 2 additions & 4 deletions integration_test/3_gym_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ Widget createGymModeScreen({locale = 'en'}) {

final mockExerciseProvider = MockExercisesProvider();

when(mockExerciseProvider.findExerciseBaseById(1))
.thenReturn(bases[0]); // bench press
when(mockExerciseProvider.findExerciseBaseById(6))
.thenReturn(bases[5]); // side raises
when(mockExerciseProvider.findExerciseBaseById(1)).thenReturn(bases[0]); // bench press
when(mockExerciseProvider.findExerciseBaseById(6)).thenReturn(bases[5]); // side raises
//when(mockExerciseProvider.findExerciseBaseById(2)).thenReturn(bases[1]); // crunches
//when(mockExerciseProvider.findExerciseBaseById(3)).thenReturn(bases[2]); // dead lift

Expand Down
3 changes: 1 addition & 2 deletions integration_test/4_measurements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import '../test_data/measurements.dart';

Widget createMeasurementScreen({locale = 'en'}) {
final mockMeasurementProvider = MockMeasurementProvider();
when(mockMeasurementProvider.categories)
.thenReturn(getMeasurementCategories());
when(mockMeasurementProvider.categories).thenReturn(getMeasurementCategories());

return MultiProvider(
providers: [
Expand Down
Loading

0 comments on commit 65ba227

Please sign in to comment.