Run executables directly (#645)
- Apps can be launched directly from file paths (including Files app support) - Added executable detection to identify unsupported or invalid binaries before launch. - App startup is now streamlined through separate registered-app and direct-execution interfaces. - Existing app launch points were migrated to the updated startup APIs.
This commit is contained in:
committed by
GitHub
parent
643cbc3806
commit
a0b2ee7ebc
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <app/event.h>
|
||||
#include <app/manager.h>
|
||||
#include <app/start.h>
|
||||
#include <app/manifest.h>
|
||||
#include <app/scheduler.h>
|
||||
#include <app/stream.h>
|
||||
|
||||
#include <lvgl_window_manager/window_manager.h>
|
||||
|
||||
@@ -13,6 +15,8 @@
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace tt::app::inputdialog {
|
||||
|
||||
constexpr auto* TAG = "InputDialog";
|
||||
@@ -30,7 +34,8 @@ struct Context {
|
||||
// The eventual appMain() return value - see AlertDialog.cpp's Context::result for why this
|
||||
// is a plain (non-atomic) field safely shared between the LVGL thread (writer, before
|
||||
// emitting APP_EVENT_CLOSE) and this dialog's own thread (reader, after waking from it).
|
||||
int32_t result = 1; // Cancelled - safety-net default if closed without pressing a button
|
||||
int32_t resultCode = 1; // Cancelled - safety-net default if closed without pressing a button
|
||||
std::string resultText;
|
||||
};
|
||||
|
||||
struct ButtonContext {
|
||||
@@ -39,12 +44,6 @@ struct ButtonContext {
|
||||
lv_obj_t* textarea;
|
||||
};
|
||||
|
||||
// The last text entered via OK. Static rather than per-instance: simple, and in practice only
|
||||
// one InputDialog is ever open at a time. Written on the LVGL thread (onButtonPressed(), before
|
||||
// emitting APP_EVENT_CLOSE); read by the parent via getLastText() after receiving that event -
|
||||
// safe without a lock for the same reason Context::result is (see AlertDialog.cpp).
|
||||
std::string lastText;
|
||||
|
||||
void onButtonDeleted(lv_event_t* e) {
|
||||
delete static_cast<ButtonContext*>(lv_event_get_user_data(e));
|
||||
}
|
||||
@@ -53,11 +52,11 @@ void onButtonPressed(lv_event_t* e) {
|
||||
auto* btnCtx = static_cast<ButtonContext*>(lv_event_get_user_data(e));
|
||||
if (btnCtx->textarea != nullptr) {
|
||||
LOG_I(TAG, "OK pressed");
|
||||
lastText = lv_textarea_get_text(btnCtx->textarea);
|
||||
btnCtx->ctx->result = 0;
|
||||
btnCtx->ctx->resultText = lv_textarea_get_text(btnCtx->textarea);
|
||||
btnCtx->ctx->resultCode = 0;
|
||||
} else {
|
||||
LOG_I(TAG, "Cancel pressed");
|
||||
btnCtx->ctx->result = 1;
|
||||
btnCtx->ctx->resultCode = 1;
|
||||
}
|
||||
app_event_emit_close(btnCtx->ctx->appInstanceId);
|
||||
}
|
||||
@@ -137,22 +136,30 @@ int32_t appMain(int argc, char* argv[]) {
|
||||
check(app_event_unsubscribe(&sub) == ERROR_NONE);
|
||||
task_event_group_destruct(&event_group);
|
||||
|
||||
return ctx.result;
|
||||
if (ctx.resultCode == 0) {
|
||||
// The caller captures this via an AppStream bound to our stdout (see start()); see
|
||||
// AppStdioWrap.cpp for how printf() itself gets routed there on POSIX.
|
||||
printf("%s", ctx.resultText.c_str());
|
||||
}
|
||||
return ctx.resultCode;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
uint32_t start(uint32_t callerAppInstanceId, const std::string& title, const std::string& message, const std::string& prefilled) {
|
||||
uint32_t start(uint32_t callerAppInstanceId, const std::string& title, const std::string& message, const std::string& prefilled, AppStream& stream, void* buffer, size_t bufferCapacity, TaskEventGroup* eventGroup) {
|
||||
const char* argv[] = { title.c_str(), message.c_str(), prefilled.c_str() };
|
||||
AppStreamBinding binding = {
|
||||
.producer_fd = STDOUT_FILENO,
|
||||
.stream = &stream,
|
||||
.buffer = buffer,
|
||||
.buffer_capacity = bufferCapacity,
|
||||
.event_group = eventGroup,
|
||||
};
|
||||
uint32_t instanceId = 0;
|
||||
app_manager_start_for_result(manifest.id, callerAppInstanceId, 3, argv, &instanceId);
|
||||
app_start_for_result_with_streams(manifest.id, 3, argv, &binding, 1, callerAppInstanceId, &instanceId);
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
std::string getLastText() {
|
||||
return lastText;
|
||||
}
|
||||
|
||||
extern const ::AppManifest manifest = {
|
||||
.id = "tactility.inputdialog",
|
||||
.name = "Input Dialog",
|
||||
|
||||
Reference in New Issue
Block a user