mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-24 01:49:41 +02:00
Improvements, bugfixes
This commit is contained in:
@@ -66,27 +66,29 @@ class NotImplementedError extends ObtainiumError {
|
||||
|
||||
class MultiAppMultiError extends ObtainiumError {
|
||||
Map<String, dynamic> rawErrors = {};
|
||||
Map<String, List<String>> content = {};
|
||||
Map<String, List<String>> idsByErrorString = {};
|
||||
Map<String, String> appIdNames = {};
|
||||
|
||||
MultiAppMultiError() : super(tr('placeholder'), unexpected: true);
|
||||
|
||||
add(String appId, dynamic error) {
|
||||
add(String appId, dynamic error, {String? appName}) {
|
||||
rawErrors[appId] = error;
|
||||
var string = error.toString();
|
||||
var tempIds = content.remove(string);
|
||||
var tempIds = idsByErrorString.remove(string);
|
||||
tempIds ??= [];
|
||||
tempIds.add(appId);
|
||||
content.putIfAbsent(string, () => tempIds!);
|
||||
idsByErrorString.putIfAbsent(string, () => tempIds!);
|
||||
if (appName != null) {
|
||||
appIdNames[appId] = appName;
|
||||
}
|
||||
}
|
||||
|
||||
String errorString(String appId) =>
|
||||
'${appIdNames.containsKey(appId) ? '${appIdNames[appId]} ($appId)' : appId}: ${rawErrors[appId].toString()}';
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String finalString = '';
|
||||
for (var e in content.keys) {
|
||||
finalString += '$e: ${content[e].toString()}\n\n';
|
||||
}
|
||||
return finalString;
|
||||
}
|
||||
String toString() =>
|
||||
idsByErrorString.keys.map((e) => errorString(e)).join('\n\n');
|
||||
}
|
||||
|
||||
showError(dynamic e, BuildContext context) {
|
||||
|
@@ -833,7 +833,7 @@ class AppsPageState extends State<AppsPage> {
|
||||
items: const [],
|
||||
initValid: true,
|
||||
message: tr('installStatusOfXWillBeResetExplanation',
|
||||
args: [plural('app', selectedAppIds.length)]),
|
||||
args: [plural('apps', selectedAppIds.length)]),
|
||||
);
|
||||
});
|
||||
if (values != null) {
|
||||
|
@@ -217,7 +217,8 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
if (errors.isEmpty) {
|
||||
// ignore: use_build_context_synchronously
|
||||
showError(
|
||||
tr('importedX', args: [plural('app', selectedUrls.length)]),
|
||||
tr('importedX',
|
||||
args: [plural('apps', selectedUrls.length)]),
|
||||
context);
|
||||
} else {
|
||||
// ignore: use_build_context_synchronously
|
||||
@@ -274,7 +275,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
if (errors.isEmpty) {
|
||||
// ignore: use_build_context_synchronously
|
||||
showError(
|
||||
tr('importedX', args: [plural('app', selectedUrls.length)]),
|
||||
tr('importedX', args: [plural('apps', selectedUrls.length)]),
|
||||
context);
|
||||
} else {
|
||||
// ignore: use_build_context_synchronously
|
||||
|
@@ -449,7 +449,7 @@ class AppsProvider with ChangeNotifier {
|
||||
} catch (e) {
|
||||
logs.add(
|
||||
'Could not install APK from XAPK \'${file.path}\': ${e.toString()}');
|
||||
errors.add(dir.appId, e);
|
||||
errors.add(dir.appId, e, appName: apps[dir.appId]?.name);
|
||||
}
|
||||
} else if (file.path.toLowerCase().endsWith('.obb')) {
|
||||
await moveObbFile(file, dir.appId);
|
||||
@@ -457,7 +457,7 @@ class AppsProvider with ChangeNotifier {
|
||||
}
|
||||
if (somethingInstalled) {
|
||||
dir.file.delete(recursive: true);
|
||||
} else if (errors.content.isNotEmpty) {
|
||||
} else if (errors.idsByErrorString.isNotEmpty) {
|
||||
throw errors;
|
||||
}
|
||||
} finally {
|
||||
@@ -677,11 +677,11 @@ class AppsProvider with ChangeNotifier {
|
||||
}
|
||||
installedIds.add(id);
|
||||
} catch (e) {
|
||||
errors.add(id, e);
|
||||
errors.add(id, e, appName: apps[id]?.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.content.isNotEmpty) {
|
||||
if (errors.idsByErrorString.isNotEmpty) {
|
||||
throw errors;
|
||||
}
|
||||
|
||||
@@ -1090,7 +1090,7 @@ class AppsProvider with ChangeNotifier {
|
||||
throwErrorsForRetry) {
|
||||
rethrow;
|
||||
}
|
||||
errors.add(appId, e);
|
||||
errors.add(appId, e, appName: apps[appId]?.name);
|
||||
}
|
||||
if (newApp != null) {
|
||||
updates.add(newApp);
|
||||
@@ -1100,7 +1100,7 @@ class AppsProvider with ChangeNotifier {
|
||||
gettingUpdates = false;
|
||||
}
|
||||
}
|
||||
if (errors.content.isNotEmpty) {
|
||||
if (errors.idsByErrorString.isNotEmpty) {
|
||||
var res = Map<String, dynamic>();
|
||||
res['errors'] = errors;
|
||||
res['updates'] = updates;
|
||||
@@ -1392,15 +1392,16 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
||||
List<App> toNotify = [];
|
||||
List<MapEntry<String, int>> toRetry = [];
|
||||
var retryAfterXSeconds = 0;
|
||||
List<MapEntry<String, dynamic>> toThrow = [];
|
||||
List<String> toThrow = [];
|
||||
var networkRestricted = false;
|
||||
if (appsProvider.settingsProvider.bgUpdatesOnWiFiOnly) {
|
||||
var netResult = await (Connectivity().checkConnectivity());
|
||||
networkRestricted = (netResult != ConnectivityResult.wifi) &&
|
||||
(netResult != ConnectivityResult.ethernet);
|
||||
}
|
||||
MultiAppMultiError? errors;
|
||||
CheckingUpdatesNotification notif =
|
||||
CheckingUpdatesNotification(plural('app', toCheck.length));
|
||||
CheckingUpdatesNotification(plural('apps', toCheck.length));
|
||||
|
||||
try {
|
||||
// Check for updates
|
||||
@@ -1411,8 +1412,8 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
||||
// If there were errors, group them into toRetry and toThrow
|
||||
if (e is Map) {
|
||||
updates = e['updates'];
|
||||
MultiAppMultiError errors = e['errors'];
|
||||
errors.rawErrors.forEach((key, err) {
|
||||
errors = e['errors'];
|
||||
errors!.rawErrors.forEach((key, err) {
|
||||
logs.add(
|
||||
'BG update task $taskId: Got error on checking for $key \'${err.toString()}\'.');
|
||||
var toCheckApp = toCheck.where((element) => element.key == key).first;
|
||||
@@ -1422,12 +1423,12 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
||||
? (err.remainingMinutes * 60)
|
||||
: e is ClientException
|
||||
? (15 * 60)
|
||||
: pow(toCheckApp.value, 2).toInt();
|
||||
: pow(toCheckApp.value + 1, 2).toInt();
|
||||
if (minRetryIntervalForThisApp > retryAfterXSeconds) {
|
||||
retryAfterXSeconds = minRetryIntervalForThisApp;
|
||||
}
|
||||
} else {
|
||||
toThrow.add(MapEntry(key, err));
|
||||
toThrow.add(key);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -1456,9 +1457,9 @@ Future<void> bgUpdateCheck(int taskId, Map<String, dynamic>? params) async {
|
||||
|
||||
// Send the error notifications
|
||||
if (toThrow.isNotEmpty) {
|
||||
for (var element in toThrow) {
|
||||
for (var appId in toThrow) {
|
||||
notificationsProvider.notify(ErrorCheckingUpdatesNotification(
|
||||
'${element.key}: ${element.value.toString()}',
|
||||
errors!.errorString(appId),
|
||||
id: Random().nextInt(10000)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user