diff --git a/lib/models/app.dart b/lib/models/app.dart index feb7697..0cbe98f 100644 --- a/lib/models/app.dart +++ b/lib/models/app.dart @@ -3,13 +3,13 @@ import 'dart:io'; import 'dart:isolate'; import 'dart:typed_data'; -import 'package:android_package_installer/android_package_installer.dart'; import 'package:android_package_manager/android_package_manager.dart'; import 'package:async/async.dart'; import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import 'package:crypto/crypto.dart'; import 'package:flutter_data/flutter_data.dart'; +import 'package:install_plugin/install_plugin.dart'; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:purplebase/purplebase.dart'; @@ -101,25 +101,20 @@ class App extends BaseApp with DataModelMixin { notifier.state = ErrorInstallProgress(Exception(e)); return; } - notifier.state = HashVerifiedInstallProgress(); + notifier.state = RequestInstallProgress(); - final result = - await AndroidPackageInstaller.installApk(apkFilePath: file.path); - final installationStatus = - result != null ? PackageInstallerStatus.byCode(result) : null; - if (installationStatus == PackageInstallerStatus.success) { + final result = await InstallPlugin.install(file.path); + + if (result['isSuccess']) { + notifier.state = IdleInstallProgress(); await file.delete(); await adapter.ref.localApps.localAppAdapter .refreshUpdateStatus(appId: identifier); - notifier.state = IdleInstallProgress(); - } else if (installationStatus == PackageInstallerStatus.failureAborted) { - // do nothing - notifier.state = IdleInstallProgress(); } else { const msg = 'Android installation failed'; notifier.state = ErrorInstallProgress( Exception(msg), - info: installationStatus?.name ?? 'Unknown error', + info: result['errorMessage'], ); } } @@ -423,7 +418,7 @@ class DownloadingInstallProgress extends AppInstallProgress { class VerifyingHashProgress extends AppInstallProgress {} -class HashVerifiedInstallProgress extends AppInstallProgress {} +class RequestInstallProgress extends AppInstallProgress {} class ErrorInstallProgress extends AppInstallProgress { final Exception e; diff --git a/lib/widgets/install_button.dart b/lib/widgets/install_button.dart index 351439e..d6395b8 100644 --- a/lib/widgets/install_button.dart +++ b/lib/widgets/install_button.dart @@ -107,8 +107,8 @@ class InstallButton extends ConsumerWidget { style: TextStyle(fontWeight: FontWeight.bold), ), VerifyingHashProgress() => Text('Verifying file integrity'), - HashVerifiedInstallProgress() => Text( - 'Hash verified, requesting ${app.canUpdate ? 'update' : 'installation'}'), + RequestInstallProgress() => + Text('Requesting ${app.canUpdate ? 'update' : 'installation'}'), ErrorInstallProgress() => Text('Error, tap to see message'), } }, diff --git a/pubspec.lock b/pubspec.lock index 552da10..c717a4e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -17,14 +17,6 @@ packages: url: "https://pub.dev" source: hosted version: "6.4.1" - android_package_installer: - dependency: "direct main" - description: - name: android_package_installer - sha256: af2a0d2dfcfb2a82255c4fd37024304941359c2bed7e4813e053a662caaa2952 - url: "https://pub.dev" - source: hosted - version: "0.0.2" android_package_manager: dependency: "direct main" description: @@ -601,6 +593,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.3+2" + install_plugin: + dependency: "direct main" + description: + name: install_plugin + sha256: "6fb67ba0781e75de4f2f2266ed25e835bfd277c5bfc2ed034af52774355857c6" + url: "https://pub.dev" + source: hosted + version: "2.1.0" intl: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 6269e5b..948806a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,7 +47,7 @@ dependencies: app_links: ^6.3.2 dart_emoji: ^0.2.0+2 remove_markdown: ^0.0.2 - android_package_installer: ^0.0.2 + install_plugin: ^2.1.0 dependency_overrides: purplebase: