mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 21:43:29 +01:00 
			
		
		
		
	Improve icon loading after last commit
This commit is contained in:
		| @@ -227,9 +227,9 @@ class _AppPageState extends State<AppPage> { | ||||
|           children: [ | ||||
|             const SizedBox(height: 20), | ||||
|             FutureBuilder( | ||||
|                 future: app?.installedInfo?.applicationInfo?.getAppIcon(), | ||||
|                 future: appsProvider.updateAppIcon(app?.app.id), | ||||
|                 builder: (ctx, val) { | ||||
|                   return val.data != null | ||||
|                   return app?.icon != null | ||||
|                       ? Row( | ||||
|                           mainAxisAlignment: MainAxisAlignment.center, | ||||
|                           children: [ | ||||
| @@ -238,7 +238,7 @@ class _AppPageState extends State<AppPage> { | ||||
|                                     ? null | ||||
|                                     : () => pm.openApp(app.app.id), | ||||
|                                 child: Image.memory( | ||||
|                                   val.data!, | ||||
|                                   app!.icon!, | ||||
|                                   height: 150, | ||||
|                                   gaplessPlayback: true, | ||||
|                                 ), | ||||
|   | ||||
| @@ -407,12 +407,11 @@ class AppsPageState extends State<AppsPage> { | ||||
|  | ||||
|     getAppIcon(int appIndex) { | ||||
|       return FutureBuilder( | ||||
|           future: | ||||
|               listedApps[appIndex].installedInfo?.applicationInfo?.getAppIcon(), | ||||
|           future: appsProvider.updateAppIcon(listedApps[appIndex].app.id), | ||||
|           builder: (ctx, val) { | ||||
|             return val.data != null | ||||
|             return listedApps[appIndex].icon != null | ||||
|                 ? Image.memory( | ||||
|                     val.data!, | ||||
|                     listedApps[appIndex].icon!, | ||||
|                     gaplessPlayback: true, | ||||
|                   ) | ||||
|                 : Row( | ||||
|   | ||||
| @@ -42,10 +42,11 @@ class AppInMemory { | ||||
|   late App app; | ||||
|   double? downloadProgress; | ||||
|   PackageInfo? installedInfo; | ||||
|   Uint8List? icon; | ||||
|  | ||||
|   AppInMemory(this.app, this.downloadProgress, this.installedInfo); | ||||
|   AppInMemory(this.app, this.downloadProgress, this.installedInfo, this.icon); | ||||
|   AppInMemory deepCopy() => | ||||
|       AppInMemory(app.deepCopy(), downloadProgress, installedInfo); | ||||
|       AppInMemory(app.deepCopy(), downloadProgress, installedInfo, icon); | ||||
|  | ||||
|   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 | ||||
|     if (installedInfo != null && | ||||
|         versionDetectionIsStandard && | ||||
|         !isVersionDetectionPossible(AppInMemory(app, null, installedInfo))) { | ||||
|         !isVersionDetectionPossible( | ||||
|             AppInMemory(app, null, installedInfo, null))) { | ||||
|       app.additionalSettings['versionDetection'] = false; | ||||
|       logs.add('Could not reconcile version formats for: ${app.id}'); | ||||
|       modded = true; | ||||
| @@ -1197,9 +1199,9 @@ class AppsProvider with ChangeNotifier { | ||||
|         // Save the app to the in-memory list without grabbing any OS info first | ||||
|         apps.update( | ||||
|             app.id, | ||||
|             (value) => | ||||
|                 AppInMemory(app!, value.downloadProgress, value.installedInfo), | ||||
|             ifAbsent: () => AppInMemory(app!, null, null)); | ||||
|             (value) => AppInMemory( | ||||
|                 app!, value.downloadProgress, value.installedInfo, value.icon), | ||||
|             ifAbsent: () => AppInMemory(app!, null, null, null)); | ||||
|         notifyListeners(); | ||||
|         try { | ||||
|           // 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 | ||||
|           apps.update( | ||||
|               app.id, | ||||
|               (value) => | ||||
|                   AppInMemory(app!, value.downloadProgress, installedInfo), | ||||
|               ifAbsent: () => AppInMemory(app!, null, installedInfo)); | ||||
|               (value) => AppInMemory( | ||||
|                   app!, value.downloadProgress, installedInfo, value.icon), | ||||
|               ifAbsent: () => AppInMemory(app!, null, installedInfo, null)); | ||||
|           notifyListeners(); | ||||
|         } catch (e) { | ||||
|           errors.add([app!.id, app.finalName, e.toString()]); | ||||
| @@ -1251,6 +1253,22 @@ class AppsProvider with ChangeNotifier { | ||||
|     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, | ||||
|       {bool attemptToCorrectInstallStatus = true, | ||||
|       bool onlyIfExists = true}) async { | ||||
| @@ -1258,6 +1276,7 @@ class AppsProvider with ChangeNotifier { | ||||
|     await Future.wait(apps.map((a) async { | ||||
|       var app = a.deepCopy(); | ||||
|       PackageInfo? info = await getInstalledInfo(app.id); | ||||
|       var icon = await info?.applicationInfo?.getAppIcon(); | ||||
|       app.name = await (info?.applicationInfo?.getAppLabel()) ?? app.name; | ||||
|       if (attemptToCorrectInstallStatus) { | ||||
|         app = getCorrectedInstallStatusAppIfPossible(app, info) ?? app; | ||||
| @@ -1267,9 +1286,10 @@ class AppsProvider with ChangeNotifier { | ||||
|             .writeAsStringSync(jsonEncode(app.toJson())); | ||||
|       } | ||||
|       try { | ||||
|         this.apps.update( | ||||
|             app.id, (value) => AppInMemory(app, value.downloadProgress, info), | ||||
|             ifAbsent: onlyIfExists ? null : () => AppInMemory(app, null, info)); | ||||
|         this.apps.update(app.id, | ||||
|             (value) => AppInMemory(app, value.downloadProgress, info, icon), | ||||
|             ifAbsent: | ||||
|                 onlyIfExists ? null : () => AppInMemory(app, null, info, icon)); | ||||
|       } catch (e) { | ||||
|         if (e is! ArgumentError || e.name != 'key') { | ||||
|           rethrow; | ||||
|   | ||||
| @@ -977,10 +977,10 @@ packages: | ||||
|     dependency: "direct main" | ||||
|     description: | ||||
|       name: webview_flutter | ||||
|       sha256: "25e1b6e839e8cbfbd708abc6f85ed09d1727e24e08e08c6b8590d7c65c9a8932" | ||||
|       sha256: "6869c8786d179f929144b4a1f86e09ac0eddfe475984951ea6c634774c16b522" | ||||
|       url: "https://pub.dev" | ||||
|     source: hosted | ||||
|     version: "4.7.0" | ||||
|     version: "4.8.0" | ||||
|   webview_flutter_android: | ||||
|     dependency: transitive | ||||
|     description: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user