[imp]: Add waitForInstalled and use after install
This is an attempt to fix the issue of Uninstall/Open not displaying after install. The app requires a hot reload to fix it.
This commit is contained in:
@@ -550,7 +550,9 @@ class AppProvider extends ChangeNotifier {
|
||||
.toList();
|
||||
|
||||
// Clean up preferences for uninstalled apps
|
||||
final installedPackages = _installedApps.map((app) => app.packageName).toSet();
|
||||
final installedPackages = _installedApps
|
||||
.map((app) => app.packageName)
|
||||
.toSet();
|
||||
await _preferencesService.cleanupUninstalledApps(installedPackages);
|
||||
|
||||
_installedAppsState = LoadingState.success;
|
||||
@@ -616,7 +618,9 @@ class AppProvider extends ChangeNotifier {
|
||||
|
||||
/// Gets the latest version for an app based on per-app unstable preference
|
||||
Future<FDroidVersion?> getLatestVersion(FDroidApp app) async {
|
||||
final includeUnstable = await _preferencesService.getIncludeUnstable(app.packageName);
|
||||
final includeUnstable = await _preferencesService.getIncludeUnstable(
|
||||
app.packageName,
|
||||
);
|
||||
return app.getLatestVersion(includeUnstable: includeUnstable);
|
||||
}
|
||||
|
||||
@@ -644,6 +648,23 @@ class AppProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Polls until an app shows up as installed or timeout is reached.
|
||||
Future<bool> waitForInstalled(
|
||||
String packageName, {
|
||||
Duration timeout = const Duration(seconds: 20),
|
||||
Duration interval = const Duration(milliseconds: 800),
|
||||
}) async {
|
||||
final deadline = DateTime.now().add(timeout);
|
||||
while (DateTime.now().isBefore(deadline)) {
|
||||
await fetchInstalledApps();
|
||||
if (isAppInstalled(packageName)) {
|
||||
return true;
|
||||
}
|
||||
await Future.delayed(interval);
|
||||
}
|
||||
return isAppInstalled(packageName);
|
||||
}
|
||||
|
||||
/// Refreshes all data
|
||||
Future<void> refreshAll({RepositoriesProvider? repositoriesProvider}) async {
|
||||
// Clear cached data
|
||||
|
||||
@@ -174,8 +174,7 @@ class _AppDetailsScreenState extends State<AppDetailsScreen> {
|
||||
}
|
||||
|
||||
await downloadProvider.installApk(downloadInfo!.filePath!);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await appProvider.fetchInstalledApps();
|
||||
await appProvider.waitForInstalled(widget.app.packageName);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -2469,8 +2468,7 @@ class _VersionDownloadButton extends StatelessWidget {
|
||||
try {
|
||||
if (downloadInfo.filePath != null) {
|
||||
await downloadProvider.installApk(downloadInfo.filePath!);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await appProvider.fetchInstalledApps();
|
||||
await appProvider.waitForInstalled(app.packageName);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Installing ${app.name}...')),
|
||||
|
||||
Reference in New Issue
Block a user