#include "Tactility/app/fileselection/FileSelectionPrivate.h" #include "Tactility/app/fileselection/View.h" #include "Tactility/app/fileselection/State.h" #include "Tactility/app/AppContext.h" #include #include #include namespace tt::app::fileselection { constexpr auto* TAG = "FileSelection"; extern const AppManifest manifest; std::string getResultPath(const Bundle& bundle) { std::string result; if (bundle.optString("path", result)) { return result; } else { return ""; } } Mode getMode(const Bundle& bundle) { int32_t mode = static_cast(Mode::ExistingOrNew); bundle.optInt32("mode", mode); return static_cast(mode); } void setMode(Bundle& bundle, Mode mode) { auto mode_int = static_cast(mode); bundle.putInt32("mode", mode_int); } class FileSelection : public App { std::unique_ptr view; std::shared_ptr state; public: FileSelection() { state = std::make_shared(); view = std::make_unique(state, [this](const std::string& path) { auto bundle = std::make_unique(); bundle->putString("path", path); setResult(Result::Ok, std::move(bundle)); service::loader::stopApp(); }); } void onShow(AppContext& appContext, lv_obj_t* parent) override { auto mode = getMode(*appContext.getParameters()); view->init(parent, mode); } }; extern const AppManifest manifest = { .id = "FileSelection", .name = "File Selection", .icon = TT_ASSETS_APP_ICON_FILES, .type = Type::Hidden, .createApp = create }; LaunchId startForExistingFile() { auto bundle = std::make_shared(); setMode(*bundle, Mode::Existing); return service::loader::startApp(manifest.id, bundle); } LaunchId startForExistingOrNewFile() { auto bundle = std::make_shared(); setMode(*bundle, Mode::ExistingOrNew); return service::loader::startApp(manifest.id, bundle); } } // namespace