window object inaccessible from an extension context

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

window object inaccessible from an extension context

Post by TIV73 »

Hi,
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?
PetrCBR
Posts: 1763
Joined: Tue Mar 07, 2006 5:31 pm
Location: Czech
Contact:

Re: window object inaccessible from an extension context

Post by PetrCBR »

You can access main window's 'window' object using:

Code: Select all

var mainAppWindow = app.dialogs.getMainWindow()._window;
mainAppWindow.mainMenuItems .... 
How to make a debuglog - step 4b: viewtopic.php?f=30&t=86643
TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

Re: window object inaccessible from an extension context

Post 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.
Post Reply