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
*/
NumberField field_threshold{
{1 * 8 + sizeof("Threshold:") * 8 + 8, 11 * 16},
{1 * 8 + 11 * 8 + 8, 11 * 16},
4,
{1, 1023},
1,

View File

@ -11,10 +11,32 @@ namespace ui {
/* 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.
/* static */ void ExternalItemsMenuLoader::load_all_external_items_callback(std::function<void(AppInfoConsole&)> 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<void(AppInfoConsole&)> 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<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)
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.
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 info{
.appCallName = appshortname.c_str(),
.appFriendlyName = reinterpret_cast<char*>(&application_information.app_name[0]),
.appLocation = application_information.menu_location};
callback(info);
AppInfoConsole appInfoConsole = {appshortname.c_str(), reinterpret_cast<char*>(&application_information.app_name[0]), application_information.menu_location};
callback(appInfoConsole);
}
}
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<char*>(&application_information.app_name[0]),
.appLocation = application_information.menu_location};
callback(info);
AppInfoConsole appInfoConsole = {appshortname.c_str(), reinterpret_cast<char*>(&application_information.app_name[0]), application_information.menu_location};
callback(appInfoConsole);
}
}

View File

@ -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<void(AppInfoConsole&)> callback);
static void load_all_external_items_callback(std::function<void(AppInfoConsole&)> callback, bool module_included = false);
private:
static std::vector<DynamicBitmap<16, 16>> bitmaps;

View File

@ -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<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
std::filesystem::path pth = conv.from_bytes(appwithpath.c_str());
if (ui::ExternalItemsMenuLoader::run_external_app(*this, pth)) {
return true;
}
return false;
};
// outside app
if (!app_started) {
app_started = execute_app(".ppma");
started = true;
}
// standalone app
if (!app_started) {
app_started = execute_app(".ppmp");
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;
}
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 **************************************************************/