Skip to content

Commit

Permalink
Closing #165 (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov committed Jul 18, 2023
1 parent 6315ccc commit 1b4673e
Show file tree
Hide file tree
Showing 34 changed files with 225 additions and 121 deletions.
5 changes: 4 additions & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ App(
],
stack_size=2 * 1024,
order=20,
fap_version="2.23",
fap_version="2.3",
fap_author="Alexander Kopachov (@akopachov)",
fap_description="Software-based TOTP authenticator for Flipper Zero device",
fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",
Expand All @@ -38,5 +38,8 @@ App(
Lib(
name="roll_value",
),
Lib(
name="fonts",
),
],
)
19 changes: 0 additions & 19 deletions features_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,3 @@
#ifndef TOTP_TARGET_FIRMWARE
#define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_OFFICIAL_STABLE
#endif

// List of available font for TOTP code
#define TOTP_FONT_MODENINE (1)
#define TOTP_FONT_REDHATMONO (2)
#define TOTP_FONT_BEDSTEAD (3)
#define TOTP_FONT_ZECTOR (4)
#define TOTP_FONT_712SERIF (5)
#define TOTP_FONT_GRAPH35PIX (6)
#define TOTP_FONT_KARMAFUTURE (7)
#define TOTP_FONT_FUNCLIMBING (8)
#define TOTP_FONT_DPCOMIC (9)
#define TOTP_FONT_PIXELFLAG (10)

// End of list

// Active font for TOTP codes
#ifndef TOTP_FONT
#define TOTP_FONT TOTP_FONT_MODENINE
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ const FONT_CHAR_INFO _712Serif_24ptDescriptors[] = {

/* Font information for 7:12 Serif 24pt */
const FONT_INFO _712Serif_24ptFontInfo = {
"712 Serif",
14, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions lib/fonts/available_fonts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "available_fonts.h"
#include "712serif/712serif.h"
#include "bedstead/bedstead.h"
#include "dpcomic/dpcomic.h"
#include "funclimbing/funclimbing.h"
#include "graph35pix/graph35pix.h"
#include "karma_future/karma_future.h"
#include "mode_nine/mode_nine.h"
#include "pixelflag/pixelflag.h"
#include "redhat_mono/redhat_mono.h"
#include "zector/zector.h"

const FONT_INFO* const available_fonts[AVAILABLE_FONTS_COUNT] = {
&modeNine_15ptFontInfo,
&_712Serif_24ptFontInfo,
&bedstead_17ptFontInfo,
&dPComic_18ptFontInfo,
&funclimbingDemo_18ptFontInfo,
&graph35pix_12ptFontInfo,
&karmaFuture_14ptFontInfo,
&pixelFlag_18ptFontInfo,
&redHatMono_16ptFontInfo,
&zector_18ptFontInfo};
7 changes: 7 additions & 0 deletions lib/fonts/available_fonts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "font_info.h"

#define AVAILABLE_FONTS_COUNT (10)

extern const FONT_INFO* const available_fonts[AVAILABLE_FONTS_COUNT];
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ const FONT_CHAR_INFO bedstead_17ptDescriptors[] = {

/* Font information for Bedstead 17pt */
const FONT_INFO bedstead_17ptFontInfo = {
"Bedstead",
16, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions ui/fonts/dpcomic/dpcomic.c → lib/fonts/dpcomic/dpcomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ const FONT_CHAR_INFO dPComic_18ptDescriptors[] = {

/* Font information for DPComic 18pt */
const FONT_INFO dPComic_18ptFontInfo = {
"DP Comic",
17, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ui/fonts/font_info.h → lib/fonts/font_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ typedef struct {

// Describes a single font
typedef struct {
const char* name; // Font name
const uint8_t height; // height, in pages (8 pixels), of the font's characters
const uint8_t startChar; // the first character in the font (e.g. in charInfo and data)
const uint8_t endChar; // the last character in the font
const uint8_t spacePixels; // number of pixels that a space character takes up
const FONT_CHAR_INFO* charInfo; // pointer to array of char information
const uint8_t* data; // pointer to generated array of character visual representation

} FONT_INFO;
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ const FONT_CHAR_INFO funclimbingDemo_18ptDescriptors[] = {

/* Font information for fun climbing (Demo) 18pt */
const FONT_INFO funclimbingDemo_18ptFontInfo = {
"Fun Climbing",
18, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ const FONT_CHAR_INFO graph35pix_12ptDescriptors[] = {

/* Font information for Graph 35+ pix 12pt */
const FONT_INFO graph35pix_12ptFontInfo = {
"Graph 35pix",
14, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ const FONT_CHAR_INFO karmaFuture_14ptDescriptors[] = {

/* Font information for Karma Future 14pt */
const FONT_INFO karmaFuture_14ptFontInfo = {
"Karma Future",
18, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ const FONT_CHAR_INFO modeNine_15ptDescriptors[] = {

/* Font information for ModeNine 15pt */
const FONT_INFO modeNine_15ptFontInfo = {
"Mode Nine",
14, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ const FONT_CHAR_INFO pixelFlag_18ptDescriptors[] = {

/* Font information for {PixelFlag} 18pt */
const FONT_INFO pixelFlag_18ptFontInfo = {
"Pixel Flag",
17, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ const FONT_CHAR_INFO redHatMono_16ptDescriptors[] = {

/* Font information for Red Hat Mono 16pt */
const FONT_INFO redHatMono_16ptFontInfo = {
"RedHat Mono",
16, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions ui/fonts/zector/zector.c → lib/fonts/zector/zector.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ const FONT_CHAR_INFO zector_18ptDescriptors[] = {

/* Font information for Zector 18pt */
const FONT_INFO zector_18ptFontInfo = {
"Zector",
16, /* Character height */
'-', /* Start character */
'Y', /* End character */
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions services/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ 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);

tmp_uint32 = 0;
flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_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");
Expand Down Expand Up @@ -257,6 +260,11 @@ bool totp_config_file_update_user_settings(const PluginState* plugin_state) {
break;
}

tmp_uint32 = plugin_state->active_font_index;
if(!flipper_format_insert_or_update_uint32(file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1)) {
break;
}

update_result = true;
} while(false);

Expand Down Expand Up @@ -405,6 +413,12 @@ bool totp_config_file_load(PluginState* const plugin_state) {

plugin_state->automation_method = tmp_uint32;

if(!flipper_format_read_uint32(fff_data_file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1)) {
tmp_uint32 = 0;
}

plugin_state->active_font_index = 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;
Expand Down
3 changes: 2 additions & 1 deletion services/config/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator")
#define CONFIG_FILE_HEADER "Flipper TOTP plugin config file"
#define CONFIG_FILE_ACTUAL_VERSION (5)
#define CONFIG_FILE_ACTUAL_VERSION (6)

#define TOTP_CONFIG_KEY_TIMEZONE "Timezone"
#define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName"
Expand All @@ -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_FONT "Font"
10 changes: 10 additions & 0 deletions services/config/migrations/common_migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ bool totp_config_migrate_to_latest(

flipper_format_rewind(fff_backup_data_file);

if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_FONT, temp_str)) {
flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_FONT, temp_str);
} else {
uint32_t default_font_index = 0;
flipper_format_write_uint32(
fff_data_file, TOTP_CONFIG_KEY_FONT, &default_font_index, 1);
}

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)) {
Expand Down
5 changes: 5 additions & 0 deletions types/plugin_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ typedef struct {
* @brief IDLE timeout context
*/
IdleTimeoutContext* idle_timeout_context;

/**
* @brief Font index to be used to draw TOTP token
*/
uint8_t active_font_index;
} PluginState;
33 changes: 33 additions & 0 deletions ui/canvas_extensions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "canvas_extensions.h"

void canvas_draw_str_ex(
Canvas* canvas,
uint8_t x,
uint8_t y,
const char* text,
size_t text_length,
const FONT_INFO* const font) {
const char* p_ch = text;
char ch;
size_t i = 0;
uint8_t offset_x = x;
uint8_t char_width = font->charInfo[0].width;
uint8_t offset_x_inc = char_width + font->spacePixels;
while(i < text_length && (ch = *p_ch) != 0) {
if(ch >= font->startChar && ch <= font->endChar) {
uint8_t char_index = ch - font->startChar;
canvas_draw_xbm(
canvas,
offset_x,
y,
char_width,
font->height,
&font->data[font->charInfo[char_index].offset]);
}

offset_x += offset_x_inc;

p_ch++;
i++;
}
}
13 changes: 13 additions & 0 deletions ui/canvas_extensions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <stdint.h>
#include <gui/gui.h>
#include <font_info.h>

void canvas_draw_str_ex(
Canvas* canvas,
uint8_t x,
uint8_t y,
const char* text,
size_t text_length,
const FONT_INFO* const font);
38 changes: 0 additions & 38 deletions ui/fonts/active_font.h

This file was deleted.

Loading

0 comments on commit 1b4673e

Please sign in to comment.