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
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
11 changed files with 163 additions and 39 deletions

View file

@ -7,8 +7,8 @@
// List of compatible firmwares
#define TOTP_FIRMWARE_OFFICIAL_STABLE 1
#define TOTP_FIRMWARE_OFFICIAL_DEV 2
#define TOTP_FIRMWARE_XTREME 3
#define TOTP_FIRMWARE_UL_XFW 3 // XFW and UL now has same bluetooth mac/advname changing API
// End of list
// Target firmware to build for
#define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_XTREME
#define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_UL_XFW

View file

@ -177,6 +177,10 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) {
flipper_format_write_uint32(
fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_METHOD, &tmp_uint32, 1);
// Default Font = 0
tmp_uint32 = 0;
flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1);
if(!flipper_format_rewind(fff_data_file)) {
totp_close_config_file(fff_data_file);
FURI_LOG_E(LOGGING_TAG, "Rewind error");
@ -259,6 +263,24 @@ bool totp_config_file_update_automation_method(const PluginState* plugin_state)
return update_result;
}
bool totp_config_file_update_selected_font(const PluginState* plugin_state) {
FlipperFormat* file = plugin_state->config_file_context->config_file;
flipper_format_rewind(file);
bool update_result = false;
do {
uint32_t tmp_uint32 = plugin_state->selected_font;
if(!flipper_format_insert_or_update_uint32(
file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1)) {
break;
}
update_result = true;
} while(false);
return update_result;
}
bool totp_config_file_update_user_settings(const PluginState* plugin_state) {
FlipperFormat* file = plugin_state->config_file_context->config_file;
flipper_format_rewind(file);
@ -280,6 +302,12 @@ bool totp_config_file_update_user_settings(const PluginState* plugin_state) {
break;
}
tmp_uint32 = plugin_state->selected_font;
if(!flipper_format_insert_or_update_uint32(
file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1)) {
break;
}
update_result = true;
} while(false);
@ -428,6 +456,16 @@ bool totp_config_file_load(PluginState* const plugin_state) {
plugin_state->automation_method = tmp_uint32;
// Load selected font
flipper_format_rewind(fff_data_file);
if(!flipper_format_read_uint32(
fff_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, &tmp_uint32, 1)) {
tmp_uint32 = 0;
}
plugin_state->selected_font = tmp_uint32;
plugin_state->config_file_context = malloc(sizeof(ConfigFileContext));
furi_check(plugin_state->config_file_context != NULL);
plugin_state->config_file_context->storage = storage;

View file

@ -44,6 +44,13 @@ bool totp_config_file_update_notification_method(const PluginState* plugin_state
*/
bool totp_config_file_update_automation_method(const PluginState* plugin_state);
/**
* @brief Updates selected font in an application config file
* @param plugin_state application state
* @return Config file update result
*/
bool totp_config_file_update_selected_font(const PluginState* plugin_state);
/**
* @brief Updates application user settings
* @param plugin_state application state

View file

@ -18,3 +18,4 @@
#define TOTP_CONFIG_KEY_PINSET "PinIsSet"
#define TOTP_CONFIG_KEY_NOTIFICATION_METHOD "NotificationMethod"
#define TOTP_CONFIG_KEY_AUTOMATION_METHOD "AutomationMethod"
#define TOTP_CONFIG_KEY_SELECTED_FONT "SelectedFont"

View file

@ -58,6 +58,15 @@ bool totp_config_migrate_to_latest(
flipper_format_rewind(fff_backup_data_file);
// Font
if(flipper_format_read_string(
fff_backup_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_SELECTED_FONT, temp_str);
}
flipper_format_rewind(fff_backup_data_file);
while(true) {
if(!flipper_format_read_string(
fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) {

View file

@ -107,6 +107,7 @@ static bool totp_activate_initial_scene(PluginState* const plugin_state) {
}
static bool totp_plugin_state_init(PluginState* const plugin_state) {
plugin_state->selected_font = 0;
plugin_state->gui = furi_record_open(RECORD_GUI);
plugin_state->notification_app = furi_record_open(RECORD_NOTIFICATION);
plugin_state->dialogs_app = furi_record_open(RECORD_DIALOGS);

View file

@ -80,6 +80,11 @@ typedef struct {
*/
NotificationMethod notification_method;
/**
* @brief Numbers Font
*/
uint8_t selected_font;
/**
* @brief Main rendering loop mutex
*/

View file

@ -3,25 +3,10 @@
#include "../../features_config.h"
#include "font_info.h"
#if TOTP_FONT == TOTP_FONT_MODENINE
#include "mode_nine/mode_nine.h"
#define TOTP_CODE_FONT_INFO modeNine_15ptFontInfo
#elif TOTP_FONT == TOTP_FONT_REDHATMONO
#include "redhat_mono/redhat_mono.h"
#define TOTP_CODE_FONT_INFO redHatMono_16ptFontInfo
#elif TOTP_FONT == TOTP_FONT_BEDSTEAD
#include "bedstead/bedstead.h"
#define TOTP_CODE_FONT_INFO bedstead_17ptFontInfo
#elif TOTP_FONT == TOTP_FONT_ZECTOR
#include "zector/zector.h"
#define TOTP_CODE_FONT_INFO zector_18ptFontInfo
#elif TOTP_FONT == TOTP_FONT_712SERIF
#include "712serif/712serif.h"
#define TOTP_CODE_FONT_INFO _712Serif_24ptFontInfo
#elif TOTP_FONT == TOTP_FONT_GRAPH35PIX
#include "graph35pix/graph35pix.h"
#define TOTP_CODE_FONT_INFO graph35pix_12ptFontInfo
#elif TOTP_FONT == TOTP_FONT_KARMAFUTURE
#include "karma_future/karma_future.h"
#define TOTP_CODE_FONT_INFO karmaFuture_14ptFontInfo
#endif

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(

View file

@ -13,7 +13,7 @@
#include "../type_code_common.h"
#include "../../features_config.h"
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_UL_XFW
#define TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN FURI_HAL_BT_ADV_NAME_LENGTH
#define TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN GAP_MAC_ADDR_SIZE
#endif
@ -29,7 +29,7 @@ struct TotpBtTypeCodeWorkerContext {
Bt* bt;
bool is_advertising;
bool is_connected;
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_UL_XFW
char previous_bt_name[TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN];
uint8_t previous_bt_mac[TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN];
#endif
@ -39,7 +39,7 @@ static inline bool totp_type_code_worker_stop_requested() {
return furi_thread_flags_get() & TotpBtTypeCodeWorkerEventStop;
}
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_UL_XFW
static void totp_type_code_worker_bt_set_app_mac(uint8_t* mac) {
uint8_t max_i;
size_t uid_size = furi_hal_version_uid_size();
@ -161,7 +161,7 @@ TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init() {
furi_delay_ms(200);
bt_keys_storage_set_storage_path(context->bt, HID_BT_KEYS_STORAGE_PATH);
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_UL_XFW
memcpy(
&context->previous_bt_name[0],
furi_hal_bt_get_profile_adv_name(FuriHalBtProfileHidKeyboard),
@ -184,7 +184,7 @@ TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init() {
furi_hal_bt_start_advertising();
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_UL_XFW
bt_enable_peer_key_update(context->bt);
#endif
@ -211,7 +211,7 @@ void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context) {
furi_delay_ms(200);
bt_keys_storage_set_default_path(context->bt);
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_UL_XFW
furi_hal_bt_set_profile_adv_name(FuriHalBtProfileHidKeyboard, context->previous_bt_name);
furi_hal_bt_set_profile_mac_addr(FuriHalBtProfileHidKeyboard, context->previous_bt_mac);
#endif