[ui] Implement provider test button #49

This commit is contained in:
Scott E. Graves 2025-04-23 10:53:22 -05:00
parent 1880c50fd8
commit 5f50e0204a
3 changed files with 50 additions and 12 deletions

View File

@ -15,6 +15,7 @@
* \#46 [bug] Changes to maximum cache size should be updated live
* \#47 [bug] Windows-to-Linux remote mount is allowing directory rename when directory is not empty
* \#48 [bug] Windows-to-Linux remote mount overlapped I/O is not detecting EOF for read operations
* \#49 [ui] Implement provider test button
### Changes from v2.0.5-rc

View File

@ -282,4 +282,27 @@ class Mount with ChangeNotifier {
debugPrint('$e');
}
}
Future<bool> test() async {
try {
final auth = await _auth.createAuth();
final response = await http.put(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&settings=${jsonEncode(mountConfig.settings)}',
),
),
);
if (response.statusCode == 401) {
_auth.logoff();
}
return (response.statusCode == 200);
} catch (e) {
debugPrint('$e');
}
return false;
}
}

View File

@ -113,8 +113,8 @@ class _AddMountScreenState extends State<AddMountScreen> {
),
),
),
if (_mount != null) const SizedBox(height: constants.padding),
if (_mount != null)
if (_mount != null) ...[
const SizedBox(height: constants.padding),
Expanded(
child: Card(
margin: EdgeInsets.all(0.0),
@ -129,8 +129,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
),
),
),
if (_mount != null) const SizedBox(height: constants.padding),
if (_mount != null)
const SizedBox(height: constants.padding),
Row(
children: [
ElevatedButton.icon(
@ -189,16 +188,15 @@ class _AddMountScreenState extends State<AddMountScreen> {
Navigator.pop(context);
},
),
if (_mountType == 'Sia' || _mountType == 'S3') ...[
const SizedBox(width: constants.padding),
ElevatedButton.icon(
label: const Text('Test'),
icon: const Icon(Icons.check),
onPressed: () async {},
),
],
const SizedBox(width: constants.padding),
ElevatedButton.icon(
label: const Text('Test'),
icon: const Icon(Icons.check),
onPressed: _handleProviderTest,
),
],
),
],
],
);
},
@ -234,6 +232,22 @@ class _AddMountScreenState extends State<AddMountScreen> {
});
}
Future<void> _handleProviderTest() async {
if (_mount == null) {
return;
}
final success = await _mount!.test();
if (!mounted) {
return;
}
displayErrorMessage(
context,
success ? "Success!" : "Provider settings are invalid!",
);
}
@override
void setState(VoidCallback fn) {
if (!mounted) {