mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-28 20:13:28 +01:00 
			
		
		
		
	Improve App load performance (#579)
This commit is contained in:
		| @@ -725,21 +725,12 @@ class AppsProvider with ChangeNotifier { | |||||||
|     notifyListeners(); |     notifyListeners(); | ||||||
|     var sp = SourceProvider(); |     var sp = SourceProvider(); | ||||||
|     List<List<String>> errors = []; |     List<List<String>> errors = []; | ||||||
|     List<FileSystemEntity> newApps = (await getAppsDir()) |     List<App?> newApps = (await getAppsDir()) // Parse Apps from JSON | ||||||
|         .listSync() |         .listSync() | ||||||
|         .where((item) => item.path.toLowerCase().endsWith('.json')) |         .where((item) => item.path.toLowerCase().endsWith('.json')) | ||||||
|         .toList(); |         .map((e) { | ||||||
|     for (var e in newApps) { |  | ||||||
|       try { |       try { | ||||||
|         var app = App.fromJson(jsonDecode(File(e.path).readAsStringSync())); |         return App.fromJson(jsonDecode(File(e.path).readAsStringSync())); | ||||||
|         try { |  | ||||||
|           var info = await getInstalledInfo(app.id); |  | ||||||
|           sp.getSource(app.url, overrideSource: app.overrideSource); |  | ||||||
|           apps[app.id] = AppInMemory(app, null, info); |  | ||||||
|           notifyListeners(); |  | ||||||
|         } catch (e) { |  | ||||||
|           errors.add([app.id, app.finalName, e.toString()]); |  | ||||||
|         } |  | ||||||
|       } catch (err) { |       } catch (err) { | ||||||
|         if (err is FormatException) { |         if (err is FormatException) { | ||||||
|           logs.add('Corrupt JSON when loading App (will be ignored): $e'); |           logs.add('Corrupt JSON when loading App (will be ignored): $e'); | ||||||
| @@ -748,6 +739,30 @@ class AppsProvider with ChangeNotifier { | |||||||
|           rethrow; |           rethrow; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|  |     }).toList(); | ||||||
|  |     for (var app in newApps) { | ||||||
|  |       // Put Apps into memory to list them (fast) | ||||||
|  |       if (app != null) { | ||||||
|  |         try { | ||||||
|  |           apps[app.id] = AppInMemory(app, null, null); | ||||||
|  |         } catch (e) { | ||||||
|  |           errors.add([app.id, app.finalName, e.toString()]); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     notifyListeners(); | ||||||
|  |     for (var app in newApps) { | ||||||
|  |       // Check install status for each App (slow) | ||||||
|  |       if (app != null) { | ||||||
|  |         try { | ||||||
|  |           apps[app.id]?.installedInfo = await getInstalledInfo(app.id); | ||||||
|  |           sp.getSource(app.url, overrideSource: app.overrideSource); | ||||||
|  |         } catch (e) { | ||||||
|  |           apps.remove(app.id); | ||||||
|  |           errors.add([app.id, app.finalName, e.toString()]); | ||||||
|  |         } | ||||||
|  |         notifyListeners(); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|     if (errors.isNotEmpty) { |     if (errors.isNotEmpty) { | ||||||
|       removeApps(errors.map((e) => e[0]).toList()); |       removeApps(errors.map((e) => e[0]).toList()); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user