Disable app page buttons while app info is being updated

This commit is contained in:
Imran Remtulla
2024-01-20 16:28:54 -05:00
parent 62dc7fd88b
commit 369ae43062

View File

@@ -23,13 +23,18 @@ class AppPage extends StatefulWidget {
class _AppPageState extends State<AppPage> { class _AppPageState extends State<AppPage> {
AppInMemory? prevApp; AppInMemory? prevApp;
bool updating = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var appsProvider = context.watch<AppsProvider>(); var appsProvider = context.watch<AppsProvider>();
var settingsProvider = context.watch<SettingsProvider>(); var settingsProvider = context.watch<SettingsProvider>();
getUpdate(String id, {bool resetVersion = false}) { getUpdate(String id, {bool resetVersion = false}) async {
appsProvider.checkUpdate(id).then((e) { try {
setState(() {
updating = true;
});
await appsProvider.checkUpdate(id);
if (resetVersion) { if (resetVersion) {
appsProvider.apps[id]?.app.additionalSettings['versionDetection'] = appsProvider.apps[id]?.app.additionalSettings['versionDetection'] =
true; true;
@@ -39,11 +44,15 @@ class _AppPageState extends State<AppPage> {
} }
appsProvider.saveApps([appsProvider.apps[id]!.app]); appsProvider.saveApps([appsProvider.apps[id]!.app]);
} }
}).catchError((e) { } catch (err) {
showError(e, context); // ignore: use_build_context_synchronously
return null; showError(err, context);
} finally {
setState(() {
updating = false;
}); });
} }
}
bool areDownloadsRunning = appsProvider.areDownloadsRunning(); bool areDownloadsRunning = appsProvider.areDownloadsRunning();
@@ -339,7 +348,7 @@ class _AppPageState extends State<AppPage> {
} }
getResetInstallStatusButton() => TextButton( getResetInstallStatusButton() => TextButton(
onPressed: app?.app == null onPressed: app?.app == null || updating
? null ? null
: () { : () {
app!.app.installedVersion = null; app!.app.installedVersion = null;
@@ -351,7 +360,8 @@ class _AppPageState extends State<AppPage> {
)); ));
getInstallOrUpdateButton() => TextButton( getInstallOrUpdateButton() => TextButton(
onPressed: (app?.app.installedVersion == null || onPressed: !updating &&
(app?.app.installedVersion == null ||
app?.app.installedVersion != app?.app.latestVersion) && app?.app.installedVersion != app?.app.latestVersion) &&
!areDownloadsRunning !areDownloadsRunning
? () async { ? () async {
@@ -398,7 +408,7 @@ class _AppPageState extends State<AppPage> {
!isVersionDetectionStandard && !isVersionDetectionStandard &&
!trackOnly) !trackOnly)
IconButton( IconButton(
onPressed: app?.downloadProgress != null onPressed: app?.downloadProgress != null || updating
? null ? null
: showMarkUpdatedDialog, : showMarkUpdatedDialog,
tooltip: tr('markUpdated'), tooltip: tr('markUpdated'),
@@ -406,7 +416,7 @@ class _AppPageState extends State<AppPage> {
if (source != null && if (source != null &&
source.combinedAppSpecificSettingFormItems.isNotEmpty) source.combinedAppSpecificSettingFormItems.isNotEmpty)
IconButton( IconButton(
onPressed: app?.downloadProgress != null onPressed: app?.downloadProgress != null || updating
? null ? null
: () async { : () async {
var values = var values =
@@ -458,7 +468,7 @@ class _AppPageState extends State<AppPage> {
: getInstallOrUpdateButton()), : getInstallOrUpdateButton()),
const SizedBox(width: 16.0), const SizedBox(width: 16.0),
IconButton( IconButton(
onPressed: app?.downloadProgress != null onPressed: app?.downloadProgress != null || updating
? null ? null
: () { : () {
appsProvider appsProvider