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_AGENT_STRING{"AgentString"};
|
||||
inline constexpr auto JSON_ANIMATIONS{"Animations"};
|
||||
inline constexpr auto JSON_API_PARENT{"ApiParent"};
|
||||
inline constexpr auto JSON_API_PASSWORD{"ApiPassword"};
|
||||
inline constexpr auto JSON_API_PATH{"ApiPath"};
|
||||
|
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/atomic.hpp"
|
||||
#include <unordered_map>
|
||||
|
||||
namespace repertory::ui {
|
||||
class mgmt_app_config final {
|
||||
@@ -36,6 +35,7 @@ private:
|
||||
std::atomic<bool> launch_only_{false};
|
||||
|
||||
private:
|
||||
std::atomic<bool> animations_{true};
|
||||
utils::atomic<std::string> api_password_{"repertory"};
|
||||
std::atomic<std::uint16_t> api_port_{default_ui_mgmt_port};
|
||||
utils::atomic<std::string> api_user_{"repertory"};
|
||||
@@ -53,6 +53,8 @@ private:
|
||||
public:
|
||||
[[nodiscard]] auto to_json() const -> nlohmann::json;
|
||||
|
||||
[[nodiscard]] auto get_animations() const -> bool { return animations_; }
|
||||
|
||||
[[nodiscard]] auto get_api_password() const -> std::string {
|
||||
return api_password_;
|
||||
}
|
||||
@@ -77,6 +79,8 @@ public:
|
||||
std::string_view name) const
|
||||
-> std::string;
|
||||
|
||||
void set_animations(bool animations);
|
||||
|
||||
void set_api_password(std::string_view api_password);
|
||||
|
||||
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 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));
|
||||
}
|
||||
|
||||
|
@@ -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>();
|
||||
|
||||
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)) {
|
||||
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 {
|
||||
nlohmann::json data;
|
||||
data[JSON_ANIMATIONS] = animations_;
|
||||
data[JSON_API_PASSWORD] = api_password_;
|
||||
data[JSON_API_PORT] = api_port_;
|
||||
data[JSON_API_USER] = api_user_;
|
||||
|
@@ -20,15 +20,41 @@ class Settings with ChangeNotifier {
|
||||
|
||||
bool get autoStart => _autoStart;
|
||||
bool get enableAnimations => _enableAnimations;
|
||||
set enableAnimations(bool enable) {
|
||||
_enableAnimations = enable;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _reset() {
|
||||
_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 {
|
||||
try {
|
||||
final auth = await _auth.createAuth();
|
||||
@@ -77,7 +103,10 @@ class Settings with ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
|
||||
_autoStart = jsonDecode(response.body)["AutoStart"] as bool;
|
||||
final jsonData = jsonDecode(response.body);
|
||||
_enableAnimations = jsonData["Animations"] as bool;
|
||||
_autoStart = jsonData["AutoStart"] as bool;
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('$e');
|
||||
|
@@ -134,10 +134,25 @@ class AppScaffold extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: constants.padding),
|
||||
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"),
|
||||
Consumer<Settings>(
|
||||
builder: (context, settings, _) {
|
||||
return IconButton(
|
||||
builder: (context, settings, _) => IconButton(
|
||||
icon: Icon(
|
||||
settings.autoStart
|
||||
? Icons.toggle_on
|
||||
@@ -148,8 +163,7 @@ class AppScaffold extends StatelessWidget {
|
||||
: scheme.onSurface,
|
||||
onPressed: () =>
|
||||
settings.setAutoStart(!settings.autoStart),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Settings',
|
||||
|
Reference in New Issue
Block a user