From a2a1f3e905de665c1f32dc8e132c99cd03f29e99 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 1 Mar 2025 16:51:08 -0600 Subject: [PATCH] added unmount handling --- repertory/repertory/include/ui/handlers.hpp | 7 ++++--- repertory/repertory/src/ui/handlers.cpp | 15 +++++++++++++++ web/repertory/lib/models/mount.dart | 12 ++++++++++++ web/repertory/lib/widgets/mount_widget.dart | 17 ++++++++++++++++- web/repertory/pubspec.lock | 16 ++++++++-------- 5 files changed, 55 insertions(+), 12 deletions(-) diff --git a/repertory/repertory/include/ui/handlers.hpp b/repertory/repertory/include/ui/handlers.hpp index 6f75b54f..3bfbc84c 100644 --- a/repertory/repertory/include/ui/handlers.hpp +++ b/repertory/repertory/include/ui/handlers.hpp @@ -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; }; } // namespace repertory::ui diff --git a/repertory/repertory/src/ui/handlers.cpp b/repertory/repertory/src/ui/handlers.cpp index 5b6574cf..1f679026 100644 --- a/repertory/repertory/src/ui/handlers.cpp +++ b/repertory/repertory/src/ui/handlers.cpp @@ -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 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 { diff --git a/web/repertory/lib/models/mount.dart b/web/repertory/lib/models/mount.dart index add14de2..b2271f20 100644 --- a/web/repertory/lib/models/mount.dart +++ b/web/repertory/lib/models/mount.dart @@ -48,6 +48,18 @@ class Mount with ChangeNotifier { notifyListeners(); } + Future 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 refresh() async { await _fetch(); return _fetchStatus(); diff --git a/web/repertory/lib/widgets/mount_widget.dart b/web/repertory/lib/widgets/mount_widget.dart index b66f31f1..f4a15257 100644 --- a/web/repertory/lib/widgets/mount_widget.dart +++ b/web/repertory/lib/widgets/mount_widget.dart @@ -14,6 +14,7 @@ class MountWidget extends StatefulWidget { class _MountWidgetState extends State { Timer? _timer; + bool _enabled = true; @override Widget build(BuildContext context) { @@ -57,7 +58,21 @@ class _MountWidgetState extends State { 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, ), ); }, diff --git a/web/repertory/pubspec.lock b/web/repertory/pubspec.lock index e85e2535..67781aef 100644 --- a/web/repertory/pubspec.lock +++ b/web/repertory/pubspec.lock @@ -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: