mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-16 11:48:09 +02:00
App load optimizations, dir delete bugfix
This commit is contained in:
@@ -322,28 +322,28 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
|
|
||||||
getLoadingWidgets() {
|
getLoadingWidgets() {
|
||||||
return [
|
return [
|
||||||
if (appsProvider.loadingApps || listedApps.isEmpty)
|
if (listedApps.isEmpty)
|
||||||
SliverFillRemaining(
|
SliverFillRemaining(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: appsProvider.loadingApps
|
child: Text(
|
||||||
? const CircularProgressIndicator()
|
appsProvider.apps.isEmpty ? tr('noApps') : tr('noAppsForFilter'),
|
||||||
: Text(
|
|
||||||
appsProvider.apps.isEmpty
|
|
||||||
? tr('noApps')
|
|
||||||
: tr('noAppsForFilter'),
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
style: Theme.of(context).textTheme.headlineMedium,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
))),
|
))),
|
||||||
if (refreshingSince != null)
|
if (refreshingSince != null || appsProvider.loadingApps)
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: LinearProgressIndicator(
|
child: LinearProgressIndicator(
|
||||||
value: appsProvider
|
value: appsProvider.loadingApps
|
||||||
|
? null
|
||||||
|
: appsProvider
|
||||||
.getAppValues()
|
.getAppValues()
|
||||||
.where((element) => !(element.app.lastUpdateCheck
|
.where((element) => !(element.app.lastUpdateCheck
|
||||||
?.isBefore(refreshingSince!) ??
|
?.isBefore(refreshingSince!) ??
|
||||||
true))
|
true))
|
||||||
.length /
|
.length /
|
||||||
(appsProvider.apps.isNotEmpty ? appsProvider.apps.length : 1),
|
(appsProvider.apps.isNotEmpty
|
||||||
|
? appsProvider.apps.length
|
||||||
|
: 1),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
@@ -130,7 +130,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
element.path.endsWith('.part') ||
|
element.path.endsWith('.part') ||
|
||||||
element.statSync().modified.isBefore(cutoff))
|
element.statSync().modified.isBefore(cutoff))
|
||||||
.forEach((partialApk) {
|
.forEach((partialApk) {
|
||||||
partialApk.delete();
|
partialApk.delete(recursive: true);
|
||||||
});
|
});
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
if (!(downloadedFile.existsSync() && useExisting)) {
|
if (!(downloadedFile.existsSync() && useExisting)) {
|
||||||
File tempDownloadedFile = File('${downloadedFile.path}.part');
|
File tempDownloadedFile = File('${downloadedFile.path}.part');
|
||||||
if (tempDownloadedFile.existsSync()) {
|
if (tempDownloadedFile.existsSync()) {
|
||||||
tempDownloadedFile.deleteSync();
|
tempDownloadedFile.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
var length = response.contentLength;
|
var length = response.contentLength;
|
||||||
var received = 0;
|
var received = 0;
|
||||||
@@ -174,7 +174,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
onProgress(progress);
|
onProgress(progress);
|
||||||
}
|
}
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
tempDownloadedFile.deleteSync();
|
tempDownloadedFile.deleteSync(recursive: true);
|
||||||
throw response.reasonPhrase ?? tr('unexpectedError');
|
throw response.reasonPhrase ?? tr('unexpectedError');
|
||||||
}
|
}
|
||||||
tempDownloadedFile.renameSync(downloadedFile.path);
|
tempDownloadedFile.renameSync(downloadedFile.path);
|
||||||
@@ -266,7 +266,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
if (fn.startsWith('${app.id}-') &&
|
if (fn.startsWith('${app.id}-') &&
|
||||||
FileSystemEntity.isFileSync(file.path) &&
|
FileSystemEntity.isFileSync(file.path) &&
|
||||||
file.path != downloadedFile.path) {
|
file.path != downloadedFile.path) {
|
||||||
file.delete();
|
file.delete(recursive: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isAPK) {
|
if (isAPK) {
|
||||||
@@ -349,7 +349,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
silent: silent);
|
silent: silent);
|
||||||
}
|
}
|
||||||
if (somethingInstalled) {
|
if (somethingInstalled) {
|
||||||
dir.file.delete();
|
dir.file.delete(recursive: true);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
dir.extracted.delete(recursive: true);
|
dir.extracted.delete(recursive: true);
|
||||||
@@ -379,7 +379,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
installed = true;
|
installed = true;
|
||||||
apps[file.appId]!.app.installedVersion =
|
apps[file.appId]!.app.installedVersion =
|
||||||
apps[file.appId]!.app.latestVersion;
|
apps[file.appId]!.app.latestVersion;
|
||||||
file.file.delete();
|
file.file.delete(recursive: true);
|
||||||
}
|
}
|
||||||
await saveApps([apps[file.appId]!.app]);
|
await saveApps([apps[file.appId]!.app]);
|
||||||
return installed;
|
return installed;
|
||||||
@@ -703,42 +703,31 @@ class AppsProvider with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
loadingApps = true;
|
loadingApps = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
List<App> newApps = (await getAppsDir())
|
var sp = SourceProvider();
|
||||||
|
List<List<String>> errors = [];
|
||||||
|
List<FileSystemEntity> newApps = (await getAppsDir())
|
||||||
.listSync()
|
.listSync()
|
||||||
.where((item) => item.path.toLowerCase().endsWith('.json'))
|
.where((item) => item.path.toLowerCase().endsWith('.json'))
|
||||||
.map((e) {
|
.toList();
|
||||||
|
for (var e in newApps) {
|
||||||
try {
|
try {
|
||||||
return App.fromJson(jsonDecode(File(e.path).readAsStringSync()));
|
var app = 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');
|
||||||
e.renameSync('${e.path}.corrupt');
|
e.renameSync('${e.path}.corrupt');
|
||||||
return App(
|
|
||||||
'', '', '', '', '', '', [], 0, {}, DateTime.now(), false);
|
|
||||||
} else {
|
} else {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.where((element) => element.id.isNotEmpty)
|
|
||||||
.toList();
|
|
||||||
var idsToDelete = apps.values
|
|
||||||
.map((e) => e.app.id)
|
|
||||||
.toSet()
|
|
||||||
.difference(newApps.map((e) => e.id).toSet());
|
|
||||||
for (var id in idsToDelete) {
|
|
||||||
apps.remove(id);
|
|
||||||
}
|
|
||||||
var sp = SourceProvider();
|
|
||||||
List<List<String>> errors = [];
|
|
||||||
for (int i = 0; i < newApps.length; i++) {
|
|
||||||
var info = await getInstalledInfo(newApps[i].id);
|
|
||||||
try {
|
|
||||||
sp.getSource(newApps[i].url, overrideSource: newApps[i].overrideSource);
|
|
||||||
apps[newApps[i].id] = AppInMemory(newApps[i], null, info);
|
|
||||||
} catch (e) {
|
|
||||||
errors.add([newApps[i].id, newApps[i].finalName, e.toString()]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (errors.isNotEmpty) {
|
if (errors.isNotEmpty) {
|
||||||
removeApps(errors.map((e) => e[0]).toList());
|
removeApps(errors.map((e) => e[0]).toList());
|
||||||
@@ -798,13 +787,13 @@ class AppsProvider with ChangeNotifier {
|
|||||||
for (var appId in appIds) {
|
for (var appId in appIds) {
|
||||||
File file = File('${(await getAppsDir()).path}/$appId.json');
|
File file = File('${(await getAppsDir()).path}/$appId.json');
|
||||||
if (file.existsSync()) {
|
if (file.existsSync()) {
|
||||||
file.deleteSync();
|
file.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
apkFiles
|
apkFiles
|
||||||
?.where(
|
?.where(
|
||||||
(element) => element.path.split('/').last.startsWith('$appId-'))
|
(element) => element.path.split('/').last.startsWith('$appId-'))
|
||||||
.forEach((element) {
|
.forEach((element) {
|
||||||
element.delete();
|
element.delete(recursive: true);
|
||||||
});
|
});
|
||||||
if (apps.containsKey(appId)) {
|
if (apps.containsKey(appId)) {
|
||||||
apps.remove(appId);
|
apps.remove(appId);
|
||||||
|
Reference in New Issue
Block a user