timezone.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "timezone.h"
  2. #include <lib/toolbox/args.h>
  3. #include "../../../config/config.h"
  4. #include "../../../../scenes/scene_director.h"
  5. #include "../../cli_helpers.h"
  6. #define TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE "timezone"
  7. void totp_cli_command_timezone_docopt_commands() {
  8. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_TIMEZONE ", " TOTP_CLI_COMMAND_TIMEZONE_ALT
  9. " Get or set current timezone\r\n");
  10. }
  11. void totp_cli_command_timezone_docopt_usage() {
  12. TOTP_CLI_PRINTF(
  13. " " TOTP_CLI_COMMAND_NAME
  14. " " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_TIMEZONE " | " TOTP_CLI_COMMAND_TIMEZONE_ALT) " " DOCOPT_OPTIONAL(
  15. DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE)) "\r\n");
  16. }
  17. void totp_cli_command_timezone_docopt_arguments() {
  18. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE
  19. " Timezone offset in hours to be set.\r\n");
  20. TOTP_CLI_PRINTF(
  21. " If not provided then current timezone offset will be printed\r\n");
  22. }
  23. void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
  24. if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
  25. return;
  26. }
  27. FuriString* temp_str = furi_string_alloc();
  28. if(args_read_string_and_trim(args, temp_str)) {
  29. float tz = strtof(furi_string_get_cstr(temp_str), NULL);
  30. if(tz >= -12.75f && tz <= 12.75f) {
  31. plugin_state->timezone_offset = tz;
  32. totp_config_file_update_timezone_offset(tz);
  33. TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
  34. if(plugin_state->current_scene == TotpSceneGenerateToken) {
  35. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  36. totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
  37. } else if(plugin_state->current_scene == TotpSceneAppSettings) {
  38. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  39. totp_scene_director_activate_scene(plugin_state, TotpSceneAppSettings, NULL);
  40. }
  41. } else {
  42. TOTP_CLI_PRINTF("Invalid timezone offset\r\n");
  43. }
  44. } else {
  45. TOTP_CLI_PRINTF("Current timezone offset is %f\r\n", plugin_state->timezone_offset);
  46. }
  47. furi_string_free(temp_str);
  48. }