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