Setting to change fonts in TOTP

opensource != selling plugin builds / do you agree?
If you don't agree - and you think I did a bad thing here by allowing users to select fonts without payment, let me know

Why I did that? - cuz I'm not making private "donation only" builds myself, while having no main job, and living only on donations, so I don't like stuff like that in opensource projects

You should support author if you like this plugin here:
https://github.com/akopachov/flipper-zero_authenticator
This commit is contained in:
MX
2023-05-26 15:09:10 +03:00
parent 24ad48d390
commit b9397693a2
11 changed files with 163 additions and 39 deletions

View File

@@ -22,6 +22,7 @@ typedef enum {
MinutesInput,
Sound,
Vibro,
FontSelector,
BadUsb,
#ifdef TOTP_BADBT_TYPE_ENABLED
BadBt,
@@ -34,6 +35,7 @@ typedef struct {
uint8_t tz_offset_minutes;
bool notification_sound;
bool notification_vibro;
uint8_t selected_font;
bool badusb_enabled;
#ifdef TOTP_BADBT_TYPE_ENABLED
bool badbt_enabled;
@@ -54,6 +56,7 @@ void totp_scene_app_settings_activate(PluginState* plugin_state) {
scene_state->notification_sound = plugin_state->notification_method & NotificationMethodSound;
scene_state->notification_vibro = plugin_state->notification_method & NotificationMethodVibro;
scene_state->badusb_enabled = plugin_state->automation_method & AutomationMethodBadUsb;
scene_state->selected_font = plugin_state->selected_font;
#ifdef TOTP_BADBT_TYPE_ENABLED
scene_state->badbt_enabled = plugin_state->automation_method & AutomationMethodBadBt;
#endif
@@ -111,27 +114,38 @@ void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plu
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(
canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications");
canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications / UI");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 0, 81 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:");
canvas_draw_str_aligned(canvas, 0, 78 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:");
ui_control_select_render(
canvas,
36,
74 - scene_state->y_offset,
71 - scene_state->y_offset,
SCREEN_WIDTH - 36,
YES_NO_LIST[scene_state->notification_sound],
scene_state->selected_control == Sound);
canvas_draw_str_aligned(canvas, 0, 99 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:");
canvas_draw_str_aligned(canvas, 0, 94 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:");
ui_control_select_render(
canvas,
36,
92 - scene_state->y_offset,
87 - scene_state->y_offset,
SCREEN_WIDTH - 36,
YES_NO_LIST[scene_state->notification_vibro],
scene_state->selected_control == Vibro);
two_digit_to_str(scene_state->selected_font, &tmp_str[0]);
canvas_draw_str_aligned(
canvas, 0, 110 - scene_state->y_offset, AlignLeft, AlignTop, "UI Font:");
ui_control_select_render(
canvas,
36,
103 - scene_state->y_offset,
SCREEN_WIDTH - 36,
&tmp_str[0],
scene_state->selected_control == FontSelector);
canvas_draw_icon(
canvas, SCREEN_WIDTH_CENTER - 5, 123 - scene_state->y_offset, &I_totp_arrow_bottom_10x5);
@@ -192,7 +206,7 @@ bool totp_scene_app_settings_handle_event(
HoursInput,
ConfirmButton,
RollOverflowBehaviorStop);
if(scene_state->selected_control > Vibro) {
if(scene_state->selected_control > FontSelector) {
scene_state->y_offset = 128;
} else if(scene_state->selected_control > MinutesInput) {
scene_state->y_offset = 64;
@@ -207,7 +221,7 @@ bool totp_scene_app_settings_handle_event(
HoursInput,
ConfirmButton,
RollOverflowBehaviorStop);
if(scene_state->selected_control > Vibro) {
if(scene_state->selected_control > FontSelector) {
scene_state->y_offset = 128;
} else if(scene_state->selected_control > MinutesInput) {
scene_state->y_offset = 64;
@@ -234,6 +248,10 @@ bool totp_scene_app_settings_handle_event(
scene_state->badbt_enabled = !scene_state->badbt_enabled;
}
#endif
else if(scene_state->selected_control == FontSelector) {
totp_roll_value_uint8_t(
&scene_state->selected_font, 1, 0, 6, RollOverflowBehaviorStop);
}
break;
case InputKeyLeft:
if(scene_state->selected_control == HoursInput) {
@@ -254,6 +272,10 @@ bool totp_scene_app_settings_handle_event(
scene_state->badbt_enabled = !scene_state->badbt_enabled;
}
#endif
else if(scene_state->selected_control == FontSelector) {
totp_roll_value_uint8_t(
&scene_state->selected_font, -1, 0, 6, RollOverflowBehaviorStop);
}
break;
case InputKeyOk:
break;
@@ -280,6 +302,7 @@ bool totp_scene_app_settings_handle_event(
plugin_state->automation_method |= scene_state->badbt_enabled ? AutomationMethodBadBt :
AutomationMethodNone;
#endif
plugin_state->selected_font = scene_state->selected_font;
if(!totp_config_file_update_user_settings(plugin_state)) {
totp_dialogs_config_updating_error(plugin_state);

View File

@@ -142,19 +142,46 @@ 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 = TOTP_CODE_FONT_INFO.charInfo[0].width;
const FONT_INFO* current_font;
switch(plugin_state->selected_font) {
case 0:
current_font = &modeNine_15ptFontInfo;
break;
case 1:
current_font = &redHatMono_16ptFontInfo;
break;
case 2:
current_font = &bedstead_17ptFontInfo;
break;
case 3:
current_font = &zector_18ptFontInfo;
break;
case 4:
current_font = &_712Serif_24ptFontInfo;
break;
case 5:
current_font = &graph35pix_12ptFontInfo;
break;
case 6:
current_font = &karmaFuture_14ptFontInfo;
break;
default:
current_font = &modeNine_15ptFontInfo;
break;
}
uint8_t char_width = current_font->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 >= TOTP_CODE_FONT_INFO.startChar && ch <= TOTP_CODE_FONT_INFO.endChar) {
uint8_t char_index = ch - TOTP_CODE_FONT_INFO.startChar;
if(ch >= current_font->startChar && ch <= current_font->endChar) {
uint8_t char_index = ch - current_font->startChar;
canvas_draw_xbm(
canvas,
offset_x,
scene_state->ui_precalculated_dimensions.code_offset_y,
char_width,
TOTP_CODE_FONT_INFO.height,
&TOTP_CODE_FONT_INFO.data[TOTP_CODE_FONT_INFO.charInfo[char_index].offset]);
current_font->height,
&current_font->data[current_font->charInfo[char_index].offset]);
}
offset_x += offset_x_inc;
@@ -172,15 +199,43 @@ 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 = TOTP_CODE_FONT_INFO.charInfo[0].width;
const FONT_INFO* current_font;
switch(plugin_state->selected_font) {
case 0:
current_font = &modeNine_15ptFontInfo;
break;
case 1:
current_font = &redHatMono_16ptFontInfo;
break;
case 2:
current_font = &bedstead_17ptFontInfo;
break;
case 3:
current_font = &zector_18ptFontInfo;
break;
case 4:
current_font = &_712Serif_24ptFontInfo;
break;
case 5:
current_font = &graph35pix_12ptFontInfo;
break;
case 6:
current_font = &karmaFuture_14ptFontInfo;
break;
default:
current_font = &modeNine_15ptFontInfo;
break;
}
uint8_t char_width = current_font->charInfo[0].width;
scene_state->ui_precalculated_dimensions.code_total_length =
current_token->digits * (char_width + TOTP_CODE_FONT_INFO.spacePixels);
current_token->digits * (char_width + current_font->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 + TOTP_CODE_FONT_INFO.spacePixels;
char_width + current_font->spacePixels;
scene_state->ui_precalculated_dimensions.code_offset_y =
SCREEN_HEIGHT_CENTER - (TOTP_CODE_FONT_INFO.height >> 1);
SCREEN_HEIGHT_CENTER - (current_font->height >> 1);
if(time_left) {
notification_message(