Page 1 of 1

window object inaccessible from an extension context

Posted: Sat Jun 15, 2019 11:14 am
by TIV73
it seems like the (supposedly) global window object is not available fron the config menu of an addon. Well, a window object is available, but it's not the same object as the one from the main player.

To verify, open the config menu of an application via Tools > Extensions. Inside the config menu, add a property to the window object or change an existing value. Close the config panel and check the changed/added properties of window, they will be back to their original value (or rather, the original values were never changed in the first place).

To add some background, I have an extension which collects actions from other extensions and adds a new main menu item with them. To do that, I create the menu and push it to window.mainMenuItems. There is a config panel where it's possible to reorder, hide, etc. items in the menu.
If the OK button on the config panel is clicked, all changes are processed and the main menu item is updated - only that this refresh never actually reaches the 'real main menu' because the config panel has its own window object.
The changes are persisted with app.setValue, but due to the separated context I have no way of telling the main window object to reload the settings or otherwise trigger a refresh.

I realize that there are options like refreshing the main menu item everytime it's clicked or periodically checking for changes - but that seems more like a workaround than a real solution. Plus, it would add additional overhead for something trivial as opening a menu item.

Is there a (proper) way to do what I'm trying to do?

Re: window object inaccessible from an extension context

Posted: Thu Jun 20, 2019 3:38 pm
by PetrCBR
You can access main window's 'window' object using:

Code: Select all

var mainAppWindow = app.dialogs.getMainWindow()._window;
mainAppWindow.mainMenuItems .... 

Re: window object inaccessible from an extension context

Posted: Fri Jun 21, 2019 3:45 pm
by TIV73
Holy cow, that worked! Thanks a lot, that was literally the last (known) bug I wanted to get rid of in the extension for the current version.