fix: toolbar buttons clickable, add node delete

Fixes:
- SVG mousedown handler now ignores clicks outside SVG (toolbar works)
- Right-click node -> Destroy Node to delete virtual devices
- POST /api/destroy-node {node_id} endpoint (uses pw-cli destroy)

Node context menu shows node name and destroy button.
This commit is contained in:
joren
2026-03-30 00:02:53 +02:00
parent 9dc685acda
commit 444fc43c9c
2 changed files with 90 additions and 1 deletions

View File

@@ -450,6 +450,37 @@ void WebServer::setupRoutes() {
m_http.Options("/api/create-loopback", cors_handler);
m_http.Options("/api/unload-module", cors_handler);
m_http.Options("/api/load-module", cors_handler);
m_http.Options("/api/destroy-node", cors_handler);
// Destroy node: POST /api/destroy-node {"node_id":N}
m_http.Post("/api/destroy-node", [this](const httplib::Request &req, httplib::Response &res) {
uint32_t node_id = 0;
if (sscanf(req.body.c_str(), "{\"node_id\":%u}", &node_id) == 1) {
// Find the module that owns this node and unload it
// First try to destroy via registry (works for pw-cli created nodes)
auto snap = m_engine.snapshot();
bool found = false;
for (auto &n : snap.nodes) {
if (n.id == node_id) {
found = true;
break;
}
}
if (found) {
// Use pw-cli to destroy
std::string cmd = "pw-cli destroy " + std::to_string(node_id) + " 2>/dev/null";
int ret = system(cmd.c_str());
(void)ret;
sleep(1);
broadcastGraph();
}
res.set_content(found ? "{\"ok\":true}" : "{\"ok\":false,\"error\":\"node not found\"}", "application/json");
} else {
res.status = 400;
res.set_content("{\"error\":\"invalid json\"}", "application/json");
}
res.set_header("Access-Control-Allow-Origin", "*");
});
// Helper: extract a string value from simple JSON
auto extractStr = [](const std::string &body, const std::string &key) -> std::string {