From f8a5ca4bebfbec2ff418724efb488c4580ef4d20 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Thu, 28 Apr 2022 13:12:31 +0600 Subject: [PATCH] application about menu update usePackageInfo hook getLyrics bug fixes --- lib/components/Lyrics/SyncedLyrics.dart | 14 ++++- lib/components/Settings.dart | 10 +++- lib/helpers/getLyrics.dart | 4 +- lib/hooks/usePackageInfo.dart | 79 +++++++++++++++++++++++++ pubspec.lock | 42 +++++++++++++ pubspec.yaml | 1 + 6 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 lib/hooks/usePackageInfo.dart diff --git a/lib/components/Lyrics/SyncedLyrics.dart b/lib/components/Lyrics/SyncedLyrics.dart index 7724a7db..1713834e 100644 --- a/lib/components/Lyrics/SyncedLyrics.dart +++ b/lib/components/Lyrics/SyncedLyrics.dart @@ -79,8 +79,18 @@ class SyncedLyrics extends HookConsumerWidget { }, ), ], - content: const Text( - "The found lyrics might not be properly synced. Do you want to default to static (genius.com) lyrics?"), + content: Column( + mainAxisSize: MainAxisSize.min, + children: const [ + Text( + "The found lyrics might not be properly synced. Do you want to default to static (genius.com) lyrics?", + ), + SizedBox(height: 10), + Text( + "Hint: Wait for a moment to see if the lyric actually sync. Sometimes it may sync.", + ), + ], + ), ); }, ); diff --git a/lib/components/Settings.dart b/lib/components/Settings.dart index 49a00b1e..d09739bd 100644 --- a/lib/components/Settings.dart +++ b/lib/components/Settings.dart @@ -8,6 +8,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:spotube/components/Settings/SettingsHotkeyTile.dart'; import 'package:spotube/components/Shared/Hyperlink.dart'; import 'package:spotube/components/Shared/PageWindowTitleBar.dart'; +import 'package:spotube/hooks/usePackageInfo.dart'; import 'package:spotube/models/LocalStorageKeys.dart'; import 'package:spotube/models/SpotifyMarkets.dart'; import 'package:spotube/provider/Auth.dart'; @@ -33,6 +34,11 @@ class Settings extends HookConsumerWidget { preferences.setYtSearchFormat(ytSearchFormatController.value.text); }); + final packageInfo = usePackageInfo( + appName: 'Spotube', + packageName: 'spotube', + ); + return SafeArea( child: Scaffold( appBar: PageWindowTitleBar( @@ -252,7 +258,9 @@ class Settings extends HookConsumerWidget { ); }), const SizedBox(height: 40), - const Text("Spotube v2.0.0"), + Text( + "Spotube v${packageInfo.version}", + ), const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/helpers/getLyrics.dart b/lib/helpers/getLyrics.dart index ac8aa7ee..26a36ec9 100644 --- a/lib/helpers/getLyrics.dart +++ b/lib/helpers/getLyrics.dart @@ -130,7 +130,7 @@ Future getLyrics( if (results == null) return null; final worthyOne = results .map((result) { - final gTitle = (result["title"] as String).toLowerCase(); + final gTitle = (result["full_title"] as String).toLowerCase(); int points = 0; final hasTitle = gTitle.contains(title.toLowerCase()); final hasAllArtists = @@ -144,7 +144,7 @@ Future getLyrics( .sorted( (a, b) => ((b["points"] as int).compareTo(a["points"] as int)), ) - .first; + .first["result"]; String? lyrics = await extractLyrics(Uri.parse(worthyOne["url"])); return lyrics; diff --git a/lib/hooks/usePackageInfo.dart b/lib/hooks/usePackageInfo.dart new file mode 100644 index 00000000..9b142ced --- /dev/null +++ b/lib/hooks/usePackageInfo.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + +PackageInfo usePackageInfo({ + /// The app name. `CFBundleDisplayName` on iOS, `application/label` on Android. + String appName = 'Unknown', + + /// The package name. `bundleIdentifier` on iOS, `getPackageName` on Android. + String packageName = 'Unknown', + + /// The package version. `CFBundleShortVersionString` on iOS, `versionName` on Android. + String version = 'Unknown', + + /// The build number. `CFBundleVersion` on iOS, `versionCode` on Android. + String buildNumber = 'Unknown', + + /// The build signature. Empty string on iOS, signing key signature (hex) on Android. + String buildSignature = '', + List? keys, +}) { + return use( + _PackageInfoHook( + appName: appName, + buildNumber: buildNumber, + packageName: packageName, + version: version, + buildSignature: buildSignature, + keys: keys, + ), + ); +} + +class _PackageInfoHook extends Hook { + final String appName; + final String packageName; + final String version; + final String buildNumber; + final String buildSignature; + + const _PackageInfoHook({ + required this.appName, + required this.packageName, + required this.version, + required this.buildNumber, + this.buildSignature = '', + List? keys, + }) : super(keys: keys); + + @override + HookState> createState() => + _PackageInfoHookState(); +} + +class _PackageInfoHookState + extends HookState> { + late PackageInfo info = PackageInfo( + appName: hook.appName, + buildNumber: hook.buildNumber, + packageName: hook.packageName, + version: hook.version, + ); + + @override + void initHook() { + PackageInfo.fromPlatform().then((packageInfo) { + setState(() { + info = packageInfo; + }); + }); + super.initHook(); + } + + @override + PackageInfo build(BuildContext context) => info; + + @override + String get debugLabel => 'usePagingController'; +} diff --git a/pubspec.lock b/pubspec.lock index 1c098b39..c418bffd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -450,6 +450,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.2" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.2" + package_info_plus_linux: + dependency: transitive + description: + name: package_info_plus_linux + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + package_info_plus_macos: + dependency: transitive + description: + name: package_info_plus_macos + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + package_info_plus_web: + dependency: transitive + description: + name: package_info_plus_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + package_info_plus_windows: + dependency: transitive + description: + name: package_info_plus_windows + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" palette_generator: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index ce049541..8a7add39 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -60,6 +60,7 @@ dependencies: permission_handler: ^9.2.0 marquee: ^2.2.1 scroll_to_index: ^2.1.1 + package_info_plus: ^1.4.2 dev_dependencies: flutter_test: