1
0
Fork 0
mirror of https://github.com/maziggy/bambuddy.git synced 2026-05-09 08:25:54 +02:00

[PR #953] [CLOSED] feat: plugin system with OctoPrint converter and PrettyGCode viewer #1142

Closed
opened 2026-05-07 00:16:15 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/953
Author: @Soopahfly
Created: 4/12/2026
Status: Closed

Base: devHead: feature/plugin-system


📝 Commits (1)

  • 5e49c61 feat: add plugin system with OctoPrint converter and PrettyGCode viewer

📊 Changes

40 files changed (+17571 additions, -10 deletions)

View changed files

📝 .gitignore (+6 -0)
backend/app/api/routes/plugins.py (+365 -0)
📝 backend/app/core/config.py (+2 -0)
📝 backend/app/core/database.py (+1 -0)
📝 backend/app/main.py (+51 -9)
backend/app/models/plugin.py (+22 -0)
backend/app/plugins/__init__.py (+0 -0)
backend/app/plugins/base.py (+208 -0)
backend/app/plugins/loader.py (+166 -0)
backend/app/plugins/octoprint_converter.py (+520 -0)
backend/app/plugins/registry.py (+164 -0)
📝 docker-compose.yml (+4 -0)
📝 frontend/src/App.tsx (+2 -0)
📝 frontend/src/api/client.ts (+73 -0)
📝 frontend/src/components/Layout.tsx (+2 -1)
frontend/src/components/PluginsSettings.tsx (+548 -0)
📝 frontend/src/i18n/locales/en.ts (+53 -0)
frontend/src/pages/PluginsPage.tsx (+9 -0)
plugins/.gitkeep (+0 -0)
plugins/example_plugin/__init__.py (+87 -0)

...and 20 more files

📄 Description

Description

Adds a first-class plugin system to Bambuddy, allowing users to install, enable/disable, and configure plugins — including automatic conversion of existing OctoPrint plugins.

Ships with a bundled PrettyGCode plugin as a reference implementation: a full 3D GCode viewer with layer sync and nozzle animation driven by Bambu MQTT data.

Fixes #952

Documentation

Companion docs PRs (delete lines that don't apply):

  • Wiki: to follow once issue is triaged — happy to write plugin authoring docs

Pick one:

  • Docs PR(s) linked above
  • No docs update required — reason: bundling with PR initially; will add wiki docs if maintainers want to proceed

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition or update

Changes Made

Backend (backend/app/plugins/)

  • Plugin loader — discovers Python packages in data/plugins/ on startup, registers to DB, loads enabled plugins
  • Mixins: StartupPlugin, ShutdownPlugin, EventHandlerPlugin, SettingsPlugin, AssetPlugin, SimpleApiPlugin
  • PluginRecord DB model (added via existing init_db() path, no migration required)
  • Plugin API (/api/v1/plugins) — list, upload/analyse/install, enable/disable, get/set settings, static asset serving, SimpleApiPlugin command dispatch
  • OctoPrint converter (octoprint_converter.py) — AST-based; maps supported mixins 1:1, stubs unsupported ones with comments
  • Lifecycle events wired into on_print_start, on_print_complete, archive creation, app startup/shutdown
  • docker-compose.yml./plugins:/app/data/plugins volume so plugins survive image rebuilds
  • config.pyplugins_dir setting, preserves _external_db_url from dev

Frontend

  • Plugins sidebar nav item (Package icon, /plugins route, between Notifications and Settings)
  • PluginsSettings component — plugin cards with enable toggle, inline settings editor, "Open Viewer" button for plugins with static/index.html
  • Upload modal — drag-drop .zip, detects Bambuddy vs OctoPrint, previews mixin support and generated code before confirming install

PrettyGCode plugin (plugins/prettygcode/)

  • Converted from OctoPrint-PrettyGCode (my own plugin, MIT licensed)
  • Standalone viewer at /api/v1/plugins/prettygcode/assets/index.html
  • bambuddy_adapter.js bridges OctoPrint ViewModel/Knockout API to Bambuddy WebSocket + REST
  • Layer highlight sync: GCode file is parsed when loaded (teed from the fetch() prettygcode.js already makes), building a layer_num → byte offset map; layer_num from MQTT drives filepos into prettygcode's existing syncGcodeObjToFilePos()
  • Nozzle animation: per-layer G0/G1 commands extracted during parse and fed as synthetic Send: log entries — works around Bambu not exposing GCode serial echo
  • All JS dependencies bundled locally (Three.js, dat.gui, camera-controls, jQuery, OBJLoader, LineMaterial/Line2, ExtruderNozzle model)

Screenshots

Plugins sidebar and card view:

Plugin list with PrettyGCode showing "Loaded" badge and "Open Viewer" button

PrettyGCode viewer:

3D GCode visualisation with layer highlight synced to live print progress

(Screenshots available on request — running locally against an X1C)

Testing

  • I have tested this on my local machine
  • I have tested with my printer model: X1C
  • Backend starts cleanly with no plugins installed (graceful empty-dir handling)
  • PrettyGCode plugin loads, viewer renders, layer highlight tracks print progress
  • OctoPrint plugin upload/detect/convert/install flow works end-to-end
  • Enable/disable toggle correctly sets DB state and shows restart badge
  • Plugin settings save and persist across page reloads

Checklist

  • My code follows the project's coding style
  • I have commented my code where necessary
  • My changes generate no new warnings
  • I have tested my changes thoroughly

Additional Notes

  • The plugins/prettygcode/ static JS files are third-party libs bundled from the original OctoPrint-PrettyGCode repo (MIT). Happy to exclude them and use CDN links instead if bundling large vendor files is a concern.
  • The OctoPrint converter is designed to be conservative — it only converts what it can verify, and leaves a clear # TODO comment for anything it can't safely map.
  • I acknowledge the process wasn't followed correctly on the first attempt (PRed to main without an issue). This submission is against dev with the issue linked.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/953 **Author:** [@Soopahfly](https://github.com/Soopahfly) **Created:** 4/12/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feature/plugin-system` --- ### 📝 Commits (1) - [`5e49c61`](https://github.com/maziggy/bambuddy/commit/5e49c611eca8e5e66fa64115453af85fb229a14e) feat: add plugin system with OctoPrint converter and PrettyGCode viewer ### 📊 Changes **40 files changed** (+17571 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+6 -0) ➕ `backend/app/api/routes/plugins.py` (+365 -0) 📝 `backend/app/core/config.py` (+2 -0) 📝 `backend/app/core/database.py` (+1 -0) 📝 `backend/app/main.py` (+51 -9) ➕ `backend/app/models/plugin.py` (+22 -0) ➕ `backend/app/plugins/__init__.py` (+0 -0) ➕ `backend/app/plugins/base.py` (+208 -0) ➕ `backend/app/plugins/loader.py` (+166 -0) ➕ `backend/app/plugins/octoprint_converter.py` (+520 -0) ➕ `backend/app/plugins/registry.py` (+164 -0) 📝 `docker-compose.yml` (+4 -0) 📝 `frontend/src/App.tsx` (+2 -0) 📝 `frontend/src/api/client.ts` (+73 -0) 📝 `frontend/src/components/Layout.tsx` (+2 -1) ➕ `frontend/src/components/PluginsSettings.tsx` (+548 -0) 📝 `frontend/src/i18n/locales/en.ts` (+53 -0) ➕ `frontend/src/pages/PluginsPage.tsx` (+9 -0) ➕ `plugins/.gitkeep` (+0 -0) ➕ `plugins/example_plugin/__init__.py` (+87 -0) _...and 20 more files_ </details> ### 📄 Description ## Description Adds a first-class plugin system to Bambuddy, allowing users to install, enable/disable, and configure plugins — including automatic conversion of existing OctoPrint plugins. Ships with a bundled PrettyGCode plugin as a reference implementation: a full 3D GCode viewer with layer sync and nozzle animation driven by Bambu MQTT data. ## Related Issue Fixes #952 ## Documentation **Companion docs PRs** (delete lines that don't apply): - Wiki: _to follow once issue is triaged — happy to write plugin authoring docs_ **Pick one**: - [ ] Docs PR(s) linked above - [x] No docs update required — reason: bundling with PR initially; will add wiki docs if maintainers want to proceed ## Type of Change - [ ] Bug fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test addition or update ## Changes Made **Backend (`backend/app/plugins/`)** - Plugin loader — discovers Python packages in `data/plugins/` on startup, registers to DB, loads enabled plugins - Mixins: `StartupPlugin`, `ShutdownPlugin`, `EventHandlerPlugin`, `SettingsPlugin`, `AssetPlugin`, `SimpleApiPlugin` - `PluginRecord` DB model (added via existing `init_db()` path, no migration required) - Plugin API (`/api/v1/plugins`) — list, upload/analyse/install, enable/disable, get/set settings, static asset serving, SimpleApiPlugin command dispatch - OctoPrint converter (`octoprint_converter.py`) — AST-based; maps supported mixins 1:1, stubs unsupported ones with comments - Lifecycle events wired into `on_print_start`, `on_print_complete`, archive creation, app startup/shutdown - `docker-compose.yml` — `./plugins:/app/data/plugins` volume so plugins survive image rebuilds - `config.py` — `plugins_dir` setting, preserves `_external_db_url` from dev **Frontend** - `Plugins` sidebar nav item (`Package` icon, `/plugins` route, between Notifications and Settings) - `PluginsSettings` component — plugin cards with enable toggle, inline settings editor, "Open Viewer" button for plugins with `static/index.html` - Upload modal — drag-drop `.zip`, detects Bambuddy vs OctoPrint, previews mixin support and generated code before confirming install **PrettyGCode plugin (`plugins/prettygcode/`)** - Converted from [OctoPrint-PrettyGCode](https://github.com/Soopahfly/OctoPrint-PrettyGCode) (my own plugin, MIT licensed) - Standalone viewer at `/api/v1/plugins/prettygcode/assets/index.html` - `bambuddy_adapter.js` bridges OctoPrint ViewModel/Knockout API to Bambuddy WebSocket + REST - Layer highlight sync: GCode file is parsed when loaded (teed from the fetch() prettygcode.js already makes), building a `layer_num → byte offset` map; `layer_num` from MQTT drives `filepos` into prettygcode's existing `syncGcodeObjToFilePos()` - Nozzle animation: per-layer G0/G1 commands extracted during parse and fed as synthetic `Send:` log entries — works around Bambu not exposing GCode serial echo - All JS dependencies bundled locally (Three.js, dat.gui, camera-controls, jQuery, OBJLoader, LineMaterial/Line2, ExtruderNozzle model) ## Screenshots _Plugins sidebar and card view:_ > Plugin list with PrettyGCode showing "Loaded" badge and "Open Viewer" button _PrettyGCode viewer:_ > 3D GCode visualisation with layer highlight synced to live print progress _(Screenshots available on request — running locally against an X1C)_ ## Testing - [x] I have tested this on my local machine - [x] I have tested with my printer model: X1C - Backend starts cleanly with no plugins installed (graceful empty-dir handling) - PrettyGCode plugin loads, viewer renders, layer highlight tracks print progress - OctoPrint plugin upload/detect/convert/install flow works end-to-end - Enable/disable toggle correctly sets DB state and shows restart badge - Plugin settings save and persist across page reloads ## Checklist - [x] My code follows the project's coding style - [x] I have commented my code where necessary - [x] My changes generate no new warnings - [x] I have tested my changes thoroughly ## Additional Notes - The `plugins/prettygcode/` static JS files are third-party libs bundled from the original OctoPrint-PrettyGCode repo (MIT). Happy to exclude them and use CDN links instead if bundling large vendor files is a concern. - The OctoPrint converter is designed to be conservative — it only converts what it can verify, and leaves a clear `# TODO` comment for anything it can't safely map. - I acknowledge the process wasn't followed correctly on the first attempt (PRed to `main` without an issue). This submission is against `dev` with the issue linked. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-07 00:16:15 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy-maziggy-1#1142
No description provided.