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:
Ken Van Hoeylandt
2026-09-04 21:23:08 +02:00
committed by GitHub
parent 643cbc3806
commit a0b2ee7ebc
63 changed files with 1276 additions and 347 deletions
@@ -10,7 +10,7 @@ namespace tt::app::fileselection {
/**
* Show a file selection dialog that allows the user to select an existing file, as a modal
* child of @a callerAppInstanceId (see app_manager_start_for_result_with_streams()). Result
* child of @a callerAppInstanceId (see app_start_for_result_with_streams()). Result
* (0 = Ok, 1 = Cancelled) is delivered back via APP_EVENT_RESULT once this app's thread exits.
* On result == 0, read the picked path with app_stream_read(&stream, ...) then
* app_stream_unsubscribe(&stream); on any other result, just app_stream_unsubscribe(&stream).
@@ -1,8 +1,12 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <string>
#include <app/stream.h>
#include <tactility/concurrent/task_event_group.h>
/**
* Show a dialog with a title, a message and a text field.
*/
@@ -10,19 +14,21 @@ namespace tt::app::inputdialog {
/**
* Show a dialog with the provided title, message and prefilled text, as a modal child of
* @a callerAppInstanceId (a new-model app - see app/manager.h). The caller receives the result
* as an APP_EVENT_RESULT in its own event loop: 0 = OK (call getLastText() for the entered
* text), 1 = Cancelled or dismissed without a press. The caller is responsible for calling
* app_manager_stop() on the returned instance id once it has handled the result.
* @a callerAppInstanceId (see app_start_for_result_with_streams()). Result (0 = OK, 1 =
* Cancelled or dismissed without a press) is delivered back via APP_EVENT_RESULT once this app's
* thread exits. On result == 0, read the entered text with app_stream_read(&stream, ...) then
* app_stream_unsubscribe(&stream); on any other result, just app_stream_unsubscribe(&stream).
* The caller must call app_manager_stop() on the returned instance id once that event arrives,
* to fully reap this instance.
* @param[in,out] stream caller-owned storage bound to the started app's stdout; must stay valid
* until app_stream_unsubscribe() is called on it (see above).
* @param[in] buffer caller-owned backing storage for @a stream's ring buffer; must stay valid
* for the same duration as @a stream.
* @param[in] bufferCapacity size of @a buffer in bytes.
* @param[in] eventGroup the caller's own event group, reused for the stream's readiness bits
* (see app_stream_subscribe()). The caller isn't required to actually wait on them itself.
* @return the new dialog's app instance id
*/
uint32_t start(uint32_t callerAppInstanceId, const std::string& title, const std::string& message, const std::string& prefilled = "");
/**
* @return the text entered the last time any InputDialog instance was closed with OK. Only one
* dialog is expected to be open at a time - call this right after receiving its
* APP_EVENT_RESULT with result == 0.
*/
std::string getLastText();
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);
}
@@ -5,7 +5,7 @@
namespace tt::app::wifimanage {
/**
* Starts as a modal child of @a callerAppInstanceId (see app_manager_start_for_result()) - an
* Starts as a modal child of @a callerAppInstanceId (see app_start_for_result()) - an
* APP_EVENT_RESULT is delivered back once the user closes this screen (default Cancelled/no
* bundle if never explicitly set - callers that just want a "the wifi step is done" signal, like
* Setup, can ignore the actual result value).
+11 -1
View File
@@ -2,6 +2,9 @@
#include "./State.h"
#include <app/stream.h>
#include <tactility/concurrent/task_event_group.h>
#include <cstdint>
#include <lvgl.h>
#include <memory>
@@ -10,8 +13,12 @@ namespace tt::app::files {
class View final {
std::shared_ptr<State> state;
TaskEventGroup* eventGroup = nullptr;
uint32_t appInstanceId = 0;
AppStream inputDialogStream {};
uint8_t inputDialogBuffer[256] {};
size_t current_start_index = 0;
size_t last_loaded_index = 0;
const size_t MAX_BATCH = 50;
@@ -30,14 +37,16 @@ class View final {
void showActionsForDirectory();
void showActionsForFile();
void showActionsForMountPoint();
void addCommonFileActions();
void viewFile(const std::string&path, const std::string&filename);
void runFile(const std::string& file_path);
void createDirEntryWidget(lv_obj_t* parent, dirent& dir_entry);
void onNavigate();
public:
explicit View(const std::shared_ptr<State>& state) : state(state) {}
View(const std::shared_ptr<State>& state, TaskEventGroup* eventGroup) : state(state), eventGroup(eventGroup) {}
void init(uint32_t appInstanceId, lv_obj_t* parent);
void update(size_t start_index = 0);
@@ -54,6 +63,7 @@ public:
void onCutPressed();
void onPastePressed();
void onEjectPressed();
void onRunPressed();
void onDirEntryListScrollBegin();
void onResult(uint32_t launchId, int32_t result);
void deinit();
+2 -1
View File
@@ -26,6 +26,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/module.h>
@@ -571,7 +572,7 @@ void run(Module* const dtsModules[], const DtsDevice dtsDevices[]) {
// It's a new-model (app-module + window-manager) app now, replacing the old app::start().
app_manager_add(&app::boot::manifest);
uint32_t boot_instance_id = 0;
app_manager_start(app::boot::manifest.id, &boot_instance_id);
app_start(app::boot::manifest.id, 0, nullptr, &boot_instance_id);
LOG_I(TAG, "Main dispatcher ready");
while (true) {
@@ -2,6 +2,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -132,7 +133,7 @@ int32_t appMain(int argc, char* argv[]) {
namespace {
// Builds argv = [title, message, buttonLabels...] for app_manager_start_for_result().
// Builds argv = [title, message, buttonLabels...] for app_start_for_result().
std::vector<const char*> buildArgv(const std::string& title, const std::string& message, const std::vector<std::string>& buttonLabels) {
std::vector<const char*> argv { title.c_str(), message.c_str() };
for (const auto& label: buttonLabels) {
@@ -146,7 +147,7 @@ std::vector<const char*> buildArgv(const std::string& title, const std::string&
uint32_t start(uint32_t callerAppInstanceId, const std::string& title, const std::string& message, const std::vector<std::string>& buttonLabels) {
auto argv = buildArgv(title, message, buttonLabels);
uint32_t instanceId = 0;
app_manager_start_for_result(manifest.id, callerAppInstanceId, static_cast<int>(argv.size()), argv.data(), &instanceId);
app_start_for_result(manifest.id, static_cast<int>(argv.size()), argv.data(), callerAppInstanceId, &instanceId);
return instanceId;
}
@@ -1,5 +1,6 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/install.h>
#include <app/scheduler.h>
@@ -158,7 +159,7 @@ int32_t appMain(int argc, char* argv[]) {
void start(const std::string& appId) {
const char* argv[] = { appId.c_str() };
uint32_t instanceId = 0;
app_manager_start_with_parameters(manifest.id, 1, argv, &instanceId);
app_start(manifest.id, 1, argv, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -9,6 +9,7 @@
#include <app/install.h>
#include <app/metadata.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -351,7 +352,7 @@ void start(const apphub::AppHubEntry& entry) {
argv.push_back(platform.c_str());
}
uint32_t instanceId = 0;
app_manager_start_for_result(manifest.id, /*parent_instance_id=*/0, static_cast<int>(argv.size()), argv.data(), &instanceId);
app_start_for_result(manifest.id, static_cast<int>(argv.size()), argv.data(), /*parent_instance_id=*/0, &instanceId);
}
extern const ::AppManifest manifest = {
+2 -1
View File
@@ -1,5 +1,6 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -28,7 +29,7 @@ void onAppPressed(lv_event_t* e) {
// Fire-and-forget top-level navigation, same as Launcher's own app-launch buttons.
const auto* manifest = static_cast<const ::AppManifest*>(lv_event_get_user_data(e));
uint32_t instanceId = 0;
app_manager_start(manifest->id, &instanceId);
app_start(manifest->id, 0, nullptr, &instanceId);
}
void onBackPressed(lv_event_t* event) {
+3 -2
View File
@@ -10,6 +10,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -251,7 +252,7 @@ void startNextApp() {
auto launcher_app_id = getLauncherAppId();
uint32_t launcher_instance_id = 0;
app_manager_start(launcher_app_id.c_str(), &launcher_instance_id);
app_start(launcher_app_id.c_str(), 0, nullptr, &launcher_instance_id);
}
void runBootSequence(TickType_t startTime) {
@@ -318,7 +319,7 @@ int32_t appMain(int argc, char* argv[]) {
runBootSequence(start_time);
// Waits until app_manager_start(launcher) (or a permanent stop) tells us to give up -
// Waits until app_start(launcher) (or a permanent stop) tells us to give up -
// startNextApp() above is what triggers that, via app-module's "save the previously active
// app" policy, unless sdCardMissing halted before it.
while (true) {
+2 -1
View File
@@ -5,6 +5,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -236,7 +237,7 @@ int32_t appMain(int argc, char* argv[]) {
uint32_t start() {
uint32_t instanceId = 0;
app_manager_start(manifest.id, &instanceId);
app_start(manifest.id, 0, nullptr, &instanceId);
return instanceId;
}
@@ -10,6 +10,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -262,7 +263,7 @@ int32_t appMain(int argc, char* argv[]) {
void start(const std::string& addrHex) {
const char* argv[] = { addrHex.c_str() };
uint32_t instanceId = 0;
app_manager_start_with_parameters(manifest.id, 1, argv, &instanceId);
app_start(manifest.id, 1, argv, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -11,6 +11,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -272,7 +273,7 @@ int32_t appMain(int argc, char* argv[]) {
void start() {
uint32_t instanceId = 0;
app_manager_start(manifest.id, &instanceId);
app_start(manifest.id, 0, nullptr, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -9,6 +9,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -184,7 +185,7 @@ int32_t appMain(int argc, char* argv[]) {
if (lvgl_is_running()) {
lvgl_lock();
// Widgets only exist while this window is topmost - skip otherwise. Another app
// (started non-modally, e.g. via app_manager_start()) can bury this window without
// (started non-modally, e.g. via app_start()) can bury this window without
// stopping this instance or notifying it; window_manager deletes a buried window's
// widgets, so touching ctx->statusLabel here would use-after-free it.
if (window_manager_get_state(window) == WINDOW_STATE_GRANTED) {
+3 -2
View File
@@ -31,12 +31,13 @@ void createWidgets(lv_obj_t* parent, void* userData) {
int32_t appMain(int argc, char* argv[]) {
uint32_t appInstanceId = app_scheduler_current_app_id();
auto state = std::make_shared<State>();
View view(state);
CreateContext createContext { &view, appInstanceId };
TaskEventGroup event_group {};
task_event_group_construct(&event_group);
View view(state, &event_group);
CreateContext createContext { &view, appInstanceId };
AppEventSubscription sub {};
check(app_event_subscribe(&sub, &event_group) == ERROR_NONE);
+75 -12
View File
@@ -1,5 +1,7 @@
#include <app/install.h>
#include <app/event.h>
#include <app/execute.h>
#include <app/install.h>
#include <app/stream.h>
#include <lvgl/lvgl.h>
#include <lvgl/widgets/toolbar.h>
@@ -102,10 +104,20 @@ static void onPastePressedCallback(lv_event_t* event) {
view->onPastePressed();
}
static void onRunPressedCallback(lv_event_t* event) {
auto* view = static_cast<View*>(lv_event_get_user_data(event));
view->onRunPressed();
}
// endregion
// region File helpers
static bool isExecutablePath(const std::string& path) {
AppLocation location { APP_LOCATION_PATH, const_cast<char*>(path.c_str()) };
return app_is_executable(location);
}
static bool copyFileContents(const std::string& src, const std::string& dst) {
FILE* in = fopen(src.c_str(), "rb");
if (in == nullptr) {
@@ -192,6 +204,8 @@ void View::viewFile(const std::string& path, const std::string& filename) {
// Remove forward slash, because we need a relative path
notes::start(file_path.substr(1));
}
} else if (isExecutablePath(file_path)) {
runFile(file_path);
} else {
LOG_W(TAG, "Opening files of this type is not supported");
}
@@ -199,6 +213,23 @@ void View::viewFile(const std::string& path, const std::string& filename) {
onNavigate();
}
void View::runFile(const std::string& file_path) {
LOG_I(TAG, "Running %s", file_path.c_str());
if (!isExecutablePath(file_path)) {
LOG_W(TAG, "Not executable: %s", file_path.c_str());
alertdialog::start(appInstanceId, "Run failed", "Could not run \"" + file::getLastPathSegment(file_path) + "\".");
return;
}
AppLocation location { APP_LOCATION_PATH, const_cast<char*>(file_path.c_str()) };
AppInstanceId instance_id = 0;
if (app_execute(location, AppStackConfig {}, 0, nullptr, &instance_id) != ERROR_NONE) {
LOG_W(TAG, "Failed to run %s", file_path.c_str());
alertdialog::start(appInstanceId, "Run failed", "Could not run \"" + file::getLastPathSegment(file_path) + "\".");
}
}
bool View::resolveDirentFromListIndex(int32_t list_index, dirent& out_entry) {
const bool is_root = (state->getCurrentPath() == "/");
const bool has_back = (!is_root && current_start_index > 0);
@@ -287,6 +318,8 @@ void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) {
symbol = LV_SYMBOL_IMAGE;
} else if (dir_entry.d_type == file::TT_DT_LNK) {
symbol = LV_SYMBOL_LOOP;
} else if (isExecutablePath(file::getChildPath(state->getCurrentPath(), dir_entry.d_name))) {
symbol = LV_SYMBOL_PLAY;
} else {
symbol = LV_SYMBOL_FILE;
}
@@ -346,7 +379,7 @@ void View::onRenamePressed() {
std::string entry_name = state->getSelectedChildEntry();
LOG_I(TAG, "Pending rename %s", entry_name.c_str());
state->setPendingAction(State::ActionRename);
inputdialog::start(appInstanceId, "Rename", "", entry_name);
inputdialog::start(appInstanceId, "Rename", "", entry_name, inputDialogStream, inputDialogBuffer, sizeof(inputDialogBuffer), eventGroup);
}
void View::onDeletePressed() {
@@ -361,18 +394,16 @@ void View::onDeletePressed() {
void View::onNewFilePressed() {
LOG_I(TAG, "Creating new file");
state->setPendingAction(State::ActionCreateFile);
inputdialog::start(appInstanceId, "New File", "Enter filename:", "");
inputdialog::start(appInstanceId, "New File", "Enter filename:", "", inputDialogStream, inputDialogBuffer, sizeof(inputDialogBuffer), eventGroup);
}
void View::onNewFolderPressed() {
LOG_I(TAG, "Creating new folder");
state->setPendingAction(State::ActionCreateFolder);
inputdialog::start(appInstanceId, "New Folder", "Enter folder name:", "");
inputdialog::start(appInstanceId, "New Folder", "Enter folder name:", "", inputDialogStream, inputDialogBuffer, sizeof(inputDialogBuffer), eventGroup);
}
void View::showActions() {
lv_obj_clean(action_list);
void View::addCommonFileActions() {
auto* copy_button = lv_list_add_button(action_list, LV_SYMBOL_COPY, "Copy");
lv_obj_add_event_cb(copy_button, onCopyPressedCallback, LV_EVENT_SHORT_CLICKED, this);
auto* cut_button = lv_list_add_button(action_list, LV_SYMBOL_CUT, "Cut");
@@ -381,12 +412,27 @@ void View::showActions() {
lv_obj_add_event_cb(rename_button, onRenamePressedCallback, LV_EVENT_SHORT_CLICKED, this);
auto* delete_button = lv_list_add_button(action_list, LV_SYMBOL_TRASH, "Delete");
lv_obj_add_event_cb(delete_button, onDeletePressedCallback, LV_EVENT_SHORT_CLICKED, this);
}
void View::showActions() {
lv_obj_clean(action_list);
addCommonFileActions();
lv_obj_remove_flag(action_list, LV_OBJ_FLAG_HIDDEN);
}
void View::showActionsForDirectory() { showActions(); }
void View::showActionsForFile() { showActions(); }
void View::showActionsForFile() {
lv_obj_clean(action_list);
if (isExecutablePath(state->getSelectedChildPath())) {
auto* run_button = lv_list_add_button(action_list, LV_SYMBOL_PLAY, "Run");
lv_obj_add_event_cb(run_button, onRunPressedCallback, LV_EVENT_SHORT_CLICKED, this);
}
addCommonFileActions();
lv_obj_remove_flag(action_list, LV_OBJ_FLAG_HIDDEN);
}
void View::showActionsForMountPoint() {
lv_obj_clean(action_list);
@@ -397,6 +443,12 @@ void View::showActionsForMountPoint() {
lv_obj_remove_flag(action_list, LV_OBJ_FLAG_HIDDEN);
}
void View::onRunPressed() {
std::string file_path = state->getSelectedChildPath();
onNavigate();
runFile(file_path);
}
void View::onEjectPressed() {
std::string mount_path = state->getSelectedChildPath();
LOG_I(TAG, "Ejecting %s", mount_path.c_str());
@@ -546,10 +598,21 @@ void View::onResult(uint32_t launchId, int32_t result) {
std::string filepath = state->getSelectedChildPath();
LOG_I(TAG, "Result for %s", filepath.c_str());
// Text-entry result (rename/new file/new folder); empty for Cancel, or for a dialog that
// doesn't produce text (delete/paste confirmations) - those switch cases below only look at
// `result`, not this.
std::string resultText = (result == 0) ? inputdialog::getLastText() : std::string();
// Text-entry result (rename/new file/new folder), read from the AppStream bound to that
// dialog's stdout. Empty for Cancel. Other pending actions (delete/paste confirmations) never
// bound this stream; their switch cases below only look at `result`, not `resultText`.
bool isTextEntryAction = state->getPendingAction() == State::ActionRename ||
state->getPendingAction() == State::ActionCreateFile ||
state->getPendingAction() == State::ActionCreateFolder;
std::string resultText;
if (isTextEntryAction) {
if (result == 0) {
char buffer[sizeof(inputDialogBuffer)];
size_t length = app_stream_read(&inputDialogStream, buffer, sizeof(buffer));
resultText = std::string(buffer, length);
}
app_stream_unsubscribe(&inputDialogStream);
}
switch (state->getPendingAction()) {
case State::ActionDelete: {
@@ -6,6 +6,7 @@
#include <app/event.h>
#include <app/io.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
#include <app/stream.h>
@@ -106,7 +107,7 @@ uint32_t startWithMode(const char* modeArg, uint32_t callerAppInstanceId, AppStr
.event_group = eventGroup,
};
uint32_t instanceId = 0;
app_manager_start_for_result_with_streams(manifest.id, callerAppInstanceId, 1, argv, &binding, 1, &instanceId);
app_start_for_result_with_streams(manifest.id, 1, argv, &binding, 1, callerAppInstanceId, &instanceId);
return instanceId;
}
@@ -8,6 +8,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -73,7 +74,7 @@ void onAddGpsPressed(lv_event_t* event) {
// this app; rebuildDeviceList() runs fresh whenever this app is resumed regardless).
(void)ctx;
uint32_t instanceId = 0;
app_manager_start(addgps::manifest.id, &instanceId);
app_start(addgps::manifest.id, 0, nullptr, &instanceId);
}
void onDeviceButtonPressed(lv_event_t* event) {
@@ -7,6 +7,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/paths.h>
#include <app/scheduler.h>
@@ -430,7 +431,7 @@ extern const ::AppManifest manifest = {
uint32_t start() {
uint32_t instanceId = 0;
app_manager_start(manifest.id, &instanceId);
app_start(manifest.id, 0, nullptr, &instanceId);
return instanceId;
}
@@ -6,6 +6,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -123,7 +124,7 @@ int32_t appMain(int argc, char* argv[]) {
void start(const std::string& file) {
const char* argv[] = { file.c_str() };
uint32_t instanceId = 0;
app_manager_start_with_parameters(manifest.id, 1, argv, &instanceId);
app_start(manifest.id, 1, argv, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -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",
+5 -4
View File
@@ -1,5 +1,6 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -45,7 +46,7 @@ int32_t computeButtonMargin(int32_t available_span, int32_t total_button_size) {
void onAppPressed(lv_event_t* e) {
auto* appId = static_cast<const char*>(lv_event_get_user_data(e));
uint32_t instance_id = 0;
app_manager_start(appId, &instance_id);
app_start(appId, 0, nullptr, &instance_id);
}
lv_obj_t* createAppButton(lv_obj_t* parent, UiDensity uiDensity, const char* imageFile, const char* appId, int32_t itemMargin, bool isLandscape) {
@@ -214,7 +215,7 @@ void runAutoStart() {
) {
LOG_I(TAG, "Starting %s", CONFIG_TT_AUTO_START_APP_ID);
uint32_t app_launch_id;
app_manager_start(CONFIG_TT_AUTO_START_APP_ID, &app_launch_id);
app_start(CONFIG_TT_AUTO_START_APP_ID, 0, nullptr, &app_launch_id);
} else if (
// Auto-start due to user configuration
settings::loadBootSettings(boot_properties) &&
@@ -223,7 +224,7 @@ void runAutoStart() {
) {
LOG_I(TAG, "Starting %s", boot_properties.autoStartAppId.c_str());
uint32_t app_launch_id;
app_manager_start(boot_properties.autoStartAppId.c_str(), &app_launch_id);
app_start(boot_properties.autoStartAppId.c_str(), 0, nullptr, &app_launch_id);
} else {
// No auto-start, consider running system setup
if (!setup::isCompleted()) {
@@ -282,7 +283,7 @@ extern const ::AppManifest manifest = {
// used by the old, unconverted CrashDiagnostics app to return to the launcher after a crash).
uint32_t start() {
uint32_t instance_id = 0;
app_manager_start(manifest.id, &instance_id);
app_start(manifest.id, 0, nullptr, &instance_id);
return instance_id;
}
+2 -1
View File
@@ -7,6 +7,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
#include <app/stream.h>
@@ -268,7 +269,7 @@ int32_t appMain(int argc, char* argv[]) {
void start(const std::string& filePath) {
const char* argv[] = { filePath.c_str() };
uint32_t instanceId = 0;
app_manager_start_with_parameters(manifest.id, 1, argv, &instanceId);
app_start(manifest.id, 1, argv, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -2,6 +2,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -133,7 +134,7 @@ int32_t appMain(int argc, char* argv[]) {
namespace {
// Builds argv = [title, items...] for app_manager_start_for_result().
// Builds argv = [title, items...] for app_start_for_result().
std::vector<const char*> buildArgv(const std::string& title, const std::vector<std::string>& items) {
std::vector<const char*> argv { title.c_str() };
for (const auto& item: items) {
@@ -147,7 +148,7 @@ std::vector<const char*> buildArgv(const std::string& title, const std::vector<s
AppInstanceId start(AppInstanceId callerAppInstanceId, const std::string& title, const std::vector<std::string>& items) {
auto argv = buildArgv(title, items);
AppInstanceId instanceId = 0;
app_manager_start_for_result(manifest.id, callerAppInstanceId, static_cast<int>(argv.size()), argv.data(), &instanceId);
app_start_for_result(manifest.id, static_cast<int>(argv.size()), argv.data(), callerAppInstanceId, &instanceId);
return instanceId;
}
+2 -1
View File
@@ -1,5 +1,6 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -28,7 +29,7 @@ void onAppPressed(lv_event_t* e) {
// Fire-and-forget top-level navigation, same as AppList's own app-launch buttons.
const auto* manifest = static_cast<const ::AppManifest*>(lv_event_get_user_data(e));
uint32_t instanceId = 0;
app_manager_start(manifest->id, &instanceId);
app_start(manifest->id, 0, nullptr, &instanceId);
}
void onBackPressed(lv_event_t* event) {
+2 -1
View File
@@ -10,6 +10,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -269,7 +270,7 @@ int32_t appMain(int argc, char* argv[]) {
void start() {
uint32_t instanceId = 0;
app_manager_start(manifest.id, &instanceId);
app_start(manifest.id, 0, nullptr, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -5,6 +5,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -206,7 +207,7 @@ int32_t appMain(int argc, char* argv[]) {
uint32_t start() {
uint32_t instanceId = 0;
app_manager_start(manifest.id, &instanceId);
app_start(manifest.id, 0, nullptr, &instanceId);
return instanceId;
}
+2 -1
View File
@@ -8,6 +8,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -273,7 +274,7 @@ int32_t appMain(int argc, char* argv[]) {
uint32_t start(uint32_t callerAppInstanceId, bool saveTimeZone) {
const char* argv[] = { saveTimeZone ? "1" : "0" };
uint32_t instanceId = 0;
app_manager_start_for_result(manifest.id, callerAppInstanceId, 1, argv, &instanceId);
app_start_for_result(manifest.id, 1, argv, callerAppInstanceId, &instanceId);
return instanceId;
}
@@ -7,6 +7,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -285,7 +286,7 @@ int32_t appMain(int argc, char* argv[]) {
uint32_t start(uint32_t callerAppInstanceId) {
uint32_t instanceId = 0;
app_manager_start_for_result(manifest.id, callerAppInstanceId, 0, nullptr, &instanceId);
app_start_for_result(manifest.id, 0, nullptr, callerAppInstanceId, &instanceId);
return instanceId;
}
@@ -5,6 +5,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -317,7 +318,7 @@ int32_t appMain(int argc, char* argv[]) {
void start(const std::string& ssid) {
const char* argv[] = { ssid.c_str() };
uint32_t instanceId = 0;
app_manager_start_with_parameters(manifest.id, 1, argv, &instanceId);
app_start(manifest.id, 1, argv, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -6,6 +6,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -377,7 +378,7 @@ int32_t appMain(int argc, char* argv[]) {
void start(const std::string& ssid, const std::string& password) {
const char* argv[] = { ssid.c_str(), password.c_str() };
uint32_t instanceId = 0;
app_manager_start_with_parameters(manifest.id, 2, argv, &instanceId);
app_start(manifest.id, 2, argv, &instanceId);
}
extern const ::AppManifest manifest = {
@@ -6,6 +6,7 @@
#include <app/event.h>
#include <app/manager.h>
#include <app/start.h>
#include <app/manifest.h>
#include <app/scheduler.h>
@@ -240,7 +241,7 @@ int32_t appMain(int argc, char* argv[]) {
uint32_t start(uint32_t callerAppInstanceId) {
uint32_t instanceId = 0;
app_manager_start_for_result(manifest.id, callerAppInstanceId, 0, nullptr, &instanceId);
app_start_for_result(manifest.id, 0, nullptr, callerAppInstanceId, &instanceId);
return instanceId;
}
@@ -2,6 +2,7 @@
#include <app/install.h>
#include <app/manager.h>
#include <app/start.h>
#include <tactility/log.h>
@@ -113,7 +114,7 @@ esp_err_t DevelopmentService::handleAppRun(httpd_req_t* request) {
}
}
app_manager_start(id_key_pos->second.c_str(), &instance_id);
app_start(id_key_pos->second.c_str(), 0, nullptr, &instance_id);
LOG_I(TAG, "[200] /app/run %s", id_key_pos->second.c_str());
httpd_resp_send(request, nullptr, 0);
@@ -2,6 +2,8 @@
#include <Tactility/service/webserver/WebServerService.h>
#include <Tactility/service/ServiceManifest.h>
#include <app/start.h>
#include <Tactility/settings/WebServerSettings.h>
#include <Tactility/MountPoints.h>
#include <Tactility/file/File.h>
@@ -1270,7 +1272,7 @@ esp_err_t WebServerService::handleApiAppsRun(httpd_req_t* request) {
// Every app instance gets its own task now, so there's no "stop the existing one first" -
// this just starts a fresh instance alongside whatever's already running.
AppInstanceId instance_id = 0;
app_manager_start(appId.c_str(), &instance_id);
app_start(appId.c_str(), 0, nullptr, &instance_id);
LOG_I(TAG, "[200] /api/apps/run %s", appId.c_str());
httpd_resp_sendstr(request, "ok");