[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 * \#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 * \#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 * \#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 ### Changes from v2.0.5-rc

View File

@ -282,4 +282,27 @@ class Mount with ChangeNotifier {
debugPrint('$e'); 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( Expanded(
child: Card( child: Card(
margin: EdgeInsets.all(0.0), margin: EdgeInsets.all(0.0),
@ -129,8 +129,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
), ),
), ),
), ),
if (_mount != null) const SizedBox(height: constants.padding), const SizedBox(height: constants.padding),
if (_mount != null)
Row( Row(
children: [ children: [
ElevatedButton.icon( ElevatedButton.icon(
@ -189,17 +188,16 @@ class _AddMountScreenState extends State<AddMountScreen> {
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
if (_mountType == 'Sia' || _mountType == 'S3') ...[
const SizedBox(width: constants.padding), const SizedBox(width: constants.padding),
ElevatedButton.icon( ElevatedButton.icon(
label: const Text('Test'), label: const Text('Test'),
icon: const Icon(Icons.check), icon: const Icon(Icons.check),
onPressed: () async {}, 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 @override
void setState(VoidCallback fn) { void setState(VoidCallback fn) {
if (!mounted) { if (!mounted) {