mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 16:18:35 -07:00
Update TOTP
This commit is contained in:
@@ -29,7 +29,7 @@ void view_unlock_model(View* view) {
|
||||
|
||||
static void commit_text_input_callback(void* context) {
|
||||
InputTextSceneState* text_input_state = (InputTextSceneState*)context;
|
||||
if(text_input_state->callback != 0) {
|
||||
if(text_input_state->callback != NULL) {
|
||||
InputTextSceneCallbackResult* result = malloc(sizeof(InputTextSceneCallbackResult));
|
||||
furi_check(result != NULL);
|
||||
result->user_input_length =
|
||||
|
||||
@@ -36,7 +36,7 @@ typedef struct {
|
||||
InputTextSceneContext* token_name_input_context;
|
||||
InputTextSceneContext* token_secret_input_context;
|
||||
InputTextSceneState* input_state;
|
||||
uint32_t input_started_at;
|
||||
bool text_input_mode;
|
||||
int16_t screen_y_offset;
|
||||
TokenHashAlgo algo;
|
||||
uint8_t digits_count_index;
|
||||
@@ -56,7 +56,7 @@ static void on_token_name_user_comitted(InputTextSceneCallbackResult* result) {
|
||||
free(scene_state->token_name);
|
||||
scene_state->token_name = result->user_input;
|
||||
scene_state->token_name_length = result->user_input_length;
|
||||
scene_state->input_started_at = 0;
|
||||
scene_state->text_input_mode = false;
|
||||
free(result);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ static void on_token_secret_user_comitted(InputTextSceneCallbackResult* result)
|
||||
free(scene_state->token_secret);
|
||||
scene_state->token_secret = result->user_input;
|
||||
scene_state->token_secret_length = result->user_input_length;
|
||||
scene_state->input_started_at = 0;
|
||||
scene_state->text_input_mode = false;
|
||||
free(result);
|
||||
}
|
||||
|
||||
@@ -127,8 +127,8 @@ void totp_scene_add_new_token_activate(PluginState* plugin_state) {
|
||||
}
|
||||
|
||||
void totp_scene_add_new_token_render(Canvas* const canvas, PluginState* plugin_state) {
|
||||
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
||||
if(scene_state->input_started_at > 0) {
|
||||
SceneState* scene_state = plugin_state->current_scene_state;
|
||||
if(scene_state->text_input_mode) {
|
||||
totp_input_text_render(canvas, scene_state->input_state);
|
||||
return;
|
||||
}
|
||||
@@ -200,63 +200,81 @@ bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState
|
||||
return true;
|
||||
}
|
||||
|
||||
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
||||
if(scene_state->input_started_at > 0 &&
|
||||
furi_get_tick() - scene_state->input_started_at > 300) {
|
||||
SceneState* scene_state = plugin_state->current_scene_state;
|
||||
|
||||
if(event->input.type == InputTypeLong && event->input.key == InputKeyBack) {
|
||||
if(scene_state->text_input_mode) {
|
||||
scene_state->text_input_mode = false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(scene_state->text_input_mode) {
|
||||
if(event->input.type == InputTypeShort && event->input.key == InputKeyBack) {
|
||||
PluginEvent long_back_cb_evt = {
|
||||
.type = event->type, .input.key = InputKeyBack, .input.type = InputTypeLong};
|
||||
return totp_input_text_handle_event(&long_back_cb_evt, scene_state->input_state);
|
||||
}
|
||||
|
||||
return totp_input_text_handle_event(event, scene_state->input_state);
|
||||
}
|
||||
|
||||
if(event->input.type == InputTypeLong && event->input.key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(event->input.type != InputTypePress) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control,
|
||||
-1,
|
||||
TokenNameTextBox,
|
||||
ConfirmButton,
|
||||
RollOverflowBehaviorStop);
|
||||
update_screen_y_offset(scene_state);
|
||||
break;
|
||||
case InputKeyDown:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control,
|
||||
1,
|
||||
TokenNameTextBox,
|
||||
ConfirmButton,
|
||||
RollOverflowBehaviorStop);
|
||||
update_screen_y_offset(scene_state);
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(scene_state->selected_control == TokenAlgoSelect) {
|
||||
totp_roll_value_uint8_t(&scene_state->algo, 1, SHA1, STEAM, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenLengthSelect) {
|
||||
if(event->input.type == InputTypePress) {
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->digits_count_index, 1, 0, 2, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenDurationSelect) {
|
||||
totp_roll_value_uint8_t(&scene_state->duration, 15, 15, 255, RollOverflowBehaviorStop);
|
||||
update_duration_text(scene_state);
|
||||
&scene_state->selected_control,
|
||||
-1,
|
||||
TokenNameTextBox,
|
||||
ConfirmButton,
|
||||
RollOverflowBehaviorStop);
|
||||
update_screen_y_offset(scene_state);
|
||||
break;
|
||||
case InputKeyDown:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control,
|
||||
1,
|
||||
TokenNameTextBox,
|
||||
ConfirmButton,
|
||||
RollOverflowBehaviorStop);
|
||||
update_screen_y_offset(scene_state);
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(scene_state->selected_control == TokenAlgoSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->algo, 1, SHA1, STEAM, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenLengthSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->digits_count_index, 1, 0, 2, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenDurationSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->duration, 15, 15, 255, RollOverflowBehaviorStop);
|
||||
update_duration_text(scene_state);
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(scene_state->selected_control == TokenAlgoSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->algo, -1, SHA1, STEAM, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenLengthSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->digits_count_index, -1, 0, 2, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenDurationSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->duration, -15, 15, 255, RollOverflowBehaviorStop);
|
||||
update_duration_text(scene_state);
|
||||
}
|
||||
break;
|
||||
case InputKeyOk:
|
||||
break;
|
||||
case InputKeyBack:
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(scene_state->selected_control == TokenAlgoSelect) {
|
||||
totp_roll_value_uint8_t(&scene_state->algo, -1, SHA1, STEAM, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenLengthSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->digits_count_index, -1, 0, 2, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == TokenDurationSelect) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->duration, -15, 15, 255, RollOverflowBehaviorStop);
|
||||
update_duration_text(scene_state);
|
||||
}
|
||||
break;
|
||||
case InputKeyOk:
|
||||
} else if(event->input.type == InputTypeRelease && event->input.key == InputKeyOk) {
|
||||
switch(scene_state->selected_control) {
|
||||
case TokenNameTextBox:
|
||||
if(scene_state->input_state != NULL) {
|
||||
@@ -264,7 +282,8 @@ bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState
|
||||
}
|
||||
scene_state->input_state =
|
||||
totp_input_text_activate(scene_state->token_name_input_context);
|
||||
scene_state->input_started_at = furi_get_tick();
|
||||
|
||||
scene_state->text_input_mode = true;
|
||||
break;
|
||||
case TokenSecretTextBox:
|
||||
if(scene_state->input_state != NULL) {
|
||||
@@ -272,7 +291,8 @@ bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState
|
||||
}
|
||||
scene_state->input_state =
|
||||
totp_input_text_activate(scene_state->token_secret_input_context);
|
||||
scene_state->input_started_at = furi_get_tick();
|
||||
|
||||
scene_state->text_input_mode = true;
|
||||
break;
|
||||
case TokenAlgoSelect:
|
||||
break;
|
||||
@@ -313,12 +333,6 @@ bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case InputKeyBack:
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -60,17 +60,17 @@ void totp_scene_app_settings_activate(PluginState* plugin_state) {
|
||||
}
|
||||
|
||||
static void two_digit_to_str(int8_t num, char* str) {
|
||||
uint8_t index = 0;
|
||||
char* s = str;
|
||||
if(num < 0) {
|
||||
str[index++] = '-';
|
||||
*(s++) = '-';
|
||||
num = -num;
|
||||
}
|
||||
|
||||
uint8_t d1 = (num / 10) % 10;
|
||||
uint8_t d2 = num % 10;
|
||||
str[index++] = CONVERT_DIGIT_TO_CHAR(d1);
|
||||
str[index++] = CONVERT_DIGIT_TO_CHAR(d2);
|
||||
str[index++] = '\0';
|
||||
*(s++) = CONVERT_DIGIT_TO_CHAR(d1);
|
||||
*(s++) = CONVERT_DIGIT_TO_CHAR(d2);
|
||||
*(s++) = '\0';
|
||||
}
|
||||
|
||||
void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plugin_state) {
|
||||
@@ -183,116 +183,117 @@ bool totp_scene_app_settings_handle_event(
|
||||
}
|
||||
|
||||
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
||||
if(event->input.type != InputTypePress && event->input.type != InputTypeRepeat) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control,
|
||||
-1,
|
||||
HoursInput,
|
||||
ConfirmButton,
|
||||
RollOverflowBehaviorStop);
|
||||
if(scene_state->selected_control > Vibro) {
|
||||
scene_state->y_offset = 128;
|
||||
} else if(scene_state->selected_control > MinutesInput) {
|
||||
scene_state->y_offset = 64;
|
||||
} else {
|
||||
scene_state->y_offset = 0;
|
||||
}
|
||||
break;
|
||||
case InputKeyDown:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control, 1, HoursInput, ConfirmButton, RollOverflowBehaviorStop);
|
||||
if(scene_state->selected_control > Vibro) {
|
||||
scene_state->y_offset = 128;
|
||||
} else if(scene_state->selected_control > MinutesInput) {
|
||||
scene_state->y_offset = 64;
|
||||
} else {
|
||||
scene_state->y_offset = 0;
|
||||
}
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(scene_state->selected_control == HoursInput) {
|
||||
totp_roll_value_int8_t(
|
||||
&scene_state->tz_offset_hours, 1, -12, 12, RollOverflowBehaviorStop);
|
||||
} else if(scene_state->selected_control == MinutesInput) {
|
||||
if(event->input.type == InputTypePress || event->input.type == InputTypeRepeat) {
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->tz_offset_minutes, 15, 0, 45, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == Sound) {
|
||||
scene_state->notification_sound = !scene_state->notification_sound;
|
||||
} else if(scene_state->selected_control == Vibro) {
|
||||
scene_state->notification_vibro = !scene_state->notification_vibro;
|
||||
} else if(scene_state->selected_control == BadUsb) {
|
||||
scene_state->badusb_enabled = !scene_state->badusb_enabled;
|
||||
}
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
else if(scene_state->selected_control == BadBt) {
|
||||
scene_state->badbt_enabled = !scene_state->badbt_enabled;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(scene_state->selected_control == HoursInput) {
|
||||
totp_roll_value_int8_t(
|
||||
&scene_state->tz_offset_hours, -1, -12, 12, RollOverflowBehaviorStop);
|
||||
} else if(scene_state->selected_control == MinutesInput) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->tz_offset_minutes, -15, 0, 45, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == Sound) {
|
||||
scene_state->notification_sound = !scene_state->notification_sound;
|
||||
} else if(scene_state->selected_control == Vibro) {
|
||||
scene_state->notification_vibro = !scene_state->notification_vibro;
|
||||
} else if(scene_state->selected_control == BadUsb) {
|
||||
scene_state->badusb_enabled = !scene_state->badusb_enabled;
|
||||
}
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
else if(scene_state->selected_control == BadBt) {
|
||||
scene_state->badbt_enabled = !scene_state->badbt_enabled;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case InputKeyOk:
|
||||
if(scene_state->selected_control == ConfirmButton) {
|
||||
plugin_state->timezone_offset = (float)scene_state->tz_offset_hours +
|
||||
(float)scene_state->tz_offset_minutes / 60.0f;
|
||||
|
||||
plugin_state->notification_method =
|
||||
(scene_state->notification_sound ? NotificationMethodSound :
|
||||
NotificationMethodNone) |
|
||||
(scene_state->notification_vibro ? NotificationMethodVibro :
|
||||
NotificationMethodNone);
|
||||
|
||||
plugin_state->automation_method =
|
||||
scene_state->badusb_enabled ? AutomationMethodBadUsb : AutomationMethodNone;
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
plugin_state->automation_method |= scene_state->badbt_enabled ? AutomationMethodBadBt :
|
||||
AutomationMethodNone;
|
||||
#endif
|
||||
|
||||
if(!totp_config_file_update_user_settings(plugin_state)) {
|
||||
totp_dialogs_config_updating_error(plugin_state);
|
||||
return false;
|
||||
&scene_state->selected_control,
|
||||
-1,
|
||||
HoursInput,
|
||||
ConfirmButton,
|
||||
RollOverflowBehaviorStop);
|
||||
if(scene_state->selected_control > Vibro) {
|
||||
scene_state->y_offset = 128;
|
||||
} else if(scene_state->selected_control > MinutesInput) {
|
||||
scene_state->y_offset = 64;
|
||||
} else {
|
||||
scene_state->y_offset = 0;
|
||||
}
|
||||
break;
|
||||
case InputKeyDown:
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control,
|
||||
1,
|
||||
HoursInput,
|
||||
ConfirmButton,
|
||||
RollOverflowBehaviorStop);
|
||||
if(scene_state->selected_control > Vibro) {
|
||||
scene_state->y_offset = 128;
|
||||
} else if(scene_state->selected_control > MinutesInput) {
|
||||
scene_state->y_offset = 64;
|
||||
} else {
|
||||
scene_state->y_offset = 0;
|
||||
}
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(scene_state->selected_control == HoursInput) {
|
||||
totp_roll_value_int8_t(
|
||||
&scene_state->tz_offset_hours, 1, -12, 12, RollOverflowBehaviorStop);
|
||||
} else if(scene_state->selected_control == MinutesInput) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->tz_offset_minutes, 15, 0, 45, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == Sound) {
|
||||
scene_state->notification_sound = !scene_state->notification_sound;
|
||||
} else if(scene_state->selected_control == Vibro) {
|
||||
scene_state->notification_vibro = !scene_state->notification_vibro;
|
||||
} else if(scene_state->selected_control == BadUsb) {
|
||||
scene_state->badusb_enabled = !scene_state->badusb_enabled;
|
||||
}
|
||||
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
if(!scene_state->badbt_enabled && plugin_state->bt_type_code_worker_context != NULL) {
|
||||
totp_bt_type_code_worker_free(plugin_state->bt_type_code_worker_context);
|
||||
plugin_state->bt_type_code_worker_context = NULL;
|
||||
else if(scene_state->selected_control == BadBt) {
|
||||
scene_state->badbt_enabled = !scene_state->badbt_enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(scene_state->selected_control == HoursInput) {
|
||||
totp_roll_value_int8_t(
|
||||
&scene_state->tz_offset_hours, -1, -12, 12, RollOverflowBehaviorStop);
|
||||
} else if(scene_state->selected_control == MinutesInput) {
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->tz_offset_minutes, -15, 0, 45, RollOverflowBehaviorRoll);
|
||||
} else if(scene_state->selected_control == Sound) {
|
||||
scene_state->notification_sound = !scene_state->notification_sound;
|
||||
} else if(scene_state->selected_control == Vibro) {
|
||||
scene_state->notification_vibro = !scene_state->notification_vibro;
|
||||
} else if(scene_state->selected_control == BadUsb) {
|
||||
scene_state->badusb_enabled = !scene_state->badusb_enabled;
|
||||
}
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
else if(scene_state->selected_control == BadBt) {
|
||||
scene_state->badbt_enabled = !scene_state->badbt_enabled;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case InputKeyOk:
|
||||
break;
|
||||
case InputKeyBack: {
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case InputKeyBack: {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(
|
||||
event->input.type == InputTypeRelease && event->input.key == InputKeyOk &&
|
||||
scene_state->selected_control == ConfirmButton) {
|
||||
plugin_state->timezone_offset =
|
||||
(float)scene_state->tz_offset_hours + (float)scene_state->tz_offset_minutes / 60.0f;
|
||||
|
||||
plugin_state->notification_method =
|
||||
(scene_state->notification_sound ? NotificationMethodSound : NotificationMethodNone) |
|
||||
(scene_state->notification_vibro ? NotificationMethodVibro : NotificationMethodNone);
|
||||
|
||||
plugin_state->automation_method = scene_state->badusb_enabled ? AutomationMethodBadUsb :
|
||||
AutomationMethodNone;
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
plugin_state->automation_method |= scene_state->badbt_enabled ? AutomationMethodBadBt :
|
||||
AutomationMethodNone;
|
||||
#endif
|
||||
|
||||
if(!totp_config_file_update_user_settings(plugin_state)) {
|
||||
totp_dialogs_config_updating_error(plugin_state);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
if(!scene_state->badbt_enabled && plugin_state->bt_type_code_worker_context != NULL) {
|
||||
totp_bt_type_code_worker_free(plugin_state->bt_type_code_worker_context);
|
||||
plugin_state->bt_type_code_worker_context = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -83,38 +83,45 @@ bool totp_scene_authenticate_handle_event(
|
||||
return false;
|
||||
}
|
||||
|
||||
if(event->input.type != InputTypePress) {
|
||||
return true;
|
||||
}
|
||||
|
||||
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
||||
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowUp;
|
||||
scene_state->code_length++;
|
||||
SceneState* scene_state = plugin_state->current_scene_state;
|
||||
if(event->input.type == InputTypePress) {
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowUp;
|
||||
scene_state->code_length++;
|
||||
}
|
||||
break;
|
||||
case InputKeyDown:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowDown;
|
||||
scene_state->code_length++;
|
||||
}
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowRight;
|
||||
scene_state->code_length++;
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowLeft;
|
||||
scene_state->code_length++;
|
||||
}
|
||||
break;
|
||||
case InputKeyOk:
|
||||
break;
|
||||
case InputKeyBack:
|
||||
if(scene_state->code_length > 0) {
|
||||
scene_state->code_input[scene_state->code_length - 1] = 0;
|
||||
scene_state->code_length--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case InputKeyDown:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowDown;
|
||||
scene_state->code_length++;
|
||||
}
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowRight;
|
||||
scene_state->code_length++;
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
if(scene_state->code_length < MAX_CODE_LENGTH) {
|
||||
scene_state->code_input[scene_state->code_length] = PinCodeArrowLeft;
|
||||
scene_state->code_length++;
|
||||
}
|
||||
break;
|
||||
case InputKeyOk: {
|
||||
} else if(event->input.type == InputTypeRelease && event->input.key == InputKeyOk) {
|
||||
CryptoSeedIVResult seed_result = totp_crypto_seed_iv(
|
||||
plugin_state, &scene_state->code_input[0], scene_state->code_length);
|
||||
|
||||
@@ -145,16 +152,6 @@ bool totp_scene_authenticate_handle_event(
|
||||
dialog_message_show(plugin_state->dialogs_app, message);
|
||||
dialog_message_free(message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InputKeyBack:
|
||||
if(scene_state->code_length > 0) {
|
||||
scene_state->code_input[scene_state->code_length - 1] = 0;
|
||||
scene_state->code_length--;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#ifdef TOTP_BADBT_TYPE_ENABLED
|
||||
#include "../../../workers/bt_type_code/bt_type_code.h"
|
||||
#endif
|
||||
#include "../../fonts/mode-nine/mode_nine.h"
|
||||
#include "../../fonts/active_font.h"
|
||||
|
||||
#define PROGRESS_BAR_MARGIN (3)
|
||||
#define PROGRESS_BAR_HEIGHT (4)
|
||||
@@ -142,19 +142,19 @@ static void draw_totp_code(Canvas* const canvas, const PluginState* const plugin
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
uint8_t code_length = totp_token_info_iterator_get_current_token(iterator_context)->digits;
|
||||
uint8_t offset_x = scene_state->ui_precalculated_dimensions.code_offset_x;
|
||||
uint8_t char_width = modeNine_15ptFontInfo.charInfo[0].width;
|
||||
uint8_t char_width = TOTP_CODE_FONT_INFO.charInfo[0].width;
|
||||
uint8_t offset_x_inc = scene_state->ui_precalculated_dimensions.code_offset_x_inc;
|
||||
for(uint8_t i = 0; i < code_length; i++) {
|
||||
char ch = scene_state->last_code[i];
|
||||
if(ch >= modeNine_15ptFontInfo.startChar && ch <= modeNine_15ptFontInfo.endChar) {
|
||||
uint8_t char_index = ch - modeNine_15ptFontInfo.startChar;
|
||||
if(ch >= TOTP_CODE_FONT_INFO.startChar && ch <= TOTP_CODE_FONT_INFO.endChar) {
|
||||
uint8_t char_index = ch - TOTP_CODE_FONT_INFO.startChar;
|
||||
canvas_draw_xbm(
|
||||
canvas,
|
||||
offset_x,
|
||||
scene_state->ui_precalculated_dimensions.code_offset_y,
|
||||
char_width,
|
||||
modeNine_15ptFontInfo.height,
|
||||
&modeNine_15ptFontInfo.data[modeNine_15ptFontInfo.charInfo[char_index].offset]);
|
||||
TOTP_CODE_FONT_INFO.height,
|
||||
&TOTP_CODE_FONT_INFO.data[TOTP_CODE_FONT_INFO.charInfo[char_index].offset]);
|
||||
}
|
||||
|
||||
offset_x += offset_x_inc;
|
||||
@@ -172,15 +172,15 @@ static void on_new_token_code_generated(bool time_left, void* context) {
|
||||
SceneState* scene_state = plugin_state->current_scene_state;
|
||||
const TokenInfo* current_token = totp_token_info_iterator_get_current_token(iterator_context);
|
||||
|
||||
uint8_t char_width = modeNine_15ptFontInfo.charInfo[0].width;
|
||||
uint8_t char_width = TOTP_CODE_FONT_INFO.charInfo[0].width;
|
||||
scene_state->ui_precalculated_dimensions.code_total_length =
|
||||
current_token->digits * (char_width + modeNine_15ptFontInfo.spacePixels);
|
||||
current_token->digits * (char_width + TOTP_CODE_FONT_INFO.spacePixels);
|
||||
scene_state->ui_precalculated_dimensions.code_offset_x =
|
||||
(SCREEN_WIDTH - scene_state->ui_precalculated_dimensions.code_total_length) >> 1;
|
||||
scene_state->ui_precalculated_dimensions.code_offset_x_inc =
|
||||
char_width + modeNine_15ptFontInfo.spacePixels;
|
||||
char_width + TOTP_CODE_FONT_INFO.spacePixels;
|
||||
scene_state->ui_precalculated_dimensions.code_offset_y =
|
||||
SCREEN_HEIGHT_CENTER - (modeNine_15ptFontInfo.height >> 1);
|
||||
SCREEN_HEIGHT_CENTER - (TOTP_CODE_FONT_INFO.height >> 1);
|
||||
|
||||
if(time_left) {
|
||||
notification_message(
|
||||
@@ -381,54 +381,51 @@ bool totp_scene_generate_token_handle_event(
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else if(event->input.type == InputTypePress || event->input.type == InputTypeRepeat) {
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
break;
|
||||
case InputKeyDown:
|
||||
break;
|
||||
case InputKeyRight: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
size_t current_token_index =
|
||||
totp_token_info_iterator_get_current_token_index(iterator_context);
|
||||
totp_roll_value_size_t(
|
||||
¤t_token_index,
|
||||
1,
|
||||
0,
|
||||
totp_token_info_iterator_get_total_count(iterator_context) - 1,
|
||||
RollOverflowBehaviorRoll);
|
||||
|
||||
if(event->input.type != InputTypePress && event->input.type != InputTypeRepeat) {
|
||||
return true;
|
||||
}
|
||||
update_totp_params(plugin_state, current_token_index);
|
||||
break;
|
||||
}
|
||||
case InputKeyLeft: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
size_t current_token_index =
|
||||
totp_token_info_iterator_get_current_token_index(iterator_context);
|
||||
totp_roll_value_size_t(
|
||||
¤t_token_index,
|
||||
-1,
|
||||
0,
|
||||
totp_token_info_iterator_get_total_count(iterator_context) - 1,
|
||||
RollOverflowBehaviorRoll);
|
||||
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp:
|
||||
break;
|
||||
case InputKeyDown:
|
||||
break;
|
||||
case InputKeyRight: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
size_t current_token_index =
|
||||
totp_token_info_iterator_get_current_token_index(iterator_context);
|
||||
totp_roll_value_size_t(
|
||||
¤t_token_index,
|
||||
1,
|
||||
0,
|
||||
totp_token_info_iterator_get_total_count(iterator_context) - 1,
|
||||
RollOverflowBehaviorRoll);
|
||||
|
||||
update_totp_params(plugin_state, current_token_index);
|
||||
break;
|
||||
}
|
||||
case InputKeyLeft: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
size_t current_token_index =
|
||||
totp_token_info_iterator_get_current_token_index(iterator_context);
|
||||
totp_roll_value_size_t(
|
||||
¤t_token_index,
|
||||
-1,
|
||||
0,
|
||||
totp_token_info_iterator_get_total_count(iterator_context) - 1,
|
||||
RollOverflowBehaviorRoll);
|
||||
|
||||
update_totp_params(plugin_state, current_token_index);
|
||||
break;
|
||||
}
|
||||
case InputKeyOk:
|
||||
update_totp_params(plugin_state, current_token_index);
|
||||
break;
|
||||
}
|
||||
case InputKeyOk:
|
||||
break;
|
||||
case InputKeyBack:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(event->input.type == InputTypeRelease && event->input.key == InputKeyOk) {
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneTokenMenu);
|
||||
break;
|
||||
case InputKeyBack:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -82,38 +82,52 @@ bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginSt
|
||||
}
|
||||
|
||||
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
|
||||
if(event->input.type != InputTypePress) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control, -1, AddNewToken, AppSettings, RollOverflowBehaviorRoll);
|
||||
if(scene_state->selected_control == DeleteToken &&
|
||||
totp_token_info_iterator_get_total_count(iterator_context) == 0) {
|
||||
scene_state->selected_control--;
|
||||
if(event->input.type == InputTypePress) {
|
||||
switch(event->input.key) {
|
||||
case InputKeyUp: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control,
|
||||
-1,
|
||||
AddNewToken,
|
||||
AppSettings,
|
||||
RollOverflowBehaviorRoll);
|
||||
if(scene_state->selected_control == DeleteToken &&
|
||||
totp_token_info_iterator_get_total_count(iterator_context) == 0) {
|
||||
scene_state->selected_control--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InputKeyDown: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control, 1, AddNewToken, AppSettings, RollOverflowBehaviorRoll);
|
||||
if(scene_state->selected_control == DeleteToken &&
|
||||
totp_token_info_iterator_get_total_count(iterator_context) == 0) {
|
||||
scene_state->selected_control++;
|
||||
case InputKeyDown: {
|
||||
const TokenInfoIteratorContext* iterator_context =
|
||||
totp_config_get_token_iterator_context(plugin_state);
|
||||
totp_roll_value_uint8_t(
|
||||
&scene_state->selected_control,
|
||||
1,
|
||||
AddNewToken,
|
||||
AppSettings,
|
||||
RollOverflowBehaviorRoll);
|
||||
if(scene_state->selected_control == DeleteToken &&
|
||||
totp_token_info_iterator_get_total_count(iterator_context) == 0) {
|
||||
scene_state->selected_control++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InputKeyRight:
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
break;
|
||||
case InputKeyOk:
|
||||
case InputKeyRight:
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
break;
|
||||
case InputKeyOk:
|
||||
break;
|
||||
case InputKeyBack: {
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(event->input.type == InputTypeRelease && event->input.key == InputKeyOk) {
|
||||
switch(scene_state->selected_control) {
|
||||
case AddNewToken: {
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneAddNewToken);
|
||||
@@ -153,13 +167,6 @@ bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginSt
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case InputKeyBack: {
|
||||
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user