ui changes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-03-15 21:37:47 -05:00
parent abd7e24b5e
commit d3070ffee1
3 changed files with 77 additions and 72 deletions

View File

@@ -76,6 +76,9 @@ class Mount with ChangeNotifier {
Future<bool> mount(bool unmount, {String? location}) async { Future<bool> mount(bool unmount, {String? location}) async {
try { try {
mountConfig.state = null;
notifyListeners();
final response = await http.post( final response = await http.post(
Uri.parse( Uri.parse(
Uri.encodeFull( Uri.encodeFull(
@@ -84,11 +87,11 @@ class Mount with ChangeNotifier {
), ),
); );
await refresh();
if (!unmount && response.statusCode == 500) { if (!unmount && response.statusCode == 500) {
return false; return false;
} }
await refresh();
} catch (e) { } catch (e) {
debugPrint('$e'); debugPrint('$e');
} }

View File

@@ -23,6 +23,7 @@ class MountConfig {
UnmodifiableMapView<String, dynamic> get settings => UnmodifiableMapView<String, dynamic> get settings =>
UnmodifiableMapView<String, dynamic>(_settings); UnmodifiableMapView<String, dynamic>(_settings);
IconData? get state => _state; IconData? get state => _state;
set state(value) => _state = value;
String get type => _type; String get type => _type;
void updateSettings(Map<String, dynamic> settings) { void updateSettings(Map<String, dynamic> settings) {

View File

@@ -19,6 +19,67 @@ class _MountWidgetState extends State<MountWidget> {
Timer? _timer; Timer? _timer;
bool _enabled = true; bool _enabled = true;
Future<String?> _getMountLocation(context, mount, isMounted) async {
if (isMounted) {
return null;
}
if (!mount.path.isEmpty) {
return mount.path;
}
String? location = await mount.getMountLocation();
if (location != null) {
return location;
}
if (!context.mounted) {
return location;
}
String? currentLocation;
return await showDialog(
context: context,
builder: (context) {
return AlertDialog(
actions: [
TextButton(
child: const Text('Cancel'),
onPressed: () => Navigator.of(context).pop(null),
),
TextButton(
child: const Text('OK'),
onPressed: () {
final result = getSettingValidators('Path').firstWhereOrNull(
(validator) => !validator(currentLocation ?? ''),
);
if (result != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text(
"Mount location is not valid",
textAlign: TextAlign.center,
),
),
);
return;
}
Navigator.of(context).pop(currentLocation);
},
),
],
content: TextField(
autofocus: true,
controller: TextEditingController(text: currentLocation),
inputFormatters: [FilteringTextInputFormatter.deny(RegExp(r'\s'))],
onChanged: (value) => currentLocation = value,
),
title: const Text('Set Mount Location'),
);
},
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Card( return Card(
@@ -31,7 +92,7 @@ class _MountWidgetState extends State<MountWidget> {
? Colors.white38 ? Colors.white38
: Colors.black87; : Colors.black87;
final isActive = mount.state == Icons.toggle_on; final isMounted = mount.state == Icons.toggle_on;
final nameText = SelectableText( final nameText = SelectableText(
formatMountName(mount.type, mount.name), formatMountName(mount.type, mount.name),
style: TextStyle(color: subTextColor), style: TextStyle(color: subTextColor),
@@ -66,7 +127,7 @@ class _MountWidgetState extends State<MountWidget> {
icon: Icon( icon: Icon(
mount.state ?? Icons.hourglass_top, mount.state ?? Icons.hourglass_top,
color: color:
isActive ? Color.fromARGB(255, 163, 96, 76) : subTextColor, isMounted ? Color.fromARGB(255, 163, 96, 76) : subTextColor,
), ),
onPressed: onPressed:
_enabled && mount.state != null _enabled && mount.state != null
@@ -75,71 +136,11 @@ class _MountWidgetState extends State<MountWidget> {
_enabled = false; _enabled = false;
}); });
String? location = mount.path; final location = await _getMountLocation(
if (!isActive && mount.path.isEmpty) { context,
location = await mount.getMountLocation(); mount,
if (location == null) { isMounted,
String? updatedValue; );
if (context.mounted) {
location = await showDialog(
context: context,
builder: (context) {
return AlertDialog(
actions: [
TextButton(
child: const Text('Cancel'),
onPressed:
() =>
Navigator.of(context).pop(null),
),
TextButton(
child: const Text('OK'),
onPressed: () {
final result = getSettingValidators(
'Path',
).firstWhereOrNull(
(validator) =>
!validator(updatedValue ?? ''),
);
if (result != null) {
ScaffoldMessenger.of(
context,
).showSnackBar(
SnackBar(
content: const Text(
"Mount location is not valid",
textAlign: TextAlign.center,
),
),
);
return;
}
Navigator.of(
context,
).pop(updatedValue);
},
),
],
content: TextField(
autofocus: true,
controller: TextEditingController(
text: updatedValue,
),
inputFormatters: [
FilteringTextInputFormatter.deny(
RegExp(r'\s'),
),
],
onChanged:
(value) => updatedValue = value,
),
title: const Text('Set Mount Location'),
);
},
);
}
}
}
cleanup() { cleanup() {
setState(() { setState(() {
@@ -147,7 +148,7 @@ class _MountWidgetState extends State<MountWidget> {
}); });
} }
if (location == null) { if (!isMounted && location == null) {
if (!context.mounted) { if (!context.mounted) {
return cleanup(); return cleanup();
} }
@@ -165,12 +166,12 @@ class _MountWidgetState extends State<MountWidget> {
} }
final success = await mount.mount( final success = await mount.mount(
isActive, isMounted,
location: location, location: location,
); );
if (success || if (success ||
isActive || isMounted ||
constants.navigatorKey.currentContext == null || constants.navigatorKey.currentContext == null ||
!constants.navigatorKey.currentContext!.mounted) { !constants.navigatorKey.currentContext!.mounted) {
return cleanup(); return cleanup();