diff --git a/applications/services/application.fam b/applications/services/application.fam index 934b0b012..6c41160db 100644 --- a/applications/services/application.fam +++ b/applications/services/application.fam @@ -6,6 +6,7 @@ App( "crypto_start", "rpc_start", "bt", + "xtreme", "desktop", "loader", "power", diff --git a/applications/services/storage/application.fam b/applications/services/storage/application.fam index 7aa721cc3..7b106e00f 100644 --- a/applications/services/storage/application.fam +++ b/applications/services/storage/application.fam @@ -7,7 +7,7 @@ App( requires=["storage_settings"], provides=["storage_start"], stack_size=3 * 1024, - order=120, + order=44, sdk_headers=["storage.h"], ) diff --git a/applications/services/xtreme/application.fam b/applications/services/xtreme/application.fam index 2dfcab051..1b4d73058 100644 --- a/applications/services/xtreme/application.fam +++ b/applications/services/xtreme/application.fam @@ -1,10 +1,10 @@ App( appid="xtreme", - apptype=FlipperAppType.STARTUP, - entry_point="xtreme_on_system_start", + name="Xtreme", + apptype=FlipperAppType.SERVICE, + entry_point="xtreme_srv", + cdefines=["SRV_XTREME"], requires=["storage"], - order=1000, - provides=[ - "xtreme", - ], + stack_size=1 * 1024, + order=46, ) diff --git a/applications/services/xtreme/assets.c b/applications/services/xtreme/assets.c index 1862f1ec7..88a6d563d 100644 --- a/applications/services/xtreme/assets.c +++ b/applications/services/xtreme/assets.c @@ -2,6 +2,8 @@ #include #include +#define TAG "XtremeAssets" + #define ICONS_FMT PACKS_DIR "/%s/Icons/%s" XtremeAssets* xtreme_assets = NULL; @@ -111,7 +113,6 @@ void XTREME_ASSETS_LOAD() { if(xtreme_assets != NULL) return; xtreme_assets = malloc(sizeof(XtremeAssets)); - XtremeSettings* xtreme_settings = XTREME_SETTINGS(); xtreme_assets->A_Levelup_128x64 = &A_Levelup_128x64; xtreme_assets->I_BLE_Pairing_128x64 = &I_BLE_Pairing_128x64; @@ -136,20 +137,34 @@ void XTREME_ASSETS_LOAD() { xtreme_assets->I_Connected_62x31 = &I_Connected_62x31; xtreme_assets->I_Error_62x31 = &I_Error_62x31; + if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { + FURI_LOG_W(TAG, "Load skipped. Device is in special startup mode."); + return; + } + + XtremeSettings* xtreme_settings = XTREME_SETTINGS(); if(xtreme_settings->asset_pack[0] == '\0') return; xtreme_assets->is_nsfw = strncmp(xtreme_settings->asset_pack, "NSFW", strlen("NSFW")) == 0; + + Storage* storage = furi_record_open(RECORD_STORAGE); + int32_t timeout = 5000; + while(timeout > 0) { + if(storage_sd_status(storage) == FSE_OK) break; + furi_delay_ms(250); + timeout -= 250; + } + FileInfo info; FuriString* path = furi_string_alloc(); furi_string_printf(path, PACKS_DIR "/%s", xtreme_settings->asset_pack); - Storage* storage = furi_record_open(RECORD_STORAGE); if(storage_common_stat(storage, furi_string_get_cstr(path), &info) == FSE_OK && info.flags & FSF_DIRECTORY) { File* file = storage_file_alloc(storage); swap(xtreme_assets, path, file); storage_file_free(file); } - furi_record_close(RECORD_STORAGE); furi_string_free(path); + furi_record_close(RECORD_STORAGE); } XtremeAssets* XTREME_ASSETS() { diff --git a/applications/services/xtreme/settings.c b/applications/services/xtreme/settings.c index eea68bd2b..bf1acae1b 100644 --- a/applications/services/xtreme/settings.c +++ b/applications/services/xtreme/settings.c @@ -1,5 +1,7 @@ #include "settings.h" +#define TAG "XtremeSettings" + XtremeSettings* xtreme_settings = NULL; XtremeSettings* XTREME_SETTINGS() { @@ -9,28 +11,39 @@ XtremeSettings* XTREME_SETTINGS() { return xtreme_settings; } -bool XTREME_SETTINGS_LOAD() { +void XTREME_SETTINGS_LOAD() { if(xtreme_settings == NULL) { + xtreme_settings = malloc(sizeof(XtremeSettings)); - bool loaded = saved_struct_load( - XTREME_SETTINGS_PATH, - xtreme_settings, - sizeof(XtremeSettings), - XTREME_SETTINGS_MAGIC, - XTREME_SETTINGS_VERSION); + bool loaded; + + if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { + FURI_LOG_W(TAG, "Load skipped. Device is in special startup mode."); + loaded = false; + } else { + loaded = saved_struct_load( + XTREME_SETTINGS_PATH, + xtreme_settings, + sizeof(XtremeSettings), + XTREME_SETTINGS_MAGIC, + XTREME_SETTINGS_VERSION); + } + if(!loaded) { memset(xtreme_settings, 0, sizeof(XtremeSettings)); - loaded = XTREME_SETTINGS_SAVE(); } - return loaded; } - return true; } bool XTREME_SETTINGS_SAVE() { if(xtreme_settings == NULL) { XTREME_SETTINGS_LOAD(); } + + if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) { + return true; + } + return saved_struct_save( XTREME_SETTINGS_PATH, xtreme_settings, diff --git a/applications/services/xtreme/settings.h b/applications/services/xtreme/settings.h index 7bbb07c9b..8dd69ff7f 100644 --- a/applications/services/xtreme/settings.h +++ b/applications/services/xtreme/settings.h @@ -34,6 +34,6 @@ typedef struct { XtremeSettings* XTREME_SETTINGS(); -bool XTREME_SETTINGS_LOAD(); +void XTREME_SETTINGS_LOAD(); bool XTREME_SETTINGS_SAVE(); diff --git a/applications/services/xtreme/on_system_start.c b/applications/services/xtreme/xtreme_srv.c similarity index 61% rename from applications/services/xtreme/on_system_start.c rename to applications/services/xtreme/xtreme_srv.c index 531888f1b..fa6fb97f2 100644 --- a/applications/services/xtreme/on_system_start.c +++ b/applications/services/xtreme/xtreme_srv.c @@ -1,7 +1,11 @@ #include "settings.h" #include "assets.h" -void xtreme_on_system_start() { +int32_t xtreme_srv(void* p) { + UNUSED(p); + XTREME_SETTINGS_LOAD(); XTREME_ASSETS_LOAD(); + + return 0; }