From ae9a719eb8d829c0e77486feb7742e49a368c068 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 31 Jan 2024 02:45:11 +0000 Subject: [PATCH] Better way of doing favorite timeout --- applications/main/lfrfid/lfrfid.c | 7 ++----- applications/main/lfrfid/lfrfid_i.h | 2 ++ applications/main/lfrfid/scenes/lfrfid_scene_emulate.c | 7 ++++++- applications/main/nfc/nfc_app.c | 7 ++----- applications/main/nfc/nfc_app_i.h | 2 ++ applications/main/nfc/scenes/nfc_scene_emulate.c | 8 +++++++- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/applications/main/lfrfid/lfrfid.c b/applications/main/lfrfid/lfrfid.c index a2eaa0619..9748ba614 100644 --- a/applications/main/lfrfid/lfrfid.c +++ b/applications/main/lfrfid/lfrfid.c @@ -216,6 +216,7 @@ int32_t lfrfid_app(char* args) { if(lfrfid_load_key_data(app, app->file_path, true)) { view_dispatcher_attach_to_gui( app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + app->fav_timeout = is_favorite; scene_manager_next_scene(app->scene_manager, LfRfidSceneEmulate); dolphin_deed(DolphinDeedRfidEmulate); } else { @@ -228,11 +229,7 @@ int32_t lfrfid_app(char* args) { scene_manager_next_scene(app->scene_manager, LfRfidSceneStart); } - if(is_favorite) { - favorite_timeout_run(app->view_dispatcher, app->scene_manager); - } else { - view_dispatcher_run(app->view_dispatcher); - } + view_dispatcher_run(app->view_dispatcher); lfrfid_free(app); diff --git a/applications/main/lfrfid/lfrfid_i.h b/applications/main/lfrfid/lfrfid_i.h index 97e6e9db4..00bb1eba9 100644 --- a/applications/main/lfrfid/lfrfid_i.h +++ b/applications/main/lfrfid/lfrfid_i.h @@ -112,6 +112,8 @@ struct LfRfid { // Custom views LfRfidReadView* read_view; + + bool fav_timeout; }; typedef enum { diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_emulate.c b/applications/main/lfrfid/scenes/lfrfid_scene_emulate.c index b729f4de0..b71a73971 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_emulate.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_emulate.c @@ -1,5 +1,7 @@ #include "../lfrfid_i.h" +#include + #define LFRFID_EMULATION_TIME_MAX_MS (5 * 60 * 1000) FuriTimer* timer_auto_exit; @@ -33,7 +35,10 @@ void lfrfid_scene_emulate_on_enter(void* context) { timer_auto_exit = furi_timer_alloc(lfrfid_scene_emulate_popup_callback, FuriTimerTypeOnce, app); - furi_timer_start(timer_auto_exit, LFRFID_EMULATION_TIME_MAX_MS); + furi_timer_start( + timer_auto_exit, + app->fav_timeout ? xtreme_settings.favorite_timeout * furi_kernel_get_tick_frequency() : + LFRFID_EMULATION_TIME_MAX_MS); view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup); } diff --git a/applications/main/nfc/nfc_app.c b/applications/main/nfc/nfc_app.c index 5df7c7d62..ded104f3e 100644 --- a/applications/main/nfc/nfc_app.c +++ b/applications/main/nfc/nfc_app.c @@ -506,6 +506,7 @@ int32_t nfc_app(void* p) { furi_string_set(nfc->file_path, args); if(nfc_load_file(nfc, nfc->file_path, false)) { + nfc->fav_timeout = is_favorite; nfc_show_initial_scene_for_device(nfc); } else { view_dispatcher_stop(nfc->view_dispatcher); @@ -517,11 +518,7 @@ int32_t nfc_app(void* p) { scene_manager_next_scene(nfc->scene_manager, NfcSceneStart); } - if(is_favorite) { - favorite_timeout_run(nfc->view_dispatcher, nfc->scene_manager); - } else { - view_dispatcher_run(nfc->view_dispatcher); - } + view_dispatcher_run(nfc->view_dispatcher); nfc_app_free(nfc); diff --git a/applications/main/nfc/nfc_app_i.h b/applications/main/nfc/nfc_app_i.h index ca3510fb4..cdf228752 100644 --- a/applications/main/nfc/nfc_app_i.h +++ b/applications/main/nfc/nfc_app_i.h @@ -141,6 +141,8 @@ struct NfcApp { FuriString* file_path; FuriString* file_name; FuriTimer* timer; + + bool fav_timeout; }; typedef enum { diff --git a/applications/main/nfc/scenes/nfc_scene_emulate.c b/applications/main/nfc/scenes/nfc_scene_emulate.c index 0f178f463..9a094a0a8 100644 --- a/applications/main/nfc/scenes/nfc_scene_emulate.c +++ b/applications/main/nfc/scenes/nfc_scene_emulate.c @@ -2,6 +2,8 @@ #include "nfc_app_i.h" +#include + #define NFC_EMULATION_TIME_MAX_MS (5 * 60 * 1000) FuriTimer* timer_auto_exit; @@ -20,7 +22,11 @@ void nfc_scene_emulate_on_enter(void* context) { timer_auto_exit = furi_timer_alloc(nfc_scene_emulate_timer_callback, FuriTimerTypeOnce, instance); - furi_timer_start(timer_auto_exit, NFC_EMULATION_TIME_MAX_MS); + furi_timer_start( + timer_auto_exit, + instance->fav_timeout ? + xtreme_settings.favorite_timeout * furi_kernel_get_tick_frequency() : + NFC_EMULATION_TIME_MAX_MS); } bool nfc_scene_emulate_on_event(void* context, SceneManagerEvent event) {