Skip to content

Commit 7419a1e

Browse files
authored
Implemented #26 (#27)
* Implemented #26 * Improved HID worker shutdown code * Refactoring
1 parent e1afd24 commit 7419a1e

30 files changed

+797
-106
lines changed

build.ps1

+14-6
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,27 @@ function Get-LatestDirectory {
66
Get-ChildItem -Path $Path | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1
77
}
88

9+
Push-Location $PSScriptRoot
10+
11+
$official_build_path = "flipperzero-firmware_official\build"
12+
$unleashed_build_path = "flipperzero-firmware_unleashed\build"
13+
14+
Remove-Item "$official_build_path\*" -Recurse -Force
15+
Remove-Item "$unleashed_build_path\*" -Recurse -Force
16+
917
./fbt u COMPACT=1 DEBUG=0 VERBOSE=0 fap_totp
1018
./fbt o COMPACT=1 DEBUG=0 VERBOSE=0 fap_totp
1119

12-
Push-Location $PSScriptRoot
13-
1420
if (!(Test-Path -PathType Container "build")) {
1521
New-Item -ItemType Directory -Path "build"
22+
} else {
23+
Remove-Item "build\*" -Recurse -Force
1624
}
1725

18-
$official_latest_dir = Get-LatestDirectory -Path "flipperzero-firmware_official\build\"
19-
Copy-Item "flipperzero-firmware_official\build\$official_latest_dir\.extapps\totp.fap" -Destination "build\totp_official-fw.fap"
26+
$official_latest_dir = Get-LatestDirectory -Path $official_build_path
27+
Copy-Item "$official_build_path\$official_latest_dir\.extapps\totp.fap" -Destination "build\totp_official-fw.fap"
2028

21-
$unleashed_latest_dir = Get-LatestDirectory -Path "flipperzero-firmware_unleashed\build\"
22-
Copy-Item "flipperzero-firmware_unleashed\build\$unleashed_latest_dir\.extapps\totp.fap" -Destination "build\totp_unleashed-fw.fap"
29+
$unleashed_latest_dir = Get-LatestDirectory -Path $unleashed_build_path
30+
Copy-Item "$unleashed_build_path\$unleashed_latest_dir\.extapps\totp.fap" -Destination "build\totp_unleashed-fw.fap"
2331

2432
Pop-Location

docs/conf-file_description.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ File format is standard for Flipper Zero device. Each line has one setting ident
4646

4747
**Default value:** 0.000000
4848

49-
**Description:** Timezone offset **in hours**. Need to be modified manually. Because of Flipper Zero API doesn't provide an access to timezone offset it is necessary to set it manually for correct TOTP tokens generation. You may find you timezone offset (or another name is "UTC offset") [here](https://www.timeanddate.com/time/zone/timezone/utc) or on any other website found in google.
49+
**Description:** Timezone offset **in hours**. Need to be modified manually. Because of Flipper Zero API doesn't provide an access to timezone offset it is necessary to set it manually for correct TOTP tokens generation. You may find your timezone offset (or another name is "UTC offset") [here](https://www.timeanddate.com/time/zone/timezone/utc) or on any other website found in google.
5050
**Important note: if your timezone offset is negative, use negative sign, like this `-2.0`, however if your timezone offset is positive DO NOT use explicit positive sign, just put offset without any sign like this `2.0`**
5151

5252
### TokenName

totp/scenes/app_settings/totp_app_settings.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bool totp_scene_app_settings_handle_event(
101101
}
102102

103103
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
104-
if(event->input.type != InputTypePress) {
104+
if(event->input.type != InputTypePress && event->input.type != InputTypeRepeat) {
105105
return true;
106106
}
107107

totp/scenes/generate_token/totp_scene_generate_token.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ bool totp_scene_generate_token_handle_event(
293293
return true;
294294
}
295295

296-
if(event->input.type != InputTypePress) {
296+
if(event->input.type != InputTypePress && event->input.type != InputTypeRepeat) {
297297
return true;
298298
}
299299

totp/scenes/scene_director.h

+34
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,46 @@
55
#include "../types/plugin_event.h"
66
#include "totp_scenes_enum.h"
77

8+
/**
9+
* @brief Activates scene
10+
* @param plugin_state application state
11+
* @param scene scene to be activated
12+
* @param context scene context to be passed to the scene activation method
13+
*/
814
void totp_scene_director_activate_scene(
915
PluginState* const plugin_state,
1016
Scene scene,
1117
const void* context);
18+
19+
/**
20+
* @brief Deactivate current scene
21+
* @param plugin_state application state
22+
*/
1223
void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state);
24+
25+
/**
26+
* @brief Initializes all the available scenes
27+
* @param plugin_state application state
28+
*/
1329
void totp_scene_director_init_scenes(PluginState* const plugin_state);
30+
31+
/**
32+
* @brief Renders current scene
33+
* @param canvas canvas to render at
34+
* @param plugin_state application state
35+
*/
1436
void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_state);
37+
38+
/**
39+
* @brief Disposes all the available scenes
40+
* @param plugin_state application state
41+
*/
1542
void totp_scene_director_dispose(const PluginState* const plugin_state);
43+
44+
/**
45+
* @brief Handles application event for the current scene
46+
* @param event event to be handled
47+
* @param plugin_state application state
48+
* @return \c true if event handled and applilcation should continue; \c false if application should be closed
49+
*/
1650
bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* const plugin_state);

totp/scenes/token_menu/totp_scene_token_menu.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,14 @@ bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginSt
147147
dialog_message_free(message);
148148
if(dialog_result == DialogMessageButtonRight &&
149149
!scene_state->current_token_index.is_null) {
150-
ListNode* list_node = list_element_at(
151-
plugin_state->tokens_list, scene_state->current_token_index.value);
152-
153-
TokenInfo* tokenInfo = list_node->data;
154-
token_info_free(tokenInfo);
155-
plugin_state->tokens_list = list_remove(plugin_state->tokens_list, list_node);
150+
TokenInfo* tokenInfo = NULL;
151+
plugin_state->tokens_list = list_remove_at(
152+
plugin_state->tokens_list,
153+
scene_state->current_token_index.value,
154+
(void**)&tokenInfo);
156155
plugin_state->tokens_count--;
156+
furi_check(tokenInfo != NULL);
157+
token_info_free(tokenInfo);
157158

158159
totp_full_save_config_file(plugin_state);
159160
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);

totp/scenes/totp_scenes_enum.h

+26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
#pragma once
22

3+
/**
4+
* @brief TOTP application scenes
5+
*/
36
typedef enum {
7+
/**
8+
* @brief Empty scene which does nothing
9+
*/
410
TotpSceneNone,
11+
12+
/**
13+
* @brief Scene where user have to enter PIN to authenticate
14+
*/
515
TotpSceneAuthentication,
16+
17+
/**
18+
* @brief Scene where actual TOTP token is getting generated and displayed to the user
19+
*/
620
TotpSceneGenerateToken,
21+
22+
/**
23+
* @brief Scene where user can add new token
24+
*/
725
TotpSceneAddNewToken,
26+
27+
/**
28+
* @brief Scene with a menu for given token, allowing user to do multiple actions
29+
*/
830
TotpSceneTokenMenu,
31+
32+
/**
33+
* @brief Scene where user can change application settings
34+
*/
935
TotpSceneAppSettings
1036
} Scene;

totp/services/base32/base32.c

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
#include <string.h>
19-
2018
#include "base32.h"
2119

2220
int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize) {

totp/services/base32/base32.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,11 @@
2929

3030
#include <stdint.h>
3131

32-
int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize)
33-
__attribute__((visibility("hidden")));
32+
/**
33+
* @brief Decodes Base-32 encoded bytes into plain bytes.
34+
* @param encoded Base-32 encoded bytes
35+
* @param[out] result result output buffer
36+
* @param bufSize result output buffer size
37+
* @return Decoded result length in bytes if successfully decoded; \c -1 otherwise
38+
*/
39+
int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize);

totp/services/cli/cli.c

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "commands/delete/delete.h"
99
#include "commands/timezone/timezone.h"
1010
#include "commands/help/help.h"
11+
#include "commands/move/move.h"
1112

1213
static void totp_cli_print_unknown_command(const FuriString* unknown_command) {
1314
TOTP_CLI_PRINTF(
@@ -44,6 +45,10 @@ static void totp_cli_handler(Cli* cli, FuriString* args, void* context) {
4445
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_TIMEZONE) == 0 ||
4546
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_TIMEZONE_ALT) == 0) {
4647
totp_cli_command_timezone_handle(plugin_state, args, cli);
48+
} else if(
49+
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_MOVE) == 0 ||
50+
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_MOVE_ALT) == 0) {
51+
totp_cli_command_move_handle(plugin_state, args, cli);
4752
} else {
4853
totp_cli_print_unknown_command(cmd);
4954
}

totp/services/cli/commands/add/add.c

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
175175
} else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX) == 0) {
176176
mask_user_input = false;
177177
parsed = true;
178+
} else {
179+
TOTP_CLI_PRINTF("Unknown argument \"%s\"\r\n", furi_string_get_cstr(temp_str));
178180
}
179181

180182
if(!parsed) {

totp/services/cli/commands/help/help.c

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../delete/delete.h"
55
#include "../list/list.h"
66
#include "../timezone/timezone.h"
7+
#include "../move/move.h"
78

89
void totp_cli_command_help_docopt_commands() {
910
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_HELP ", " TOTP_CLI_COMMAND_HELP_ALT
@@ -23,13 +24,15 @@ void totp_cli_command_help_handle() {
2324
totp_cli_command_add_docopt_usage();
2425
totp_cli_command_delete_docopt_usage();
2526
totp_cli_command_timezone_docopt_usage();
27+
totp_cli_command_move_docopt_usage();
2628
cli_nl();
2729
TOTP_CLI_PRINTF("Commands:\r\n");
2830
totp_cli_command_help_docopt_commands();
2931
totp_cli_command_list_docopt_commands();
3032
totp_cli_command_add_docopt_commands();
3133
totp_cli_command_delete_docopt_commands();
3234
totp_cli_command_timezone_docopt_commands();
35+
totp_cli_command_move_docopt_commands();
3336
cli_nl();
3437
TOTP_CLI_PRINTF("Arguments:\r\n");
3538
totp_cli_command_add_docopt_arguments();
@@ -39,4 +42,5 @@ void totp_cli_command_help_handle() {
3942
TOTP_CLI_PRINTF("Options:\r\n");
4043
totp_cli_command_add_docopt_options();
4144
totp_cli_command_delete_docopt_options();
45+
totp_cli_command_move_docopt_options();
4246
}

0 commit comments

Comments
 (0)