timezone.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "timezone.h"
  2. #include <lib/toolbox/args.h>
  3. #include "../../../config/config.h"
  4. #include "../../../../scenes/scene_director.h"
  5. #include "../../cli_common_helpers.h"
  6. #define TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE "TIMEZONE"
  7. void totp_cli_command_timezone_print_help() {
  8. TOTP_CLI_PRINTF("\t" TOTP_CLI_COMMAND_TIMEZONE " " TOTP_CLI_OPTIONAL_PARAM(
  9. TOTP_CLI_ARG(TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE)) "\r\n");
  10. TOTP_CLI_PRINTF("\t\t" TOTP_CLI_ARG(
  11. TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE) " - " TOTP_CLI_OPTIONAL_PARAM_MARK
  12. " timezone offset in hours to be set, if not provided then current timezone offset will be printed\r\n\r\n");
  13. }
  14. void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
  15. if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
  16. return;
  17. }
  18. FuriString* temp_str = furi_string_alloc();
  19. if(args_read_string_and_trim(args, temp_str)) {
  20. float tz = strtof(furi_string_get_cstr(temp_str), NULL);
  21. if(tz >= -12.75f && tz <= 12.75f) {
  22. plugin_state->timezone_offset = tz;
  23. totp_config_file_update_timezone_offset(tz);
  24. TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
  25. if(plugin_state->current_scene == TotpSceneGenerateToken) {
  26. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  27. totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
  28. } else if(plugin_state->current_scene == TotpSceneAppSettings) {
  29. totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
  30. totp_scene_director_activate_scene(plugin_state, TotpSceneAppSettings, NULL);
  31. }
  32. } else {
  33. TOTP_CLI_PRINTF("Invalid timezone offset\r\n");
  34. }
  35. } else {
  36. TOTP_CLI_PRINTF("Current timezone offset is %f\r\n", plugin_state->timezone_offset);
  37. }
  38. furi_string_free(temp_str);
  39. }