timezone.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <lib/toolbox/args.h>
  2. #include <flipper_application/flipper_application.h>
  3. #include "../../../services/config/config.h"
  4. #include "../../../ui/scene_director.h"
  5. #include "../../cli_helpers.h"
  6. #include "../../cli_plugin_interface.h"
  7. #include "../../cli_shared_methods.h"
  8. static void handle(PluginState* plugin_state, FuriString* args, PipeSide* pipe) {
  9. UNUSED(args);
  10. UNUSED(plugin_state);
  11. if(!totp_cli_ensure_authenticated(plugin_state, pipe)) {
  12. return;
  13. }
  14. FuriString* temp_str = furi_string_alloc();
  15. if(args_read_string_and_trim(args, temp_str)) {
  16. char* strtof_endptr;
  17. float tz = strtof(furi_string_get_cstr(temp_str), &strtof_endptr);
  18. if(*strtof_endptr == 0 && tz >= -12.75f && tz <= 14.75f) {
  19. TOTP_CLI_LOCK_UI(plugin_state);
  20. plugin_state->timezone_offset = tz;
  21. if(totp_config_file_update_timezone_offset(plugin_state)) {
  22. TOTP_CLI_PRINTF_SUCCESS("Timezone is set to %f\r\n", (double)tz);
  23. } else {
  24. TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
  25. }
  26. TOTP_CLI_UNLOCK_UI(plugin_state);
  27. } else {
  28. TOTP_CLI_PRINTF_ERROR("Invalid timezone offset\r\n");
  29. }
  30. } else {
  31. TOTP_CLI_PRINTF_INFO(
  32. "Current timezone offset is %f\r\n", (double)plugin_state->timezone_offset);
  33. }
  34. furi_string_free(temp_str);
  35. }
  36. static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Timezone", .handle = &handle};
  37. static const FlipperAppPluginDescriptor plugin_descriptor = {
  38. .appid = PLUGIN_APP_ID,
  39. .ep_api_version = PLUGIN_API_VERSION,
  40. .entry_point = &plugin,
  41. };
  42. const FlipperAppPluginDescriptor* totp_cli_timezone_plugin_ep() {
  43. return &plugin_descriptor;
  44. }