added unmount handling
This commit is contained in:
parent
7d1574d042
commit
a2a1f3e905
@ -64,9 +64,10 @@ private:
|
||||
|
||||
void handle_get_mount_status(auto &&req, auto &&res) const;
|
||||
|
||||
[[nodiscard]] static auto read_process(provider_type prov,
|
||||
std::string_view name,
|
||||
std::string_view command)
|
||||
void handle_post_mount(auto &&req, auto &&res) const;
|
||||
|
||||
static auto read_process(provider_type prov, std::string_view name,
|
||||
std::string_view command)
|
||||
-> std::vector<std::string>;
|
||||
};
|
||||
} // namespace repertory::ui
|
||||
|
@ -83,6 +83,9 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
handle_get_mount_status(req, res);
|
||||
});
|
||||
|
||||
server->Post("/api/v1/mount",
|
||||
[this](auto &&req, auto &&res) { handle_post_mount(req, res); });
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
static std::atomic<httplib::Server *> this_server{server_};
|
||||
@ -200,6 +203,18 @@ void handlers::handle_get_mount_status(auto &&req, auto &&res) const {
|
||||
res.status = http_error_codes::ok;
|
||||
}
|
||||
|
||||
void handlers::handle_post_mount(auto &&req, auto &&res) const {
|
||||
auto type = req.get_param_value("type");
|
||||
auto name = req.get_param_value("name");
|
||||
auto unmount = utils::string::to_bool(req.get_param_value("unmount"));
|
||||
auto prov = provider_type_from_string(type);
|
||||
|
||||
if (unmount) {
|
||||
read_process(prov, name, "-unmount");
|
||||
}
|
||||
res.status = http_error_codes::ok;
|
||||
}
|
||||
|
||||
auto handlers::read_process(provider_type prov, std::string_view name,
|
||||
std::string_view command)
|
||||
-> std::vector<std::string> {
|
||||
|
@ -48,6 +48,18 @@ class Mount with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> mount(bool unmount) async {
|
||||
await http.post(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${Uri.base.origin}/api/v1/mount?unmount=$unmount&name=$name&type=$type',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return refresh();
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
await _fetch();
|
||||
return _fetchStatus();
|
||||
|
@ -14,6 +14,7 @@ class MountWidget extends StatefulWidget {
|
||||
|
||||
class _MountWidgetState extends State<MountWidget> {
|
||||
Timer? _timer;
|
||||
bool _enabled = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -57,7 +58,21 @@ class _MountWidgetState extends State<MountWidget> {
|
||||
mount.state,
|
||||
color: isActive ? Colors.blue : Colors.grey,
|
||||
),
|
||||
onPressed: () {},
|
||||
onPressed:
|
||||
_enabled
|
||||
? () async {
|
||||
setState(() {
|
||||
_enabled = false;
|
||||
});
|
||||
if (isActive) {
|
||||
mount.mount(isActive).then((_) {
|
||||
setState(() {
|
||||
_enabled = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
@ -5,10 +5,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
|
||||
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.12.0"
|
||||
version: "2.13.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -53,10 +53,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fake_async
|
||||
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
|
||||
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.2"
|
||||
version: "1.3.3"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@ -95,10 +95,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
|
||||
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.8"
|
||||
version: "10.0.9"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -244,10 +244,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
|
||||
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "14.3.1"
|
||||
version: "15.0.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
Loading…
x
Reference in New Issue
Block a user