reset.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <flipper_application/flipper_application.h>
  2. #include "../../cli_helpers.h"
  3. #include "../../cli_shared_methods.h"
  4. #include "../../cli_plugin_interface.h"
  5. #include "../../../ui/scene_director.h"
  6. #include "../../../services/config/config.h"
  7. #define TOTP_CLI_RESET_CONFIRMATION_KEYWORD "YES"
  8. static void handle(PluginState* plugin_state, FuriString* args, PipeSide* pipe) {
  9. UNUSED(args);
  10. TOTP_CLI_LOCK_UI(plugin_state);
  11. TOTP_CLI_PRINTF_WARNING(
  12. "As a result of reset all the settings and tokens will be permanently lost.\r\n");
  13. TOTP_CLI_PRINTF_WARNING("Do you really want to reset application?\r\n");
  14. TOTP_CLI_PRINTF_WARNING("Type \"" TOTP_CLI_RESET_CONFIRMATION_KEYWORD
  15. "\" and hit <ENTER> to confirm:\r\n");
  16. FuriString* temp_str = furi_string_alloc();
  17. bool is_confirmed = totp_cli_read_line(pipe, temp_str, false) &&
  18. furi_string_cmpi_str(temp_str, TOTP_CLI_RESET_CONFIRMATION_KEYWORD) == 0;
  19. furi_string_free(temp_str);
  20. if(is_confirmed) {
  21. totp_config_file_reset(plugin_state);
  22. TOTP_CLI_PRINTF_SUCCESS("Application has been successfully reset to default.\r\n");
  23. TOTP_CLI_PRINTF_SUCCESS("Now application will be closed to apply all the changes.\r\n");
  24. totp_cli_force_close_app(plugin_state->event_queue);
  25. } else {
  26. TOTP_CLI_PRINTF_INFO("Action was not confirmed by user\r\n");
  27. TOTP_CLI_UNLOCK_UI(plugin_state);
  28. }
  29. }
  30. static const CliPlugin plugin = {.name = "TOTP CLI Plugin: Reset", .handle = &handle};
  31. static const FlipperAppPluginDescriptor plugin_descriptor = {
  32. .appid = PLUGIN_APP_ID,
  33. .ep_api_version = PLUGIN_API_VERSION,
  34. .entry_point = &plugin,
  35. };
  36. const FlipperAppPluginDescriptor* totp_cli_reset_plugin_ep() {
  37. return &plugin_descriptor;
  38. }