3DCoded / DynamicMacros

Never restart Klipper again for simple macros.
https://3dcoded.github.io/DynamicMacros/
GNU General Public License v3.0
26 stars 3 forks source link

[Bug]: Fluidd won't show any macros after installing DynamicMacros #5

Closed AlejandroRivera closed 3 days ago

AlejandroRivera commented 2 months ago

What happened?

After installing DynamicMacros, the list of Macros that Fluidd used to display has disappeared.

Fluidd: v1.30.3 (latest) DynamicMacros: v1.2-0-g6d8b1c47

Before: image

After: image

printer.cfg:

[...]  # All my normal config

# The very last entry in the file
[dynamicmacros]
configs = my_dynamic_macros.cfg

Fluidd console logs:

index-DQH5Kcko.js:19 error TypeError: Cannot read properties of undefined (reading 'description')
    at index-DQH5Kcko.js:147:30934
    at o.zA [as _l] (index-DQH5Kcko.js:6:16356)
    at index-DQH5Kcko.js:147:30839
    at o.zA [as _l] (index-DQH5Kcko.js:6:16356)
    at o.nte (index-DQH5Kcko.js:147:30232)
    at r._render (index-DQH5Kcko.js:6:22130)
    at o.s (index-DQH5Kcko.js:6:32156)
    at r.get (index-DQH5Kcko.js:6:28348)
    at r (index-DQH5Kcko.js:6:28265)
    at WE (index-DQH5Kcko.js:6:32249)

(ps. I'm not 99% sure this log is related to this issue since it's all obfuscated, but this error message appears when there are gcode_macros defined in the file referenced by the configs para inside the [dynamicmacros] section. If there are no dynamic macros being loaded at all, things work as per usual.

My guess is that the dynamic macro object isn't registering some attribute correctly which the Fluidd UI expects, and this breaks things in the UI.

Klippy Log

(Nothing useful found in Klippy.log)

[dynamicmacros]
configs = nozzle_dynamic_macros.cfg

[...]
DynamicMacros: Reading section gcode_macro WIPE_NOZZLE
Extruder max_extrude_ratio=2.078758
mcu 'mcu': Starting serial connect
[...]
AlejandroRivera commented 2 months ago

As a workaround, I've discovered that if you define a [gcode_macro NAME] outside of the dynamic macros file, and inside the [gcode_macro NAME] of the dynamic macros file you define rename_existing: BASE_NAME, things work as expected again.

Example:

in my_normal_macros.cfg

[gcode_macro HELLO]
gcode:
   # Do nothing as this will be replaced by a dynamic macro 

in my_dynamic_macros.cfg

[gcode_macro HELLO]
rename_existing: BASE_HELLO
gcode:
   M117 Hello world
3DCoded commented 2 months ago

Thank you for finding this bug. I was able to reproduce this issue in Fluidd, however Mainsail works fine.

Screenshot 2024-09-04 at 6 54 22 AM

Since this works with Mainsail, I would say this is an unexpected bug with Fluidd. I'll keep this issue open, but I'll add your workaround to the documentation with a note about using Mainsail vs Fluidd.

fritzw commented 2 weeks ago

I'd like to note that dynamic macros also don't show up in the KlipperScreen macro list, though normal macros do show up. Maybe this is related, but I'm not sure exactly where KlipperScreen gets its macro list from.

My current workaround is to call my dynamic macros _MACRO_NAME, and then have MACRO_NAME as a normal gcode_macro section in printer.cfg, which just expands to _MACRO_NAME (and forwards all arguments).

3DCoded commented 2 weeks ago

I'm currently working on a way to automatically perform that workaround, where each dynamic macro has a standard "dummy" macro that silently calls the dynamic macro.

3DCoded commented 2 weeks ago

@AlejandroRivera @fritzw

I've added an experimental automatic workaround for this issue and am looking for testers. To install it:

cd ~/DynamicMacros
git fetch
git checkout dev
git pull
sh install.sh
sudo service klipper restart

In your [dynamicmacros] config section, add this line:

interface_workaround: true

After this, restart Klipper, wait for it to start, then restart it again.

This should automatically create a hidden .dynamicmacros.cfg file (note the . in front of the name) and include it in your printer.cfg.

Let me know if this works on your setups.