wait for mount/unmount to complete
This commit is contained in:
parent
ee1638e1dd
commit
d57fa022d8
@ -10,6 +10,8 @@ class Mount with ChangeNotifier {
|
|||||||
final MountConfig mountConfig;
|
final MountConfig mountConfig;
|
||||||
final MountList? _mountList;
|
final MountList? _mountList;
|
||||||
bool _isMounting = false;
|
bool _isMounting = false;
|
||||||
|
bool _isRefreshing = false;
|
||||||
|
|
||||||
Mount(this.mountConfig, this._mountList, {isAdd = false}) {
|
Mount(this.mountConfig, this._mountList, {isAdd = false}) {
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
return;
|
return;
|
||||||
@ -42,8 +44,11 @@ class Mount with ChangeNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mountConfig.updateSettings(jsonDecode(response.body));
|
if (_isMounting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mountConfig.updateSettings(jsonDecode(response.body));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('$e');
|
debugPrint('$e');
|
||||||
@ -69,6 +74,10 @@ class Mount with ChangeNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_isMounting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mountConfig.updateStatus(jsonDecode(response.body));
|
mountConfig.updateStatus(jsonDecode(response.body));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -83,6 +92,11 @@ class Mount with ChangeNotifier {
|
|||||||
mountConfig.mounted = null;
|
mountConfig.mounted = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
while (_isRefreshing && count++ < 10) {
|
||||||
|
await Future.delayed(Duration(seconds: 1));
|
||||||
|
}
|
||||||
|
|
||||||
final response = await http.post(
|
final response = await http.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
@ -112,12 +126,20 @@ class Mount with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh({bool force = false}) async {
|
Future<void> refresh({bool force = false}) async {
|
||||||
if (!force && _isMounting) {
|
if (_isRefreshing || (!force && _isMounting)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _fetch();
|
_isRefreshing = true;
|
||||||
return _fetchStatus();
|
|
||||||
|
try {
|
||||||
|
await _fetch();
|
||||||
|
await _fetchStatus();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
|
|
||||||
|
_isRefreshing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setValue(String key, String value) async {
|
Future<void> setValue(String key, String value) async {
|
||||||
|
@ -102,7 +102,6 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final success = await mount.mount(mount.mounted!, location: location);
|
final success = await mount.mount(mount.mounted!, location: location);
|
||||||
|
|
||||||
if (success ||
|
if (success ||
|
||||||
mount.mounted! ||
|
mount.mounted! ||
|
||||||
constants.navigatorKey.currentContext == null ||
|
constants.navigatorKey.currentContext == null ||
|
||||||
@ -111,7 +110,7 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
displayErrorMessage(context, "Mount location is not available");
|
displayErrorMessage(context, "Mount location is not available");
|
||||||
return cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user