From 51512a30bd9ba206e2fea0490310af4ecfec0a13 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Wed, 30 Apr 2025 08:40:25 +0300 Subject: [PATCH] nyx: improve Nyx reload and auto reload Check that Nyx exists and also improve detection when SD is removed. --- nyx/nyx_gui/frontend/gui.c | 44 ++++++++++++++++++++++-------- nyx/nyx_gui/frontend/gui_options.c | 2 +- nyx/nyx_gui/nyx.c | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index b7be9f3..570deed 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -38,7 +38,7 @@ extern volatile nyx_storage_t *nyx_str; extern lv_res_t launch_payload(lv_obj_t *list); static bool disp_init_done = false; -static bool do_reload = false; +static bool do_auto_reload = false; lv_style_t hint_small_style; lv_style_t hint_small_style_white; @@ -200,8 +200,8 @@ static void _save_fb_to_bmp() if (get_tmr_ms() < timer) return; - if (do_reload) - return; + if (do_auto_reload) + goto exit; // Invalidate data. bpmp_mmu_maintenance(BPMP_MMU_MAINT_INVALID_WAY, false); @@ -304,6 +304,7 @@ static void _save_fb_to_bmp() manual_system_maintenance(true); lv_mbox_start_auto_close(mbox, 4000); +exit: // Set timer to 2s. timer = get_tmr_ms() + 2000; } @@ -928,8 +929,27 @@ static void _launch_hos(u8 autoboot, u8 autoboot_list) (*main_ptr)(); } -void reload_nyx() +void reload_nyx(lv_obj_t *obj, bool force) { + if (!force) + { + sd_mount(); + + // Check that Nyx still exists. + if (f_stat("bootloader/sys/nyx.bin", NULL)) + { + sd_unmount(); + + // Remove lvgl object in case of being invoked from a window. + if (obj) + lv_obj_del(obj); + + do_auto_reload = false; + + return; + } + } + b_cfg->boot_cfg = BOOT_CFG_AUTOBOOT_EN; b_cfg->autoboot = 0; b_cfg->autoboot_list = 0; @@ -947,7 +967,7 @@ void reload_nyx() static lv_res_t reload_action(lv_obj_t *btns, const char *txt) { if (!lv_btnm_get_pressed(btns)) - reload_nyx(); + reload_nyx(NULL, false); return mbox_action(btns, txt); } @@ -969,7 +989,7 @@ static lv_res_t _removed_sd_action(lv_obj_t *btns, const char *txt) break; case 2: sd_end(); - do_reload = false; + do_auto_reload = false; break; } @@ -978,12 +998,14 @@ static lv_res_t _removed_sd_action(lv_obj_t *btns, const char *txt) static void _check_sd_card_removed(void *params) { + static lv_obj_t *dark_bg = NULL; + // The following checks if SDMMC_1 is initialized. // If yes and card was removed, shows a message box, // that will reload Nyx, when the card is inserted again. - if (!do_reload && sd_get_card_removed()) + if (!do_auto_reload && sd_get_card_removed()) { - lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + dark_bg = lv_obj_create(lv_scr_act(), NULL); lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); @@ -999,12 +1021,12 @@ static void _check_sd_card_removed(void *params) lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_set_top(mbox, true); - do_reload = true; + do_auto_reload = true; } // If in reload state and card was inserted, reload nyx. - if (do_reload && !sd_get_card_removed()) - reload_nyx(); + if (do_auto_reload && !sd_get_card_removed()) + reload_nyx(dark_bg, false); } lv_task_t *task_emmc_errors; diff --git a/nyx/nyx_gui/frontend/gui_options.c b/nyx/nyx_gui/frontend/gui_options.c index 999b221..63b098d 100644 --- a/nyx/nyx_gui/frontend/gui_options.c +++ b/nyx/nyx_gui/frontend/gui_options.c @@ -432,7 +432,7 @@ static lv_res_t _save_theme_color_action(lv_obj_t *btn) // Save nyx config. create_nyx_config_entry(true); - reload_nyx(); + reload_nyx(NULL, false); return LV_RES_OK; } diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index 86d90cd..05275a2 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -402,7 +402,7 @@ error_occured: msleep(1000); btn_wait(); - reload_nyx(); + reload_nyx(NULL, true); } }