mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-10-21 10:03:44 +02:00
Fix repeating background install for some apps (#886)
This commit is contained in:
@@ -430,7 +430,8 @@ class AppsProvider with ChangeNotifier {
|
|||||||
zipFile: File(filePath), destinationDir: Directory(destinationPath));
|
zipFile: File(filePath), destinationDir: Directory(destinationPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> installXApkDir(DownloadedXApkDir dir) async {
|
Future<void> installXApkDir(
|
||||||
|
DownloadedXApkDir dir, BuildContext? context) async {
|
||||||
// We don't know which APKs in an XAPK are supported by the user's device
|
// We don't know which APKs in an XAPK are supported by the user's device
|
||||||
// So we try installing all of them and assume success if at least one installed
|
// So we try installing all of them and assume success if at least one installed
|
||||||
// If 0 APKs installed, throw the first install error encountered
|
// If 0 APKs installed, throw the first install error encountered
|
||||||
@@ -443,7 +444,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
if (file.path.toLowerCase().endsWith('.apk')) {
|
if (file.path.toLowerCase().endsWith('.apk')) {
|
||||||
try {
|
try {
|
||||||
somethingInstalled = somethingInstalled ||
|
somethingInstalled = somethingInstalled ||
|
||||||
await installApk(DownloadedApk(dir.appId, file));
|
await installApk(DownloadedApk(dir.appId, file), context);
|
||||||
} 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()}');
|
||||||
@@ -463,7 +464,7 @@ class AppsProvider with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> installApk(DownloadedApk file) async {
|
Future<bool> installApk(DownloadedApk file, BuildContext? context) async {
|
||||||
var newInfo =
|
var newInfo =
|
||||||
await pm.getPackageArchiveInfo(archiveFilePath: file.file.path);
|
await pm.getPackageArchiveInfo(archiveFilePath: file.file.path);
|
||||||
PackageInfo? appInfo = await getInstalledInfo(apps[file.appId]!.app.id);
|
PackageInfo? appInfo = await getInstalledInfo(apps[file.appId]!.app.id);
|
||||||
@@ -472,8 +473,16 @@ class AppsProvider with ChangeNotifier {
|
|||||||
!(await canDowngradeApps())) {
|
!(await canDowngradeApps())) {
|
||||||
throw DowngradeError();
|
throw DowngradeError();
|
||||||
}
|
}
|
||||||
int? code =
|
int? code;
|
||||||
await AndroidPackageInstaller.installApk(apkFilePath: file.file.path);
|
if (context == null) {
|
||||||
|
// In background installs, 'installApk' never returns so don't wait for it
|
||||||
|
// TODO: Find a fix to make this work synchronously without context
|
||||||
|
AndroidPackageInstaller.installApk(apkFilePath: file.file.path);
|
||||||
|
code = 0; // Be optimistic (ver. det. will get most wrong ones anyways)
|
||||||
|
} else {
|
||||||
|
code =
|
||||||
|
await AndroidPackageInstaller.installApk(apkFilePath: file.file.path);
|
||||||
|
}
|
||||||
bool installed = false;
|
bool installed = false;
|
||||||
if (code != null && code != 0 && code != 3) {
|
if (code != null && code != 0 && code != 3) {
|
||||||
throw InstallError(code);
|
throw InstallError(code);
|
||||||
@@ -640,19 +649,11 @@ class AppsProvider with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
if (downloadedFile != null) {
|
if (downloadedFile != null) {
|
||||||
if (willBeSilent && context == null) {
|
// ignore: use_build_context_synchronously
|
||||||
// Would await forever - workaround - TODO
|
await installApk(downloadedFile, context);
|
||||||
installApk(downloadedFile);
|
|
||||||
} else {
|
|
||||||
await installApk(downloadedFile);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (willBeSilent && context == null) {
|
// ignore: use_build_context_synchronously
|
||||||
// Would await forever - workaround - TODO
|
await installXApkDir(downloadedDir!, context);
|
||||||
installXApkDir(downloadedDir!);
|
|
||||||
} else {
|
|
||||||
await installXApkDir(downloadedDir!);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (willBeSilent && context == null) {
|
if (willBeSilent && context == null) {
|
||||||
notificationsProvider?.notify(SilentUpdateAttemptNotification(
|
notificationsProvider?.notify(SilentUpdateAttemptNotification(
|
||||||
|
Reference in New Issue
Block a user