mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-10-24 11:23:45 +02:00
Enable icon caching (#1837)
This commit is contained in:
@@ -375,6 +375,7 @@ class AppsProvider with ChangeNotifier {
|
||||
late Stream<FGBGType>? foregroundStream;
|
||||
late StreamSubscription<FGBGType>? foregroundSubscription;
|
||||
late Directory APKDir;
|
||||
late Directory iconsCacheDir;
|
||||
late SettingsProvider settingsProvider = SettingsProvider();
|
||||
|
||||
Iterable<AppInMemory> getAppValues() => apps.values.map((a) => a.deepCopy());
|
||||
@@ -393,12 +394,21 @@ class AppsProvider with ChangeNotifier {
|
||||
var cacheDirs = await getExternalCacheDirectories();
|
||||
if (cacheDirs?.isNotEmpty ?? false) {
|
||||
APKDir = cacheDirs!.first;
|
||||
iconsCacheDir = Directory('${cacheDirs.first.path}/icons');
|
||||
if (!iconsCacheDir.existsSync()) {
|
||||
iconsCacheDir.createSync();
|
||||
}
|
||||
} else {
|
||||
APKDir =
|
||||
Directory('${(await getExternalStorageDirectory())!.path}/apks');
|
||||
if (!APKDir.existsSync()) {
|
||||
APKDir.createSync();
|
||||
}
|
||||
iconsCacheDir =
|
||||
Directory('${(await getExternalStorageDirectory())!.path}/icons');
|
||||
if (!iconsCacheDir.existsSync()) {
|
||||
iconsCacheDir.createSync();
|
||||
}
|
||||
}
|
||||
if (!isBg) {
|
||||
// Load Apps into memory (in background processes, this is done later instead of in the constructor)
|
||||
@@ -1297,10 +1307,16 @@ class AppsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> updateAppIcon(String? appId) async {
|
||||
Future<void> updateAppIcon(String? appId, {bool ignoreCache = false}) async {
|
||||
if (apps[appId]?.icon == null) {
|
||||
var icon =
|
||||
(await apps[appId]?.installedInfo?.applicationInfo?.getAppIcon());
|
||||
var cachedIcon = File('${iconsCacheDir.path}/$appId.png');
|
||||
var alreadyCached = cachedIcon.existsSync() && !ignoreCache;
|
||||
var icon = alreadyCached
|
||||
? (await cachedIcon.readAsBytes())
|
||||
: (await apps[appId]?.installedInfo?.applicationInfo?.getAppIcon());
|
||||
if (icon != null && !alreadyCached) {
|
||||
cachedIcon.writeAsBytes(icon.toList());
|
||||
}
|
||||
if (icon != null) {
|
||||
apps.update(
|
||||
apps[appId]!.app.id,
|
||||
@@ -1351,6 +1367,10 @@ class AppsProvider with ChangeNotifier {
|
||||
if (file.existsSync()) {
|
||||
file.deleteSync(recursive: true);
|
||||
}
|
||||
File iconFile = File('$iconsCacheDir/$appId.png');
|
||||
if (iconFile.existsSync()) {
|
||||
iconFile.deleteSync(recursive: true);
|
||||
}
|
||||
apkFiles
|
||||
.where(
|
||||
(element) => element.path.split('/').last.startsWith('$appId-'))
|
||||
|
Reference in New Issue
Block a user