14static const char*
TAG =
"PLG_UI";
77 const char* label =
"Start failed";
90 std::snprintf(msg,
sizeof(msg),
"%s\nErr %d", label,
static_cast<int>(result));
131 static std::string body;
145 list_.setOnSelect(&PluginListView::onSelectStatic);
146 list_.setOnMenu (&PluginListView::onMenuStatic);
170 list_.render(partial);
175 return list_.onKey(key);
189void PluginListView::rebuildItems()
192 ids_ = mgr.listInstalledIds();
195 labels_.reserve(ids_.size());
196 items_.reserve(ids_.size());
198 for (
const auto&
id : ids_) {
199 std::string display = id;
201 auto it = mf->i18n_meta.find(
"name");
202 if (it != mf->i18n_meta.end() && !it->second.by_lang.empty()) {
203 auto def = it->second.by_lang.find(mf->default_language);
204 if (def != it->second.by_lang.end()) {
205 display = def->second;
207 display = it->second.by_lang.begin()->second;
211 labels_.push_back(std::move(display));
215 const bool running = mgr.isRunningInBackground(
id) ||
216 (mgr.activePluginIsBackground() && mgr.activePluginId() ==
id);
217 const bool disabled = mgr.isPluginDisabled(
id);
219 const uint8_t icon = disabled ?
static_cast<uint8_t
>(
'X')
221 items_.push_back(cdc::ui::ListItem{labels_.back().c_str(), icon,
false,
nullptr});
224 list_.init(
"Plugins", items_.data(),
static_cast<uint16_t
>(items_.size()));
225 list_.setEmptyText(
"No plugins installed");
226 list_.setHint(
cdc::ui::tr(
"core.hint_plugin_list"));
229void PluginListView::onSelectStatic(uint16_t index,
void*)
234void PluginListView::onMenuStatic(uint16_t index,
void*)
239void PluginListView::onSelect(uint16_t index)
241 if (index >= ids_.size())
return;
242 const auto&
id = ids_[index];
243 LOG_I(
TAG,
"start plugin %s",
id.c_str());
248void PluginListView::onMenu(uint16_t index)
250 if (index >= ids_.size())
return;
254 const bool running = mgr.isRunningInBackground(
s_ctxPluginId) ||
255 (mgr.activePluginIsBackground() && mgr.activePluginId() ==
s_ctxPluginId);
261 const bool inBackground = mgr.isRunningInBackground(
s_ctxPluginId);
270 }
else if (running) {
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
Main-menu entry "Plugins" - lists all installed WASM plugins.
Discovers, loads, runs and unloads WASM plugins on the badge.
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_I(tag, fmt,...)
static PluginListView * active() noexcept
Currently-mounted PluginListView instance, or nullptr if none.
const char * getFooterHint() const override
void onEnter(void *context=nullptr) override
void render(bool partial) override
cdc::ui::InputResult onKey(char key) override
void requestStopActivePlugin()
static PluginManager & instance() noexcept
bool unloadFromRam(const std::string &id)
bool uninstallPlugin(const std::string &id)
CDC Badge OS plugin host API - canonical C ABI contract.
static void onCtxDisable()
Context-menu Disable callback: persistently disables and unloads.
static void onCtxEnable()
Context-menu Enable callback: removes the persistent disabled marker.
static void onCtxStart()
Context-menu Start callback: starts the selected (stopped) plugin.
static PluginListView * s_active
static cdc::ui::ContextMenuItem s_ctxItems[3]
static void onUninstallConfirmed(void *)
Confirm callback for uninstall: deletes the plugin and refreshes.
static std::string s_ctxPluginId
static void onCtxUninstall()
Context-menu Uninstall callback: asks for confirmation, then deletes.
static void reportStartResult(StartResult result)
Show a toast describing a non-Ok plugin start result.
static void onCtxStop()
Context-menu Stop callback: force-unloads the selected plugin.
const char * tr(const char *key)
Look up a translation by string key.
void showConfirm(const char *message, ConfirmView::ConfirmCallback onConfirm, ConfirmView::CancelCallback onCancel=nullptr, ConfirmView::Icon icon=ConfirmView::Icon::QUESTION, void *userData=nullptr)
Shows a shared modal confirmation dialog instance.
void hideContextMenu()
Hides the active context menu modal.
ContextMenuView * showContextMenu(const char *title, const ContextMenuItem *items, uint8_t count)
Shows the shared context menu instance as modal.
void showToastInfo(const char *message, uint16_t durationMs=1500)
Shows an informational toast message.
void showToastError(const char *message, uint16_t durationMs=1500)
Shows an error toast message.