timezone.c 1.9 KB

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