From 90250e338fbeafd0ef479cd5a693ee71010d506a Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Tue, 24 Oct 2023 18:12:22 +0300 Subject: [PATCH] minor --- lib/model/device.dart | 10 +- .../entry/extensions/metadata_edition.dart | 4 +- lib/utils/xmp_utils.dart | 4 +- lib/widgets/about/about_tv_page.dart | 16 +-- lib/widgets/about/app_ref.dart | 102 ++++++++---------- lib/widgets/about/bug_report.dart | 4 +- test/utils/xmp_utils_test.dart | 30 +++--- 7 files changed, 73 insertions(+), 97 deletions(-) diff --git a/lib/model/device.dart b/lib/model/device.dart index c70c1d8ed..e2c687e21 100644 --- a/lib/model/device.dart +++ b/lib/model/device.dart @@ -8,11 +8,15 @@ import 'package:package_info_plus/package_info_plus.dart'; final Device device = Device._private(); class Device { - late final String _userAgent; + late final String _packageName, _packageVersion, _userAgent; late final bool _canAuthenticateUser, _canGrantDirectoryAccess, _canPinShortcut; late final bool _canRenderFlagEmojis, _canRenderSubdivisionFlagEmojis, _canRequestManageMedia, _canSetLockScreenWallpaper, _canUseCrypto; late final bool _hasGeocoder, _isDynamicColorAvailable, _isTelevision, _showPinShortcutFeedback, _supportEdgeToEdgeUIMode, _supportPictureInPicture; + String get packageName => _packageName; + + String get packageVersion => _packageVersion; + String get userAgent => _userAgent; bool get canAuthenticateUser => _canAuthenticateUser; @@ -49,7 +53,9 @@ class Device { Future init() async { final packageInfo = await PackageInfo.fromPlatform(); - _userAgent = '${packageInfo.packageName}/${packageInfo.version}'; + _packageName = packageInfo.packageName; + _packageVersion = packageInfo.version; + _userAgent = '$_packageName/$_packageVersion'; final androidInfo = await DeviceInfoPlugin().androidInfo; _isTelevision = androidInfo.systemFeatures.contains('android.software.leanback'); diff --git a/lib/model/entry/extensions/metadata_edition.dart b/lib/model/entry/extensions/metadata_edition.dart index e0ddc829f..cf92324c9 100644 --- a/lib/model/entry/extensions/metadata_edition.dart +++ b/lib/model/entry/extensions/metadata_edition.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:aves/convert/convert.dart'; +import 'package:aves/model/device.dart'; import 'package:aves/model/entry/entry.dart'; import 'package:aves/model/entry/extensions/catalog.dart'; import 'package:aves/model/entry/extensions/props.dart'; @@ -18,7 +19,6 @@ import 'package:aves_model/aves_model.dart'; import 'package:flutter/foundation.dart'; import 'package:intl/intl.dart'; import 'package:latlong2/latlong.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:xml/xml.dart'; extension ExtraAvesEntryMetadataEdition on AvesEntry { @@ -569,7 +569,7 @@ extension ExtraAvesEntryMetadataEdition on AvesEntry { final editedXmpString = await XMP.edit( xmpString, - () => PackageInfo.fromPlatform().then((v) => 'Aves v${v.version}'), + 'Aves v${device.packageVersion}', apply, ); diff --git a/lib/utils/xmp_utils.dart b/lib/utils/xmp_utils.dart index 0953bac31..72b120b32 100644 --- a/lib/utils/xmp_utils.dart +++ b/lib/utils/xmp_utils.dart @@ -188,7 +188,7 @@ class XMP { static Future edit( String? xmpString, - Future Function() toolkit, + String toolkit, bool Function(List descriptions) apply, { DateTime? modifyDate, }) async { @@ -202,7 +202,7 @@ class XMP { builder.element(XmpElements.xXmpmeta, namespace: nsX, namespaces: { nsX: prefixOf(nsX), }, attributes: { - '${prefixOf(nsX)}$propNamespaceSeparator${XmpAttributes.xXmptk}': await toolkit(), + '${prefixOf(nsX)}$propNamespaceSeparator${XmpAttributes.xXmptk}': toolkit, }); xmpDoc = builder.buildDocument(); } diff --git a/lib/widgets/about/about_tv_page.dart b/lib/widgets/about/about_tv_page.dart index 10875ea09..a1a944caf 100644 --- a/lib/widgets/about/about_tv_page.dart +++ b/lib/widgets/about/about_tv_page.dart @@ -1,3 +1,4 @@ +import 'package:aves/model/device.dart'; import 'package:aves/widgets/about/app_ref.dart'; import 'package:aves/widgets/about/credits.dart'; import 'package:aves/widgets/about/translators.dart'; @@ -10,7 +11,6 @@ import 'package:aves/widgets/common/extensions/build_context.dart'; import 'package:aves/widgets/common/identity/buttons/outlined_button.dart'; import 'package:aves/widgets/navigation/tv_rail.dart'; import 'package:flutter/material.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; class AboutTvPage extends StatelessWidget { @@ -72,16 +72,9 @@ enum _Section { links, credits, translators, licenses } class _ContentState extends State<_Content> { final FocusNode _railFocusNode = FocusNode(); final ValueNotifier _railIndexNotifier = ValueNotifier(0); - late Future _packageInfoLoader; static const double railWidth = 256; - @override - void initState() { - super.initState(); - _packageInfoLoader = PackageInfo.fromPlatform(); - } - @override void dispose() { _railIndexNotifier.dispose(); @@ -149,12 +142,7 @@ class _ContentState extends State<_Content> { Widget _getTitle(_Section key) { switch (key) { case _Section.links: - return FutureBuilder( - future: _packageInfoLoader, - builder: (context, snapshot) { - return Text('${context.l10n.appName} ${snapshot.data?.version}'); - }, - ); + return Text('${context.l10n.appName} ${device.packageVersion}'); case _Section.credits: return Text(context.l10n.aboutCreditsSectionTitle); case _Section.translators: diff --git a/lib/widgets/about/app_ref.dart b/lib/widgets/about/app_ref.dart index 99d814f00..228a62a13 100644 --- a/lib/widgets/about/app_ref.dart +++ b/lib/widgets/about/app_ref.dart @@ -1,20 +1,59 @@ import 'dart:ui'; +import 'package:aves/model/device.dart'; import 'package:aves/theme/icons.dart'; import 'package:aves/widgets/about/policy_page.dart'; import 'package:aves/widgets/common/basic/link_chip.dart'; import 'package:aves/widgets/common/extensions/build_context.dart'; import 'package:aves/widgets/common/identity/aves_logo.dart'; import 'package:flutter/material.dart'; -import 'package:package_info_plus/package_info_plus.dart'; -class AppReference extends StatefulWidget { +class AppReference extends StatelessWidget { static const avesGithub = 'https://github.com/deckerst/aves'; + static const _appTitleStyle = TextStyle( + fontSize: 20, + fontWeight: FontWeight.normal, + letterSpacing: 1.0, + fontFeatures: [FontFeature.enable('smcp')], + ); + const AppReference({super.key}); @override - State createState() => _AppReferenceState(); + Widget build(BuildContext context) { + return Center( + child: Column( + children: [ + _buildAvesLine(context), + const SizedBox(height: 16), + Wrap( + alignment: WrapAlignment.center, + spacing: 16, + crossAxisAlignment: WrapCrossAlignment.center, + children: AppReference.buildLinks(context), + ), + ], + ), + ); + } + + Widget _buildAvesLine(BuildContext context) { + final textScaleFactor = MediaQuery.textScaleFactorOf(context); + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + AvesLogo( + size: _appTitleStyle.fontSize! * textScaleFactor * 1.3, + ), + const SizedBox(width: 8), + Text( + '${context.l10n.appName} ${device.packageVersion}', + style: _appTitleStyle, + ), + ], + ); + } static List buildLinks(BuildContext context) { final l10n = context.l10n; @@ -55,60 +94,3 @@ class AppReference extends StatefulWidget { ); } } - -class _AppReferenceState extends State { - late Future _packageInfoLoader; - - static const _appTitleStyle = TextStyle( - fontSize: 20, - fontWeight: FontWeight.normal, - letterSpacing: 1.0, - fontFeatures: [FontFeature.enable('smcp')], - ); - - @override - void initState() { - super.initState(); - _packageInfoLoader = PackageInfo.fromPlatform(); - } - - @override - Widget build(BuildContext context) { - return Center( - child: Column( - children: [ - _buildAvesLine(), - const SizedBox(height: 16), - Wrap( - alignment: WrapAlignment.center, - spacing: 16, - crossAxisAlignment: WrapCrossAlignment.center, - children: AppReference.buildLinks(context), - ), - ], - ), - ); - } - - Widget _buildAvesLine() { - return FutureBuilder( - future: _packageInfoLoader, - builder: (context, snapshot) { - final textScaleFactor = MediaQuery.textScaleFactorOf(context); - return Row( - mainAxisSize: MainAxisSize.min, - children: [ - AvesLogo( - size: _appTitleStyle.fontSize! * textScaleFactor * 1.3, - ), - const SizedBox(width: 8), - Text( - '${context.l10n.appName} ${snapshot.data?.version}', - style: _appTitleStyle, - ), - ], - ); - }, - ); - } -} diff --git a/lib/widgets/about/bug_report.dart b/lib/widgets/about/bug_report.dart index 6c5ad4a43..6a3f39ade 100644 --- a/lib/widgets/about/bug_report.dart +++ b/lib/widgets/about/bug_report.dart @@ -148,9 +148,9 @@ class _BugReportState extends State with FeedbackMixin { final storageVolumes = await storageService.getStorageVolumes(); final storageGrants = await storageService.getGrantedDirectories(); return [ - 'Package: ${packageInfo.packageName}', + 'Package: ${device.packageName}', 'Installer: ${packageInfo.installerStore}', - 'Aves version: ${packageInfo.version}-$flavor, build ${packageInfo.buildNumber}', + 'Aves version: ${device.packageVersion}-$flavor, build ${packageInfo.buildNumber}', 'Flutter: ${version['channel']} ${version['frameworkVersion']}', 'Android version: ${androidInfo.version.release}, API ${androidInfo.version.sdkInt}', 'Android build: ${androidInfo.display}', diff --git a/test/utils/xmp_utils_test.dart b/test/utils/xmp_utils_test.dart index 0374f1467..d45e13e74 100644 --- a/test/utils/xmp_utils_test.dart +++ b/test/utils/xmp_utils_test.dart @@ -146,7 +146,7 @@ void main() { expect( _toExpect(await XMP.edit( null, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {'one', 'two'}), modifyDate: modifyDate, )), @@ -177,7 +177,7 @@ void main() { expect( _toExpect(await XMP.edit( inMultiDescriptionRatings, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {'one', 'two'}), modifyDate: modifyDate, )), @@ -212,7 +212,7 @@ void main() { expect( _toExpect(await XMP.edit( inSubjects, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {'one', 'two'}), modifyDate: modifyDate, )), @@ -240,7 +240,7 @@ void main() { expect( _toExpect(await XMP.edit( inSubjects, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {}), )), _toExpect(null)); @@ -253,7 +253,7 @@ void main() { expect( _toExpect(await XMP.edit( inSubjectsCreator, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {}), modifyDate: modifyDate, )), @@ -283,7 +283,7 @@ void main() { expect( _toExpect(await XMP.edit( null, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3), modifyDate: modifyDate, )), @@ -307,7 +307,7 @@ void main() { expect( _toExpect(await XMP.edit( inMultiDescriptionRatings, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3), modifyDate: modifyDate, )), @@ -333,7 +333,7 @@ void main() { expect( _toExpect(await XMP.edit( inRatingAttribute, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3), modifyDate: modifyDate, )), @@ -357,7 +357,7 @@ void main() { expect( _toExpect(await XMP.edit( inRatingElement, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3), modifyDate: modifyDate, )), @@ -381,7 +381,7 @@ void main() { expect( _toExpect(await XMP.edit( inSubjects, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3), modifyDate: modifyDate, )), @@ -411,7 +411,7 @@ void main() { expect( _toExpect(await XMP.edit( inSubjects, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, null), modifyDate: modifyDate, )), @@ -424,7 +424,7 @@ void main() { expect( _toExpect(await XMP.edit( inMotionPhotoMicroVideo, - () async => toolkit, + toolkit, ExtraAvesEntryMetadataEdition.removeContainerXmp, modifyDate: modifyDate, )), @@ -437,7 +437,7 @@ void main() { expect( _toExpect(await XMP.edit( inMotionPhotoContainer, - () async => toolkit, + toolkit, ExtraAvesEntryMetadataEdition.removeContainerXmp, modifyDate: modifyDate, )), @@ -450,7 +450,7 @@ void main() { expect( _toExpect(await XMP.edit( inSubjects, - () async => toolkit, + toolkit, ExtraAvesEntryMetadataEdition.removeContainerXmp, modifyDate: modifyDate, )), @@ -463,7 +463,7 @@ void main() { expect( _toExpect(await XMP.edit( inMultiDescriptionRatings, - () async => toolkit, + toolkit, (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, null), modifyDate: modifyDate, )),