return available drive letters on windows
This commit is contained in:
@@ -101,6 +101,34 @@ class Mount with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> getAvailableLocations() async {
|
||||
try {
|
||||
final auth = await _auth.createAuth();
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${getBaseUri()}/api/v1/mount_location?auth=$auth&name=$name&type=$type',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
_auth.logoff();
|
||||
return <String>[];
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return <String>[];
|
||||
}
|
||||
|
||||
return jsonDecode(response.body) as List<String>;
|
||||
} catch (e) {
|
||||
debugPrint('$e');
|
||||
}
|
||||
|
||||
return <String>[];
|
||||
}
|
||||
|
||||
Future<String?> getMountLocation() async {
|
||||
try {
|
||||
final auth = await _auth.createAuth();
|
||||
|
@@ -149,39 +149,66 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
return location;
|
||||
}
|
||||
|
||||
final available = await mount.getAvailableLocations();
|
||||
|
||||
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) {
|
||||
return displayErrorMessage(
|
||||
context,
|
||||
"Mount location is not valid",
|
||||
);
|
||||
}
|
||||
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'),
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
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) {
|
||||
return displayErrorMessage(
|
||||
context,
|
||||
"Mount location is not valid",
|
||||
);
|
||||
}
|
||||
Navigator.of(context).pop(currentLocation);
|
||||
},
|
||||
),
|
||||
],
|
||||
content:
|
||||
available.isEmpty
|
||||
? TextField(
|
||||
autofocus: true,
|
||||
controller: TextEditingController(
|
||||
text: currentLocation,
|
||||
),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s')),
|
||||
],
|
||||
onChanged:
|
||||
(value) => setState(() => currentLocation = value),
|
||||
)
|
||||
: DropdownButton<String>(
|
||||
value: currentLocation,
|
||||
onChanged:
|
||||
(value) => setState(() => currentLocation = value),
|
||||
items:
|
||||
available.map<DropdownMenuItem<String>>((item) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
title: const Text('Set Mount Location'),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user