From d57fa022d8f09863f113c201f89f112f5b021d11 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 18 Mar 2025 07:30:54 -0500 Subject: [PATCH] wait for mount/unmount to complete --- web/repertory/lib/models/mount.dart | 30 ++++++++++++++++++--- web/repertory/lib/widgets/mount_widget.dart | 3 +-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/web/repertory/lib/models/mount.dart b/web/repertory/lib/models/mount.dart index bcf7f94f..170417e4 100644 --- a/web/repertory/lib/models/mount.dart +++ b/web/repertory/lib/models/mount.dart @@ -10,6 +10,8 @@ class Mount with ChangeNotifier { final MountConfig mountConfig; final MountList? _mountList; bool _isMounting = false; + bool _isRefreshing = false; + Mount(this.mountConfig, this._mountList, {isAdd = false}) { if (isAdd) { return; @@ -42,8 +44,11 @@ class Mount with ChangeNotifier { return; } - mountConfig.updateSettings(jsonDecode(response.body)); + if (_isMounting) { + return; + } + mountConfig.updateSettings(jsonDecode(response.body)); notifyListeners(); } catch (e) { debugPrint('$e'); @@ -69,6 +74,10 @@ class Mount with ChangeNotifier { return; } + if (_isMounting) { + return; + } + mountConfig.updateStatus(jsonDecode(response.body)); notifyListeners(); } catch (e) { @@ -83,6 +92,11 @@ class Mount with ChangeNotifier { mountConfig.mounted = null; notifyListeners(); + var count = 0; + while (_isRefreshing && count++ < 10) { + await Future.delayed(Duration(seconds: 1)); + } + final response = await http.post( Uri.parse( Uri.encodeFull( @@ -112,12 +126,20 @@ class Mount with ChangeNotifier { } Future refresh({bool force = false}) async { - if (!force && _isMounting) { + if (_isRefreshing || (!force && _isMounting)) { return; } - await _fetch(); - return _fetchStatus(); + _isRefreshing = true; + + try { + await _fetch(); + await _fetchStatus(); + } catch (e) { + debugPrint('$e'); + } + + _isRefreshing = false; } Future setValue(String key, String value) async { diff --git a/web/repertory/lib/widgets/mount_widget.dart b/web/repertory/lib/widgets/mount_widget.dart index e5ec1b74..8bb6d051 100644 --- a/web/repertory/lib/widgets/mount_widget.dart +++ b/web/repertory/lib/widgets/mount_widget.dart @@ -102,7 +102,6 @@ class _MountWidgetState extends State { } final success = await mount.mount(mount.mounted!, location: location); - if (success || mount.mounted! || constants.navigatorKey.currentContext == null || @@ -111,7 +110,7 @@ class _MountWidgetState extends State { } displayErrorMessage(context, "Mount location is not available"); - return cleanup(); + cleanup(); } : null; }