13static const char*
TAG =
"PLG_UI";
76 const char* label =
"Start failed";
89 std::snprintf(msg,
sizeof(msg),
"%s\nErr %d", label,
static_cast<int>(result));
114 list_.setOnSelect(&PluginListView::onSelectStatic);
115 list_.setOnMenu (&PluginListView::onMenuStatic);
139 list_.render(partial);
144 return list_.onKey(key);
158void PluginListView::rebuildItems()
161 ids_ = mgr.listInstalledIds();
164 labels_.reserve(ids_.size());
165 items_.reserve(ids_.size());
167 for (
const auto&
id : ids_) {
168 std::string display = id;
170 auto it = mf->i18n_meta.find(
"name");
171 if (it != mf->i18n_meta.end() && !it->second.by_lang.empty()) {
172 auto def = it->second.by_lang.find(mf->default_language);
173 if (def != it->second.by_lang.end()) {
174 display = def->second;
176 display = it->second.by_lang.begin()->second;
180 labels_.push_back(std::move(display));
184 const bool running = mgr.isRunningInBackground(
id) ||
185 (mgr.activePluginIsBackground() && mgr.activePluginId() ==
id);
186 const bool disabled = mgr.isPluginDisabled(
id);
188 const uint8_t icon = disabled ?
static_cast<uint8_t
>(
'X')
190 items_.push_back(cdc::ui::ListItem{labels_.back().c_str(), icon,
false,
nullptr});
193 list_.init(
"Plugins", items_.data(),
static_cast<uint16_t
>(items_.size()));
194 list_.setEmptyText(
"No plugins installed");
195 list_.setHint(
cdc::ui::tr(
"core.hint_plugin_list"));
198void PluginListView::onSelectStatic(uint16_t index,
void*)
203void PluginListView::onMenuStatic(uint16_t index,
void*)
208void PluginListView::onSelect(uint16_t index)
210 if (index >= ids_.size())
return;
211 const auto&
id = ids_[index];
212 LOG_I(
TAG,
"start plugin %s",
id.c_str());
217void PluginListView::onMenu(uint16_t index)
219 if (index >= ids_.size())
return;
223 const bool running = mgr.isRunningInBackground(
s_ctxPluginId) ||
224 (mgr.activePluginIsBackground() && mgr.activePluginId() ==
s_ctxPluginId);
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)
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[2]
static std::string s_ctxPluginId
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 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.