This commit is contained in:
Thibault Deckers 2023-10-24 18:12:22 +03:00
parent 7b9213e82e
commit 90250e338f
7 changed files with 73 additions and 97 deletions

View file

@ -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<void> 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');

View file

@ -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,
);

View file

@ -188,7 +188,7 @@ class XMP {
static Future<String?> edit(
String? xmpString,
Future<String> Function() toolkit,
String toolkit,
bool Function(List<XmlNode> 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();
}

View file

@ -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<int> _railIndexNotifier = ValueNotifier(0);
late Future<PackageInfo> _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<PackageInfo>(
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:

View file

@ -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<AppReference> 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<Widget> buildLinks(BuildContext context) {
final l10n = context.l10n;
@ -55,60 +94,3 @@ class AppReference extends StatefulWidget {
);
}
}
class _AppReferenceState extends State<AppReference> {
late Future<PackageInfo> _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<PackageInfo>(
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,
),
],
);
},
);
}
}

View file

@ -148,9 +148,9 @@ class _BugReportState extends State<BugReport> 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}',

View file

@ -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,
)),