Improve icon loading after last commit

This commit is contained in:
Imran Remtulla
2024-05-23 21:02:50 -04:00
parent 5edaf1306d
commit 6c5e5043a4
4 changed files with 40 additions and 21 deletions

View File

@@ -227,9 +227,9 @@ class _AppPageState extends State<AppPage> {
children: [ children: [
const SizedBox(height: 20), const SizedBox(height: 20),
FutureBuilder( FutureBuilder(
future: app?.installedInfo?.applicationInfo?.getAppIcon(), future: appsProvider.updateAppIcon(app?.app.id),
builder: (ctx, val) { builder: (ctx, val) {
return val.data != null return app?.icon != null
? Row( ? Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
@@ -238,7 +238,7 @@ class _AppPageState extends State<AppPage> {
? null ? null
: () => pm.openApp(app.app.id), : () => pm.openApp(app.app.id),
child: Image.memory( child: Image.memory(
val.data!, app!.icon!,
height: 150, height: 150,
gaplessPlayback: true, gaplessPlayback: true,
), ),

View File

@@ -407,12 +407,11 @@ class AppsPageState extends State<AppsPage> {
getAppIcon(int appIndex) { getAppIcon(int appIndex) {
return FutureBuilder( return FutureBuilder(
future: future: appsProvider.updateAppIcon(listedApps[appIndex].app.id),
listedApps[appIndex].installedInfo?.applicationInfo?.getAppIcon(),
builder: (ctx, val) { builder: (ctx, val) {
return val.data != null return listedApps[appIndex].icon != null
? Image.memory( ? Image.memory(
val.data!, listedApps[appIndex].icon!,
gaplessPlayback: true, gaplessPlayback: true,
) )
: Row( : Row(

View File

@@ -42,10 +42,11 @@ class AppInMemory {
late App app; late App app;
double? downloadProgress; double? downloadProgress;
PackageInfo? installedInfo; PackageInfo? installedInfo;
Uint8List? icon;
AppInMemory(this.app, this.downloadProgress, this.installedInfo); AppInMemory(this.app, this.downloadProgress, this.installedInfo, this.icon);
AppInMemory deepCopy() => AppInMemory deepCopy() =>
AppInMemory(app.deepCopy(), downloadProgress, installedInfo); AppInMemory(app.deepCopy(), downloadProgress, installedInfo, icon);
String get name => app.overrideName ?? app.finalName; String get name => app.overrideName ?? app.finalName;
} }
@@ -1121,7 +1122,8 @@ class AppsProvider with ChangeNotifier {
// FOURTH, DISABLE VERSION DETECTION IF ENABLED AND THE REPORTED/REAL INSTALLED VERSIONS ARE NOT STANDARDIZED // FOURTH, DISABLE VERSION DETECTION IF ENABLED AND THE REPORTED/REAL INSTALLED VERSIONS ARE NOT STANDARDIZED
if (installedInfo != null && if (installedInfo != null &&
versionDetectionIsStandard && versionDetectionIsStandard &&
!isVersionDetectionPossible(AppInMemory(app, null, installedInfo))) { !isVersionDetectionPossible(
AppInMemory(app, null, installedInfo, null))) {
app.additionalSettings['versionDetection'] = false; app.additionalSettings['versionDetection'] = false;
logs.add('Could not reconcile version formats for: ${app.id}'); logs.add('Could not reconcile version formats for: ${app.id}');
modded = true; modded = true;
@@ -1197,9 +1199,9 @@ class AppsProvider with ChangeNotifier {
// Save the app to the in-memory list without grabbing any OS info first // Save the app to the in-memory list without grabbing any OS info first
apps.update( apps.update(
app.id, app.id,
(value) => (value) => AppInMemory(
AppInMemory(app!, value.downloadProgress, value.installedInfo), app!, value.downloadProgress, value.installedInfo, value.icon),
ifAbsent: () => AppInMemory(app!, null, null)); ifAbsent: () => AppInMemory(app!, null, null, null));
notifyListeners(); notifyListeners();
try { try {
// Try getting the app's source to ensure no invalid apps get loaded // Try getting the app's source to ensure no invalid apps get loaded
@@ -1225,9 +1227,9 @@ class AppsProvider with ChangeNotifier {
// Update the app in memory with install info and corrections // Update the app in memory with install info and corrections
apps.update( apps.update(
app.id, app.id,
(value) => (value) => AppInMemory(
AppInMemory(app!, value.downloadProgress, installedInfo), app!, value.downloadProgress, installedInfo, value.icon),
ifAbsent: () => AppInMemory(app!, null, installedInfo)); ifAbsent: () => AppInMemory(app!, null, installedInfo, null));
notifyListeners(); notifyListeners();
} catch (e) { } catch (e) {
errors.add([app!.id, app.finalName, e.toString()]); errors.add([app!.id, app.finalName, e.toString()]);
@@ -1251,6 +1253,22 @@ class AppsProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> updateAppIcon(String? appId) async {
if (apps[appId]?.icon == null) {
var icon =
(await apps[appId]?.installedInfo?.applicationInfo?.getAppIcon());
if (icon != null) {
apps.update(
apps[appId]!.app.id,
(value) => AppInMemory(apps[appId]!.app, value.downloadProgress,
value.installedInfo, icon),
ifAbsent: () => AppInMemory(
apps[appId]!.app, null, apps[appId]?.installedInfo, icon));
notifyListeners();
}
}
}
Future<void> saveApps(List<App> apps, Future<void> saveApps(List<App> apps,
{bool attemptToCorrectInstallStatus = true, {bool attemptToCorrectInstallStatus = true,
bool onlyIfExists = true}) async { bool onlyIfExists = true}) async {
@@ -1258,6 +1276,7 @@ class AppsProvider with ChangeNotifier {
await Future.wait(apps.map((a) async { await Future.wait(apps.map((a) async {
var app = a.deepCopy(); var app = a.deepCopy();
PackageInfo? info = await getInstalledInfo(app.id); PackageInfo? info = await getInstalledInfo(app.id);
var icon = await info?.applicationInfo?.getAppIcon();
app.name = await (info?.applicationInfo?.getAppLabel()) ?? app.name; app.name = await (info?.applicationInfo?.getAppLabel()) ?? app.name;
if (attemptToCorrectInstallStatus) { if (attemptToCorrectInstallStatus) {
app = getCorrectedInstallStatusAppIfPossible(app, info) ?? app; app = getCorrectedInstallStatusAppIfPossible(app, info) ?? app;
@@ -1267,9 +1286,10 @@ class AppsProvider with ChangeNotifier {
.writeAsStringSync(jsonEncode(app.toJson())); .writeAsStringSync(jsonEncode(app.toJson()));
} }
try { try {
this.apps.update( this.apps.update(app.id,
app.id, (value) => AppInMemory(app, value.downloadProgress, info), (value) => AppInMemory(app, value.downloadProgress, info, icon),
ifAbsent: onlyIfExists ? null : () => AppInMemory(app, null, info)); ifAbsent:
onlyIfExists ? null : () => AppInMemory(app, null, info, icon));
} catch (e) { } catch (e) {
if (e is! ArgumentError || e.name != 'key') { if (e is! ArgumentError || e.name != 'key') {
rethrow; rethrow;

View File

@@ -977,10 +977,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: webview_flutter name: webview_flutter
sha256: "25e1b6e839e8cbfbd708abc6f85ed09d1727e24e08e08c6b8590d7c65c9a8932" sha256: "6869c8786d179f929144b4a1f86e09ac0eddfe475984951ea6c634774c16b522"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.7.0" version: "4.8.0"
webview_flutter_android: webview_flutter_android:
dependency: transitive dependency: transitive
description: description: