timezone.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 " Get or set current timezone\r\n");
  9. }
  10. void totp_cli_command_timezone_docopt_usage() {
  11. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_TIMEZONE " | " TOTP_CLI_COMMAND_TIMEZONE_ALT) " " DOCOPT_OPTIONAL(DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE)) "\r\n");
  12. }
  13. void totp_cli_command_timezone_docopt_arguments() {
  14. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE " Timezone offset in hours to be set.\r\n");
  15. TOTP_CLI_PRINTF(" If not provided then current timezone offset will be printed\r\n");
  16. }
  17. void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
  18. if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
  19. return;
  20. }
  21. FuriString* temp_str = furi_string_alloc();
  22. if(args_read_string_and_trim(args, temp_str)) {
  23. float tz = strtof(furi_string_get_cstr(temp_str), NULL);
  24. if(tz >= -12.75f && tz <= 12.75f) {
  25. plugin_state->timezone_offset = tz;
  26. totp_config_file_update_timezone_offset(tz);
  27. TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
  28. if(plugin_state->current_scene == TotpSceneGenerateToken) {
  29. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  30. totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
  31. } else if(plugin_state->current_scene == TotpSceneAppSettings) {
  32. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  33. totp_scene_director_activate_scene(plugin_state, TotpSceneAppSettings, NULL);
  34. }
  35. } else {
  36. TOTP_CLI_PRINTF("Invalid timezone offset\r\n");
  37. }
  38. } else {
  39. TOTP_CLI_PRINTF("Current timezone offset is %f\r\n", plugin_state->timezone_offset);
  40. }
  41. furi_string_free(temp_str);
  42. }