Compare commits
4 Commits
7605be809c
...
b93e2978b0
Author | SHA1 | Date | |
---|---|---|---|
b93e2978b0 | |||
ece002f25b | |||
b9f5f774e2 | |||
52d210974b |
@ -334,6 +334,7 @@ void handlers::handle_post_mount(auto &&req, auto &&res) const {
|
||||
} else {
|
||||
if (not utils::file::directory{location}.exists()) {
|
||||
res.status = http_error_codes::internal_error;
|
||||
return;
|
||||
}
|
||||
|
||||
launch_process(prov, name, fmt::format(R"("{}")", location), true);
|
||||
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:repertory/constants.dart' as constants;
|
||||
import 'package:repertory/helpers.dart';
|
||||
import 'package:repertory/models/mount_list.dart';
|
||||
import 'package:repertory/types/mount_config.dart';
|
||||
@ -73,9 +74,9 @@ class Mount with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> mount(bool unmount, {String? location}) async {
|
||||
Future<bool> mount(bool unmount, {String? location}) async {
|
||||
try {
|
||||
await http.post(
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
|
||||
@ -83,10 +84,16 @@ class Mount with ChangeNotifier {
|
||||
),
|
||||
);
|
||||
|
||||
return refresh();
|
||||
if (!unmount && response.statusCode == 500) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await refresh();
|
||||
} catch (e) {
|
||||
debugPrint('$e');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
|
@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:repertory/constants.dart' as constants;
|
||||
import 'package:repertory/helpers.dart';
|
||||
import 'package:repertory/models/mount.dart';
|
||||
|
||||
@ -140,9 +141,15 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
setState(() {
|
||||
_enabled = true;
|
||||
});
|
||||
}
|
||||
|
||||
if (location == null) {
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@ -153,21 +160,34 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
mount
|
||||
.mount(isActive, location: location)
|
||||
.then((_) {
|
||||
setState(() {
|
||||
_enabled = true;
|
||||
});
|
||||
})
|
||||
.catchError((_) {
|
||||
setState(() {
|
||||
_enabled = true;
|
||||
});
|
||||
});
|
||||
final success = await mount.mount(
|
||||
isActive,
|
||||
location: location,
|
||||
);
|
||||
|
||||
if (success ||
|
||||
isActive ||
|
||||
constants.navigatorKey.currentContext == null ||
|
||||
!constants.navigatorKey.currentContext!.mounted) {
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(
|
||||
constants.navigatorKey.currentContext!,
|
||||
).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text(
|
||||
"Mount location not found",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cleanup();
|
||||
}
|
||||
: null,
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user