From d6a9c746653c3e6c04fba7a1cf60da433d82a07e Mon Sep 17 00:00:00 2001 From: Totoo Date: Sat, 2 Nov 2024 15:15:33 +0100 Subject: [PATCH] Auto start again (#2333) * Extend autostart a bit * @zxkmm 's sizeof fix --- firmware/application/apps/ui_settings.hpp | 2 +- .../ui_external_items_menu_loader.cpp | 57 ++++++++++++------- .../ui_external_items_menu_loader.hpp | 2 +- firmware/application/ui_navigation.cpp | 38 ++++++------- 4 files changed, 56 insertions(+), 43 deletions(-) diff --git a/firmware/application/apps/ui_settings.hpp b/firmware/application/apps/ui_settings.hpp index cf6849a73..77ecea812 100644 --- a/firmware/application/apps/ui_settings.hpp +++ b/firmware/application/apps/ui_settings.hpp @@ -795,7 +795,7 @@ class SetTouchscreenThresholdView : public View { * threshold range: 1023/1 to 1023/128 = 1023 to 8 */ NumberField field_threshold{ - {1 * 8 + sizeof("Threshold:") * 8 + 8, 11 * 16}, + {1 * 8 + 11 * 8 + 8, 11 * 16}, 4, {1, 1023}, 1, diff --git a/firmware/application/ui_external_items_menu_loader.cpp b/firmware/application/ui_external_items_menu_loader.cpp index 7090e8679..31a322e18 100644 --- a/firmware/application/ui_external_items_menu_loader.cpp +++ b/firmware/application/ui_external_items_menu_loader.cpp @@ -11,10 +11,32 @@ namespace ui { /* static */ std::vector> ExternalItemsMenuLoader::bitmaps; -// iterates over all ppma-s, and if it is runnable on the current system, it'll call the callback, and pass info. -/* static */ void ExternalItemsMenuLoader::load_all_external_items_callback(std::function callback) { +// iterates over all possible ext apps-s, and if it is runnable on the current system, it'll call the callback, and pass minimal info. used to print to console, and for autostart setting's app list. where the minimal info is enough +// please keep in sync with load_external_items +/* static */ void ExternalItemsMenuLoader::load_all_external_items_callback(std::function callback, bool module_included) { if (!callback) return; + auto dev = (i2cdev::I2cDev_PPmod*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDECMDL_PPMOD); + + if (dev && module_included) { + auto device_info = dev->readDeviceInfo(); + + if (device_info.has_value()) { + for (uint32_t i = 0; i < device_info->application_count; i++) { + auto appInfo = dev->getStandaloneAppInfo(i); + if (appInfo.has_value() == false) { + continue; + } + + if (appInfo->header_version > CURRENT_STANDALONE_APPLICATION_API_VERSION) + continue; + + AppInfoConsole appInfoConsole = {reinterpret_cast(&appInfo->app_name[0]), reinterpret_cast(&appInfo->app_name[0]), appInfo->menu_location}; + callback(appInfoConsole); + } + } + } + if (sd_card::status() != sd_card::Status::Mounted) return; @@ -36,18 +58,16 @@ namespace ui { continue; bool versionMatches = VERSION_MD5 == application_information.app_version; - if (!versionMatches) continue; - // here the app is startable and good. - std::string appshortname = filePath.filename().string(); - if (appshortname.size() >= 5 && appshortname.substr(appshortname.size() - 5) == ".ppma") { - // Remove the ".ppma" suffix - appshortname = appshortname.substr(0, appshortname.size() - 5); + + if (versionMatches) { + std::string appshortname = filePath.filename().string(); + if (appshortname.size() >= 5 && appshortname.substr(appshortname.size() - 5) == ".ppma") { + // Remove the ".ppma" suffix + appshortname = appshortname.substr(0, appshortname.size() - 5); + } + AppInfoConsole appInfoConsole = {appshortname.c_str(), reinterpret_cast(&application_information.app_name[0]), application_information.menu_location}; + callback(appInfoConsole); } - AppInfoConsole info{ - .appCallName = appshortname.c_str(), - .appFriendlyName = reinterpret_cast(&application_information.app_name[0]), - .appLocation = application_information.menu_location}; - callback(info); } for (const auto& entry : std::filesystem::directory_iterator(apps_dir, u"*.ppmp")) { @@ -64,21 +84,16 @@ namespace ui { if (!readResult) continue; - if (application_information.header_version < CURRENT_STANDALONE_APPLICATION_API_VERSION) + if (application_information.header_version > CURRENT_STANDALONE_APPLICATION_API_VERSION) continue; - // here the app is startable and good. std::string appshortname = filePath.filename().string(); if (appshortname.size() >= 5 && appshortname.substr(appshortname.size() - 5) == ".ppmp") { // Remove the ".ppmp" suffix appshortname = appshortname.substr(0, appshortname.size() - 5); } - AppInfoConsole info{ - .appCallName = appshortname.c_str(), - .appFriendlyName = reinterpret_cast(&application_information.app_name[0]), - .appLocation = application_information.menu_location}; - - callback(info); + AppInfoConsole appInfoConsole = {appshortname.c_str(), reinterpret_cast(&application_information.app_name[0]), application_information.menu_location}; + callback(appInfoConsole); } } diff --git a/firmware/application/ui_external_items_menu_loader.hpp b/firmware/application/ui_external_items_menu_loader.hpp index d9b932971..3b547f1f5 100644 --- a/firmware/application/ui_external_items_menu_loader.hpp +++ b/firmware/application/ui_external_items_menu_loader.hpp @@ -60,7 +60,7 @@ class ExternalItemsMenuLoader { static bool run_external_app(ui::NavigationView&, std::filesystem::path); static bool run_standalone_app(ui::NavigationView&, std::filesystem::path); static bool run_module_app(ui::NavigationView&, uint8_t*, size_t); - static void load_all_external_items_callback(std::function callback); + static void load_all_external_items_callback(std::function callback, bool module_included = false); private: static std::vector> bitmaps; diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 42e4ffaf0..ca812282d 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -724,42 +724,40 @@ void NavigationView::handle_autostart() { "nav"sv, {{"autostart_app"sv, &autostart_app}}}; if (!autostart_app.empty()) { - bool app_started = false; + bool started = false; // inner app if (StartAppByName(autostart_app.c_str())) { - app_started = true; - return; + started = true; } - // lambda - auto execute_app = [=](const std::string& extension) { // TODO: capture ref aka [&] would also lagging th GUI, no idea why - std::string appwithpath = "/" + apps_dir.string() + "/" + autostart_app + extension; + if (!started) { + // ppma + + std::string appwithpath = "/" + apps_dir.string() + "/" + autostart_app + ".ppma"; std::wstring_convert, char16_t> conv; std::filesystem::path pth = conv.from_bytes(appwithpath.c_str()); if (ui::ExternalItemsMenuLoader::run_external_app(*this, pth)) { - return true; + started = true; } - return false; - }; - // outside app - if (!app_started) { - app_started = execute_app(".ppma"); + if (!started) { + // ppmp / standalone + appwithpath = "/" + apps_dir.string() + "/" + autostart_app + ".ppmp"; + pth = conv.from_bytes(appwithpath.c_str()); + if (ui::ExternalItemsMenuLoader::run_standalone_app(*this, pth)) { + started = true; + } + } } - - // standalone app - if (!app_started) { - app_started = execute_app(".ppmp"); - } - - if (!app_started) { + if (!started) { display_modal( "Notice", "Autostart failed:\n" + autostart_app + "\nupdate sdcard content\n" + "and check if .ppma exists"); } - } + } // autostart end + return; } /* Helpers **************************************************************/