TheQwertiest / foo_spider_monkey_panel

foobar2000 component that allows to use JavaScript to create CUI/DUI panels
https://theqwertiest.github.io/foo_spider_monkey_panel/
MIT License
274 stars 21 forks source link

on_script_unload() and property saving bug #205

Open regorxxx opened 1 year ago

regorxxx commented 1 year ago

on_script_unload() when foobar is closed (without errors) is behaving badly.

I have a code to save a property on script unload and it works fine on panel reload, but it doesn't work when closing foobar.

  1. If you add this code to a new panel and immediately close foobar, after restarting the properties panel is empty. (*)
    
    const p = ['name', 'value'];

function on_script_unload(){ window.SetProperty(p[0],p[1]); }


2. On the other hand, if you simply add the code and reload the panel. It's added fine.

(*) Note you can not do this after panel reload, since cleaning the properties reloads the script again and adds the properties (being equivalent to 2).
marc2k3 commented 1 year ago

JSP3 has this issue too but there isn't anything that can be done (other than clarifying in the docs).

Code inside the callback definitely runs because I tested writing an external text file which works.

The issue here is that that fb2k itself is writing the panel configuration to theme.fth (DUI) or foo_ui_columns.dll.cfg (CUI) before we get notified that it is shutting down. Any subsequent changes made by window.SetProperty are lost in the ether.

Component authors control what is written to layout files but not when.

regorxxx commented 1 year ago

Yep, found the same logging to a file. The properties are properly written to the panel within the callback (GetProperty gets the updated value) but not saved to the config file.

A warning should be added then to be cautious about what code is run there.

marc2k3 commented 1 year ago

I've added a note to my own docs...

https://jscript-panel.github.io/docs/callbacks/#on_script_unload