2023-01-06 23:07:26 +00:00
|
|
|
#include "reset.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2023-04-13 18:20:29 +00:00
|
|
|
#include <furi/core/string.h>
|
2023-01-06 23:07:26 +00:00
|
|
|
#include "../../cli_helpers.h"
|
2023-04-26 20:50:37 +00:00
|
|
|
#include "../../../ui/scene_director.h"
|
2023-01-06 23:07:26 +00:00
|
|
|
#include "../../../services/config/config.h"
|
|
|
|
|
|
|
|
#define TOTP_CLI_RESET_CONFIRMATION_KEYWORD "YES"
|
|
|
|
|
|
|
|
void totp_cli_command_reset_docopt_commands() {
|
|
|
|
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_RESET
|
|
|
|
" Reset application to default settings\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void totp_cli_command_reset_docopt_usage() {
|
|
|
|
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_RESET "\r\n");
|
|
|
|
}
|
|
|
|
|
2023-04-26 20:50:37 +00:00
|
|
|
void totp_cli_command_reset_handle(
|
|
|
|
PluginState* plugin_state,
|
|
|
|
Cli* cli,
|
|
|
|
FuriMessageQueue* event_queue) {
|
|
|
|
TOTP_CLI_LOCK_UI(plugin_state);
|
2023-03-09 15:40:09 +00:00
|
|
|
TOTP_CLI_PRINTF_WARNING(
|
2023-01-06 23:07:26 +00:00
|
|
|
"As a result of reset all the settings and tokens will be permanently lost.\r\n");
|
2023-03-09 15:40:09 +00:00
|
|
|
TOTP_CLI_PRINTF_WARNING("Do you really want to reset application?\r\n");
|
|
|
|
TOTP_CLI_PRINTF_WARNING("Type \"" TOTP_CLI_RESET_CONFIRMATION_KEYWORD
|
|
|
|
"\" and hit <ENTER> to confirm:\r\n");
|
2023-01-06 23:07:26 +00:00
|
|
|
FuriString* temp_str = furi_string_alloc();
|
|
|
|
bool is_confirmed = totp_cli_read_line(cli, temp_str, false) &&
|
|
|
|
furi_string_cmpi_str(temp_str, TOTP_CLI_RESET_CONFIRMATION_KEYWORD) == 0;
|
|
|
|
furi_string_free(temp_str);
|
|
|
|
if(is_confirmed) {
|
2023-04-26 20:50:37 +00:00
|
|
|
totp_config_file_reset(plugin_state);
|
2023-03-09 15:40:09 +00:00
|
|
|
TOTP_CLI_PRINTF_SUCCESS("Application has been successfully reset to default.\r\n");
|
|
|
|
TOTP_CLI_PRINTF_SUCCESS("Now application will be closed to apply all the changes.\r\n");
|
2023-01-06 23:07:26 +00:00
|
|
|
totp_cli_force_close_app(event_queue);
|
|
|
|
} else {
|
2023-03-09 15:40:09 +00:00
|
|
|
TOTP_CLI_PRINTF_INFO("Action was not confirmed by user\r\n");
|
2023-04-26 20:50:37 +00:00
|
|
|
TOTP_CLI_UNLOCK_UI(plugin_state);
|
2023-01-06 23:07:26 +00:00
|
|
|
}
|
|
|
|
}
|