diff --git a/lib/main.dart b/lib/main.dart index 14276a1..e9a4888 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -19,7 +19,7 @@ import 'package:easy_localization/src/easy_localization_controller.dart'; // ignore: implementation_imports import 'package:easy_localization/src/localization.dart'; -const String currentVersion = '0.14.14'; +const String currentVersion = '0.14.15'; const String currentReleaseTag = 'v$currentVersion-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index a9b5edd..7d08656 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -430,8 +430,8 @@ class AppsProvider with ChangeNotifier { zipFile: File(filePath), destinationDir: Directory(destinationPath)); } - Future installXApkDir( - DownloadedXApkDir dir, BuildContext? context) async { + Future installXApkDir(DownloadedXApkDir dir, + {bool needsBGWorkaround = false}) async { // 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 // If 0 APKs installed, throw the first install error encountered @@ -444,7 +444,8 @@ class AppsProvider with ChangeNotifier { if (file.path.toLowerCase().endsWith('.apk')) { try { somethingInstalled = somethingInstalled || - await installApk(DownloadedApk(dir.appId, file), context); + await installApk(DownloadedApk(dir.appId, file), + needsBGWorkaround: needsBGWorkaround); } catch (e) { logs.add( 'Could not install APK from XAPK \'${file.path}\': ${e.toString()}'); @@ -464,7 +465,8 @@ class AppsProvider with ChangeNotifier { } } - Future installApk(DownloadedApk file, BuildContext? context) async { + Future installApk(DownloadedApk file, + {bool needsBGWorkaround = false}) async { var newInfo = await pm.getPackageArchiveInfo(archiveFilePath: file.file.path); PackageInfo? appInfo = await getInstalledInfo(apps[file.appId]!.app.id); @@ -473,16 +475,19 @@ class AppsProvider with ChangeNotifier { !(await canDowngradeApps())) { throw DowngradeError(); } - int? code; - 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); + if (needsBGWorkaround) { + // The below 'await' will never return if we are in a background process + // To work around this, we should assume the install will be successful + // So we update the app's installed version first as we will never get to the later code + // We can't conditionally get rid of the 'await' as this causes install fails (BG process times out) - see #896 + // TODO: When fixed, update this function and the calls to it accordingly + apps[file.appId]!.app.installedVersion = + apps[file.appId]!.app.latestVersion; + await saveApps([apps[file.appId]!.app], + attemptToCorrectInstallStatus: false); } + int? code = + await AndroidPackageInstaller.installApk(apkFilePath: file.file.path); bool installed = false; if (code != null && code != 0 && code != 3) { throw InstallError(code); @@ -649,11 +654,17 @@ class AppsProvider with ChangeNotifier { notifyListeners(); try { if (downloadedFile != null) { - // ignore: use_build_context_synchronously - await installApk(downloadedFile, context); + if (willBeSilent && context == null) { + installApk(downloadedFile, needsBGWorkaround: true); + } else { + await installApk(downloadedFile); + } } else { - // ignore: use_build_context_synchronously - await installXApkDir(downloadedDir!, context); + if (willBeSilent && context == null) { + installXApkDir(downloadedDir!, needsBGWorkaround: true); + } else { + await installXApkDir(downloadedDir!); + } } if (willBeSilent && context == null) { notificationsProvider?.notify(SilentUpdateAttemptNotification( diff --git a/pubspec.lock b/pubspec.lock index ef2647c..33758ce 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -198,10 +198,10 @@ packages: dependency: "direct main" description: name: dynamic_color - sha256: de4798a7069121aee12d5895315680258415de9b00e717723a1bd73d58f0126d + sha256: "96bff3df72e3d428bda2b874c7a521e8c86f592cae626ea594922fcc8d166e0c" url: "https://pub.dev" source: hosted - version: "1.6.6" + version: "1.6.7" easy_localization: dependency: "direct main" description: @@ -887,10 +887,10 @@ packages: dependency: transitive description: name: webview_flutter_android - sha256: "9427774649fd3c8b7ff53523051395d13aed2ca355822b822e6493d79f5fc05a" + sha256: ddc167c6676f57c8b367d19fcbee267d6dc6adf81bd6c3cb87981d30746e0a6d url: "https://pub.dev" source: hosted - version: "3.10.0" + version: "3.10.1" webview_flutter_platform_interface: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index db5c5ca..66170d7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 # 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. -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: sdk: '>=3.0.0 <4.0.0'