added animation toggle
This commit is contained in:
		| @@ -395,6 +395,7 @@ using meta_provider_callback = std::function<void(directory_item &)>; | |||||||
|  |  | ||||||
| inline constexpr auto JSON_ACCESS_KEY{"AccessKey"}; | inline constexpr auto JSON_ACCESS_KEY{"AccessKey"}; | ||||||
| inline constexpr auto JSON_AGENT_STRING{"AgentString"}; | inline constexpr auto JSON_AGENT_STRING{"AgentString"}; | ||||||
|  | inline constexpr auto JSON_ANIMATIONS{"Animations"}; | ||||||
| inline constexpr auto JSON_API_PARENT{"ApiParent"}; | inline constexpr auto JSON_API_PARENT{"ApiParent"}; | ||||||
| inline constexpr auto JSON_API_PASSWORD{"ApiPassword"}; | inline constexpr auto JSON_API_PASSWORD{"ApiPassword"}; | ||||||
| inline constexpr auto JSON_API_PATH{"ApiPath"}; | inline constexpr auto JSON_API_PATH{"ApiPath"}; | ||||||
|   | |||||||
| @@ -24,7 +24,6 @@ | |||||||
|  |  | ||||||
| #include "types/repertory.hpp" | #include "types/repertory.hpp" | ||||||
| #include "utils/atomic.hpp" | #include "utils/atomic.hpp" | ||||||
| #include <unordered_map> |  | ||||||
|  |  | ||||||
| namespace repertory::ui { | namespace repertory::ui { | ||||||
| class mgmt_app_config final { | class mgmt_app_config final { | ||||||
| @@ -36,6 +35,7 @@ private: | |||||||
|   std::atomic<bool> launch_only_{false}; |   std::atomic<bool> launch_only_{false}; | ||||||
|  |  | ||||||
| private: | private: | ||||||
|  |   std::atomic<bool> animations_{true}; | ||||||
|   utils::atomic<std::string> api_password_{"repertory"}; |   utils::atomic<std::string> api_password_{"repertory"}; | ||||||
|   std::atomic<std::uint16_t> api_port_{default_ui_mgmt_port}; |   std::atomic<std::uint16_t> api_port_{default_ui_mgmt_port}; | ||||||
|   utils::atomic<std::string> api_user_{"repertory"}; |   utils::atomic<std::string> api_user_{"repertory"}; | ||||||
| @@ -53,6 +53,8 @@ private: | |||||||
| public: | public: | ||||||
|   [[nodiscard]] auto to_json() const -> nlohmann::json; |   [[nodiscard]] auto to_json() const -> nlohmann::json; | ||||||
|  |  | ||||||
|  |   [[nodiscard]] auto get_animations() const -> bool { return animations_; } | ||||||
|  |  | ||||||
|   [[nodiscard]] auto get_api_password() const -> std::string { |   [[nodiscard]] auto get_api_password() const -> std::string { | ||||||
|     return api_password_; |     return api_password_; | ||||||
|   } |   } | ||||||
| @@ -77,6 +79,8 @@ public: | |||||||
|                                         std::string_view name) const |                                         std::string_view name) const | ||||||
|       -> std::string; |       -> std::string; | ||||||
|  |  | ||||||
|  |   void set_animations(bool animations); | ||||||
|  |  | ||||||
|   void set_api_password(std::string_view api_password); |   void set_api_password(std::string_view api_password); | ||||||
|  |  | ||||||
|   void set_api_port(std::uint16_t api_port); |   void set_api_port(std::uint16_t api_port); | ||||||
|   | |||||||
| @@ -720,7 +720,9 @@ void handlers::handle_put_setting(const httplib::Request &req, | |||||||
|   auto name = req.get_param_value("name"); |   auto name = req.get_param_value("name"); | ||||||
|   auto value = req.get_param_value("value"); |   auto value = req.get_param_value("value"); | ||||||
|  |  | ||||||
|   if (name == JSON_AUTO_START) { |   if (name == JSON_ANIMATIONS) { | ||||||
|  |     config_->set_animations(utils::string::to_bool(value)); | ||||||
|  |   } else if (name == JSON_AUTO_START) { | ||||||
|     config_->set_auto_start(utils::string::to_bool(value)); |     config_->set_auto_start(utils::string::to_bool(value)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -97,7 +97,14 @@ mgmt_app_config::mgmt_app_config(bool hidden, bool launch_only) | |||||||
|       api_user_ = data.at(JSON_API_USER).get<std::string>(); |       api_user_ = data.at(JSON_API_USER).get<std::string>(); | ||||||
|  |  | ||||||
|       auto should_save{not data.contains(JSON_AUTO_START)}; |       auto should_save{not data.contains(JSON_AUTO_START)}; | ||||||
|       auto_start_ = should_save ? false : data.at(JSON_AUTO_START).get<bool>(); |       auto_start_ = | ||||||
|  |           should_save ? auto_start_ : data.at(JSON_AUTO_START).get<bool>(); | ||||||
|  |  | ||||||
|  |       if (data.contains(JSON_ANIMATIONS)) { | ||||||
|  |         animations_ = data.at(JSON_ANIMATIONS).get<bool>(); | ||||||
|  |       } else { | ||||||
|  |         should_save = true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|       if (data.contains(JSON_MOUNT_AUTO_START)) { |       if (data.contains(JSON_MOUNT_AUTO_START)) { | ||||||
|         mount_auto_start_ = from_json<bool>(data.at(JSON_MOUNT_AUTO_START)); |         mount_auto_start_ = from_json<bool>(data.at(JSON_MOUNT_AUTO_START)); | ||||||
| @@ -378,6 +385,7 @@ void mgmt_app_config::set_mount_location(provider_type prov, | |||||||
|  |  | ||||||
| auto mgmt_app_config::to_json() const -> nlohmann::json { | auto mgmt_app_config::to_json() const -> nlohmann::json { | ||||||
|   nlohmann::json data; |   nlohmann::json data; | ||||||
|  |   data[JSON_ANIMATIONS] = animations_; | ||||||
|   data[JSON_API_PASSWORD] = api_password_; |   data[JSON_API_PASSWORD] = api_password_; | ||||||
|   data[JSON_API_PORT] = api_port_; |   data[JSON_API_PORT] = api_port_; | ||||||
|   data[JSON_API_USER] = api_user_; |   data[JSON_API_USER] = api_user_; | ||||||
|   | |||||||
| @@ -20,15 +20,41 @@ class Settings with ChangeNotifier { | |||||||
|  |  | ||||||
|   bool get autoStart => _autoStart; |   bool get autoStart => _autoStart; | ||||||
|   bool get enableAnimations => _enableAnimations; |   bool get enableAnimations => _enableAnimations; | ||||||
|   set enableAnimations(bool enable) { |  | ||||||
|     _enableAnimations = enable; |  | ||||||
|     notifyListeners(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   void _reset() { |   void _reset() { | ||||||
|     _autoStart = false; |     _autoStart = false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   Future<void> setEnableAnimations(bool value) async { | ||||||
|  |     try { | ||||||
|  |       final auth = await _auth.createAuth(); | ||||||
|  |       final response = await http.put( | ||||||
|  |         Uri.parse( | ||||||
|  |           Uri.encodeFull( | ||||||
|  |             '${getBaseUri()}/api/v1/setting?auth=$auth&name=Animations&value=$value', | ||||||
|  |           ), | ||||||
|  |         ), | ||||||
|  |       ); | ||||||
|  |  | ||||||
|  |       if (response.statusCode == 401) { | ||||||
|  |         _auth.logoff(); | ||||||
|  |         _reset(); | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (response.statusCode != 200) { | ||||||
|  |         _reset(); | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       _enableAnimations = value; | ||||||
|  |       notifyListeners(); | ||||||
|  |     } catch (e) { | ||||||
|  |       debugPrint('$e'); | ||||||
|  |       _reset(); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   Future<void> setAutoStart(bool value) async { |   Future<void> setAutoStart(bool value) async { | ||||||
|     try { |     try { | ||||||
|       final auth = await _auth.createAuth(); |       final auth = await _auth.createAuth(); | ||||||
| @@ -77,7 +103,10 @@ class Settings with ChangeNotifier { | |||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       _autoStart = jsonDecode(response.body)["AutoStart"] as bool; |       final jsonData = jsonDecode(response.body); | ||||||
|  |       _enableAnimations = jsonData["Animations"] as bool; | ||||||
|  |       _autoStart = jsonData["AutoStart"] as bool; | ||||||
|  |  | ||||||
|       notifyListeners(); |       notifyListeners(); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       debugPrint('$e'); |       debugPrint('$e'); | ||||||
|   | |||||||
| @@ -134,22 +134,36 @@ class AppScaffold extends StatelessWidget { | |||||||
|                       ), |                       ), | ||||||
|                       const SizedBox(width: constants.padding), |                       const SizedBox(width: constants.padding), | ||||||
|                       if (!showBack) ...[ |                       if (!showBack) ...[ | ||||||
|  |                         const Text("Animations"), | ||||||
|  |                         Consumer<Settings>( | ||||||
|  |                           builder: (context, settings, _) => IconButton( | ||||||
|  |                             icon: Icon( | ||||||
|  |                               settings.enableAnimations | ||||||
|  |                                   ? Icons.toggle_on | ||||||
|  |                                   : Icons.toggle_off, | ||||||
|  |                             ), | ||||||
|  |                             color: settings.enableAnimations | ||||||
|  |                                 ? scheme.primary | ||||||
|  |                                 : scheme.onSurface, | ||||||
|  |                             onPressed: () => settings.setEnableAnimations( | ||||||
|  |                               !settings.enableAnimations, | ||||||
|  |                             ), | ||||||
|  |                           ), | ||||||
|  |                         ), | ||||||
|                         const Text("Auto-start"), |                         const Text("Auto-start"), | ||||||
|                         Consumer<Settings>( |                         Consumer<Settings>( | ||||||
|                           builder: (context, settings, _) { |                           builder: (context, settings, _) => IconButton( | ||||||
|                             return IconButton( |                             icon: Icon( | ||||||
|                               icon: Icon( |                               settings.autoStart | ||||||
|                                 settings.autoStart |                                   ? Icons.toggle_on | ||||||
|                                     ? Icons.toggle_on |                                   : Icons.toggle_off, | ||||||
|                                     : Icons.toggle_off, |                             ), | ||||||
|                               ), |                             color: settings.autoStart | ||||||
|                               color: settings.autoStart |                                 ? scheme.primary | ||||||
|                                   ? scheme.primary |                                 : scheme.onSurface, | ||||||
|                                   : scheme.onSurface, |                             onPressed: () => | ||||||
|                               onPressed: () => |                                 settings.setAutoStart(!settings.autoStart), | ||||||
|                                   settings.setAutoStart(!settings.autoStart), |                           ), | ||||||
|                             ); |  | ||||||
|                           }, |  | ||||||
|                         ), |                         ), | ||||||
|                         IconButton( |                         IconButton( | ||||||
|                           tooltip: 'Settings', |                           tooltip: 'Settings', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user