Auto start again (#2333)

* Extend autostart a bit

* @zxkmm 's sizeof fix
This commit is contained in:
Totoo 2024-11-02 15:15:33 +01:00 committed by GitHub
parent 5bb23b636e
commit d6a9c74665
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 56 additions and 43 deletions

View File

@ -795,7 +795,7 @@ class SetTouchscreenThresholdView : public View {
* threshold range: 1023/1 to 1023/128 = 1023 to 8 * threshold range: 1023/1 to 1023/128 = 1023 to 8
*/ */
NumberField field_threshold{ NumberField field_threshold{
{1 * 8 + sizeof("Threshold:") * 8 + 8, 11 * 16}, {1 * 8 + 11 * 8 + 8, 11 * 16},
4, 4,
{1, 1023}, {1, 1023},
1, 1,

View File

@ -11,10 +11,32 @@ namespace ui {
/* static */ std::vector<DynamicBitmap<16, 16>> ExternalItemsMenuLoader::bitmaps; /* static */ std::vector<DynamicBitmap<16, 16>> ExternalItemsMenuLoader::bitmaps;
// iterates over all ppma-s, and if it is runnable on the current system, it'll call the callback, and pass info. // 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
/* static */ void ExternalItemsMenuLoader::load_all_external_items_callback(std::function<void(AppInfoConsole&)> callback) { // please keep in sync with load_external_items
/* static */ void ExternalItemsMenuLoader::load_all_external_items_callback(std::function<void(AppInfoConsole&)> callback, bool module_included) {
if (!callback) return; 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<char*>(&appInfo->app_name[0]), reinterpret_cast<char*>(&appInfo->app_name[0]), appInfo->menu_location};
callback(appInfoConsole);
}
}
}
if (sd_card::status() != sd_card::Status::Mounted) if (sd_card::status() != sd_card::Status::Mounted)
return; return;
@ -36,18 +58,16 @@ namespace ui {
continue; continue;
bool versionMatches = VERSION_MD5 == application_information.app_version; bool versionMatches = VERSION_MD5 == application_information.app_version;
if (!versionMatches) continue;
// here the app is startable and good. if (versionMatches) {
std::string appshortname = filePath.filename().string(); std::string appshortname = filePath.filename().string();
if (appshortname.size() >= 5 && appshortname.substr(appshortname.size() - 5) == ".ppma") { if (appshortname.size() >= 5 && appshortname.substr(appshortname.size() - 5) == ".ppma") {
// Remove the ".ppma" suffix // Remove the ".ppma" suffix
appshortname = appshortname.substr(0, appshortname.size() - 5); appshortname = appshortname.substr(0, appshortname.size() - 5);
}
AppInfoConsole appInfoConsole = {appshortname.c_str(), reinterpret_cast<char*>(&application_information.app_name[0]), application_information.menu_location};
callback(appInfoConsole);
} }
AppInfoConsole info{
.appCallName = appshortname.c_str(),
.appFriendlyName = reinterpret_cast<char*>(&application_information.app_name[0]),
.appLocation = application_information.menu_location};
callback(info);
} }
for (const auto& entry : std::filesystem::directory_iterator(apps_dir, u"*.ppmp")) { for (const auto& entry : std::filesystem::directory_iterator(apps_dir, u"*.ppmp")) {
@ -64,21 +84,16 @@ namespace ui {
if (!readResult) if (!readResult)
continue; continue;
if (application_information.header_version < CURRENT_STANDALONE_APPLICATION_API_VERSION) if (application_information.header_version > CURRENT_STANDALONE_APPLICATION_API_VERSION)
continue; continue;
// here the app is startable and good.
std::string appshortname = filePath.filename().string(); std::string appshortname = filePath.filename().string();
if (appshortname.size() >= 5 && appshortname.substr(appshortname.size() - 5) == ".ppmp") { if (appshortname.size() >= 5 && appshortname.substr(appshortname.size() - 5) == ".ppmp") {
// Remove the ".ppmp" suffix // Remove the ".ppmp" suffix
appshortname = appshortname.substr(0, appshortname.size() - 5); appshortname = appshortname.substr(0, appshortname.size() - 5);
} }
AppInfoConsole info{ AppInfoConsole appInfoConsole = {appshortname.c_str(), reinterpret_cast<char*>(&application_information.app_name[0]), application_information.menu_location};
.appCallName = appshortname.c_str(), callback(appInfoConsole);
.appFriendlyName = reinterpret_cast<char*>(&application_information.app_name[0]),
.appLocation = application_information.menu_location};
callback(info);
} }
} }

View File

@ -60,7 +60,7 @@ class ExternalItemsMenuLoader {
static bool run_external_app(ui::NavigationView&, std::filesystem::path); static bool run_external_app(ui::NavigationView&, std::filesystem::path);
static bool run_standalone_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 bool run_module_app(ui::NavigationView&, uint8_t*, size_t);
static void load_all_external_items_callback(std::function<void(AppInfoConsole&)> callback); static void load_all_external_items_callback(std::function<void(AppInfoConsole&)> callback, bool module_included = false);
private: private:
static std::vector<DynamicBitmap<16, 16>> bitmaps; static std::vector<DynamicBitmap<16, 16>> bitmaps;

View File

@ -724,42 +724,40 @@ void NavigationView::handle_autostart() {
"nav"sv, "nav"sv,
{{"autostart_app"sv, &autostart_app}}}; {{"autostart_app"sv, &autostart_app}}};
if (!autostart_app.empty()) { if (!autostart_app.empty()) {
bool app_started = false; bool started = false;
// inner app // inner app
if (StartAppByName(autostart_app.c_str())) { if (StartAppByName(autostart_app.c_str())) {
app_started = true; started = true;
return;
} }
// lambda if (!started) {
auto execute_app = [=](const std::string& extension) { // TODO: capture ref aka [&] would also lagging th GUI, no idea why // ppma
std::string appwithpath = "/" + apps_dir.string() + "/" + autostart_app + extension;
std::string appwithpath = "/" + apps_dir.string() + "/" + autostart_app + ".ppma";
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
std::filesystem::path pth = conv.from_bytes(appwithpath.c_str()); std::filesystem::path pth = conv.from_bytes(appwithpath.c_str());
if (ui::ExternalItemsMenuLoader::run_external_app(*this, pth)) { if (ui::ExternalItemsMenuLoader::run_external_app(*this, pth)) {
return true; started = true;
} }
return false;
};
// outside app if (!started) {
if (!app_started) { // ppmp / standalone
app_started = execute_app(".ppma"); appwithpath = "/" + apps_dir.string() + "/" + autostart_app + ".ppmp";
pth = conv.from_bytes(appwithpath.c_str());
if (ui::ExternalItemsMenuLoader::run_standalone_app(*this, pth)) {
started = true;
}
}
} }
if (!started) {
// standalone app
if (!app_started) {
app_started = execute_app(".ppmp");
}
if (!app_started) {
display_modal( display_modal(
"Notice", "Autostart failed:\n" + "Notice", "Autostart failed:\n" +
autostart_app + autostart_app +
"\nupdate sdcard content\n" + "\nupdate sdcard content\n" +
"and check if .ppma exists"); "and check if .ppma exists");
} }
} } // autostart end
return;
} }
/* Helpers **************************************************************/ /* Helpers **************************************************************/