mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23:28 +01:00 
			
		
		
		
	Merge pull request #901 from ImranR98/dev
Fix background update issue (#896)
This commit is contained in:
		| @@ -19,7 +19,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart'; | |||||||
| // ignore: implementation_imports | // ignore: implementation_imports | ||||||
| import 'package:easy_localization/src/localization.dart'; | import 'package:easy_localization/src/localization.dart'; | ||||||
|  |  | ||||||
| const String currentVersion = '0.14.14'; | const String currentVersion = '0.14.15'; | ||||||
| const String currentReleaseTag = | const String currentReleaseTag = | ||||||
|     'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES |     'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES | ||||||
|  |  | ||||||
|   | |||||||
| @@ -430,8 +430,8 @@ class AppsProvider with ChangeNotifier { | |||||||
|         zipFile: File(filePath), destinationDir: Directory(destinationPath)); |         zipFile: File(filePath), destinationDir: Directory(destinationPath)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Future<void> installXApkDir( |   Future<void> installXApkDir(DownloadedXApkDir dir, | ||||||
|       DownloadedXApkDir dir, BuildContext? context) async { |       {bool needsBGWorkaround = false}) 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 | ||||||
| @@ -444,7 +444,8 @@ 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), context); |                 await installApk(DownloadedApk(dir.appId, file), | ||||||
|  |                     needsBGWorkaround: needsBGWorkaround); | ||||||
|           } 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()}'); | ||||||
| @@ -464,7 +465,8 @@ class AppsProvider with ChangeNotifier { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Future<bool> installApk(DownloadedApk file, BuildContext? context) async { |   Future<bool> installApk(DownloadedApk file, | ||||||
|  |       {bool needsBGWorkaround = false}) 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); | ||||||
| @@ -473,16 +475,19 @@ class AppsProvider with ChangeNotifier { | |||||||
|         !(await canDowngradeApps())) { |         !(await canDowngradeApps())) { | ||||||
|       throw DowngradeError(); |       throw DowngradeError(); | ||||||
|     } |     } | ||||||
|     int? code; |     if (needsBGWorkaround) { | ||||||
|     if (context == null) { |       // The below 'await' will never return if we are in a background process | ||||||
|       // In background installs, 'installApk' never returns so don't wait for it |       // To work around this, we should assume the install will be successful | ||||||
|       // TODO: Find a fix to make this work synchronously without context |       // So we update the app's installed version first as we will never get to the later code | ||||||
|       AndroidPackageInstaller.installApk(apkFilePath: file.file.path); |       // We can't conditionally get rid of the 'await' as this causes install fails (BG process times out) - see #896 | ||||||
|       code = 0; // Be optimistic (ver. det. will get most wrong ones anyways) |       // TODO: When fixed, update this function and the calls to it accordingly | ||||||
|     } else { |       apps[file.appId]!.app.installedVersion = | ||||||
|       code = |           apps[file.appId]!.app.latestVersion; | ||||||
|           await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); |       await saveApps([apps[file.appId]!.app], | ||||||
|  |           attemptToCorrectInstallStatus: false); | ||||||
|     } |     } | ||||||
|  |     int? 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); | ||||||
| @@ -649,11 +654,17 @@ class AppsProvider with ChangeNotifier { | |||||||
|         notifyListeners(); |         notifyListeners(); | ||||||
|         try { |         try { | ||||||
|           if (downloadedFile != null) { |           if (downloadedFile != null) { | ||||||
|             // ignore: use_build_context_synchronously |             if (willBeSilent && context == null) { | ||||||
|             await installApk(downloadedFile, context); |               installApk(downloadedFile, needsBGWorkaround: true); | ||||||
|  |             } else { | ||||||
|  |               await installApk(downloadedFile); | ||||||
|  |             } | ||||||
|           } else { |           } else { | ||||||
|             // ignore: use_build_context_synchronously |             if (willBeSilent && context == null) { | ||||||
|             await installXApkDir(downloadedDir!, context); |               installXApkDir(downloadedDir!, needsBGWorkaround: true); | ||||||
|  |             } else { | ||||||
|  |               await installXApkDir(downloadedDir!); | ||||||
|  |             } | ||||||
|           } |           } | ||||||
|           if (willBeSilent && context == null) { |           if (willBeSilent && context == null) { | ||||||
|             notificationsProvider?.notify(SilentUpdateAttemptNotification( |             notificationsProvider?.notify(SilentUpdateAttemptNotification( | ||||||
|   | |||||||
| @@ -198,10 +198,10 @@ packages: | |||||||
|     dependency: "direct main" |     dependency: "direct main" | ||||||
|     description: |     description: | ||||||
|       name: dynamic_color |       name: dynamic_color | ||||||
|       sha256: de4798a7069121aee12d5895315680258415de9b00e717723a1bd73d58f0126d |       sha256: "96bff3df72e3d428bda2b874c7a521e8c86f592cae626ea594922fcc8d166e0c" | ||||||
|       url: "https://pub.dev" |       url: "https://pub.dev" | ||||||
|     source: hosted |     source: hosted | ||||||
|     version: "1.6.6" |     version: "1.6.7" | ||||||
|   easy_localization: |   easy_localization: | ||||||
|     dependency: "direct main" |     dependency: "direct main" | ||||||
|     description: |     description: | ||||||
| @@ -887,10 +887,10 @@ packages: | |||||||
|     dependency: transitive |     dependency: transitive | ||||||
|     description: |     description: | ||||||
|       name: webview_flutter_android |       name: webview_flutter_android | ||||||
|       sha256: "9427774649fd3c8b7ff53523051395d13aed2ca355822b822e6493d79f5fc05a" |       sha256: ddc167c6676f57c8b367d19fcbee267d6dc6adf81bd6c3cb87981d30746e0a6d | ||||||
|       url: "https://pub.dev" |       url: "https://pub.dev" | ||||||
|     source: hosted |     source: hosted | ||||||
|     version: "3.10.0" |     version: "3.10.1" | ||||||
|   webview_flutter_platform_interface: |   webview_flutter_platform_interface: | ||||||
|     dependency: transitive |     dependency: transitive | ||||||
|     description: |     description: | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev | |||||||
| # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | ||||||
| # In Windows, build-name is used as the major, minor, and patch parts | # In Windows, build-name is used as the major, minor, and patch parts | ||||||
| # of the product and file versions while build-number is used as the build suffix. | # of the product and file versions while build-number is used as the build suffix. | ||||||
| version: 0.14.14+206 # When changing this, update the tag in main() accordingly | version: 0.14.15+207 # When changing this, update the tag in main() accordingly | ||||||
|  |  | ||||||
| environment: | environment: | ||||||
|   sdk: '>=3.0.0 <4.0.0' |   sdk: '>=3.0.0 <4.0.0' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user