diff --git a/applications/services/application.fam b/applications/services/application.fam index aec49b231..afa69301d 100644 --- a/applications/services/application.fam +++ b/applications/services/application.fam @@ -9,5 +9,6 @@ App( "desktop", "loader", "power", + "namechange_srv", ], ) diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index 25e2017c2..77999dfcc 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -9,9 +9,6 @@ #include #include -#include -#include - #include "animations/animation_manager.h" #include "desktop/scenes/desktop_scene.h" #include "desktop/scenes/desktop_scene_i.h" @@ -429,26 +426,6 @@ int32_t desktop_srv(void* p) { scene_manager_next_scene(desktop->scene_manager, DesktopSceneFault); } - // I added some very bydlo kod here, and thrown some delays to make it worse, pls don't look at it, it will make you cry from laugh - if(furi_hal_rtc_get_boot_mode() == FuriHalRtcBootModeNormal) { - if(NameChanger_Init()) { - Cli* cli = furi_record_open(RECORD_CLI); - cli_session_close(cli); - furi_delay_ms(2); - cli_session_open(cli, &cli_vcp); - furi_record_close(RECORD_CLI); - - furi_delay_ms(3); - Bt* bt = furi_record_open(RECORD_BT); - if(!bt_set_profile(bt, BtProfileSerial)) { - FURI_LOG_D(TAG, "Failed to touch bluetooth to name change"); - } - furi_record_close(RECORD_BT); - bt = NULL; - furi_delay_ms(3); - } - } - view_dispatcher_run(desktop->view_dispatcher); desktop_free(desktop); diff --git a/applications/services/namechanger/application.fam b/applications/services/namechanger/application.fam new file mode 100644 index 000000000..a4bc23938 --- /dev/null +++ b/applications/services/namechanger/application.fam @@ -0,0 +1,8 @@ +App( + appid="namechange_srv", + apptype=FlipperAppType.STARTUP, + entry_point="namechange_on_system_start", + requires=["storage", "cli", "bt"], + conflicts=["updater"], + order=600, +) \ No newline at end of file diff --git a/applications/services/namechanger/namechange.c b/applications/services/namechanger/namechange.c new file mode 100644 index 000000000..22cb0d9de --- /dev/null +++ b/applications/services/namechanger/namechange.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +#include +#include + +int32_t namechange_on_system_start(void* p) { + UNUSED(p); + if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { + return 0; + } + + // Wait for all required services to start and create their records + uint8_t timeout = 0; + while(!furi_record_exists(RECORD_CLI) || !furi_record_exists(RECORD_BT) || + !furi_record_exists(RECORD_STORAGE)) { + timeout++; + if(timeout > 250) { + return 0; + } + furi_delay_ms(5); + } + + // Hehe bad code now here, bad bad bad, very bad, bad example, dont take it, make it better + + if(NameChanger_Init()) { + Cli* cli = furi_record_open(RECORD_CLI); + cli_session_close(cli); + furi_delay_ms(2); // why i added delays here + cli_session_open(cli, &cli_vcp); + furi_record_close(RECORD_CLI); + + furi_delay_ms(3); + Bt* bt = furi_record_open(RECORD_BT); + if(!bt_set_profile(bt, BtProfileSerial)) { + //FURI_LOG_D(TAG, "Failed to touch bluetooth to name change"); + } + furi_record_close(RECORD_BT); + bt = NULL; + furi_delay_ms(3); + } + + return 0; +} \ No newline at end of file diff --git a/lib/toolbox/namechanger.c b/lib/toolbox/namechanger.c index 33842bcd7..94e08ac13 100644 --- a/lib/toolbox/namechanger.c +++ b/lib/toolbox/namechanger.c @@ -6,6 +6,20 @@ bool NameChanger_Init() { Storage* storage = furi_record_open(RECORD_STORAGE); + + // Kostil + velosiped = top ficha + uint8_t timeout = 0; + while(timeout < 11) { + if(storage_sd_status(storage) == FSE_OK) break; + furi_delay_ms(250); + timeout++; + /*if(timeout == 10) { + // Failed to init namechanger, SD card not ready + furi_record_close(RECORD_STORAGE); + return false; + }*/ + } + FuriString* str = furi_string_alloc(); FlipperFormat* file = flipper_format_file_alloc(storage);