View Issue Details

IDProjectCategoryView StatusLast Update
0018997MMW 5Extensions frameworkpublic2022-08-31 16:12
Reporterzvezdan Assigned To 
PriorityurgentSeverityminorReproducibilityN/A
Status closedResolutionno change required 
Product Version5.0.3 
Target Version5.0.3 
Summary0018997: Method to add menu item to the context menus of all displayed tracklists needed
DescriptionWe need a simple way to add menu items to the context menus of all displayed tracklists including Playing. They need to be added during run-time, after the addon was already loaded, i.e. without using trackListView_add.js. It was trivial to do that in MM4.
TagsNo tags attached.
Fixed in build

Relationships

related to 0017898 closedpetr Add a method to only reload window, to facilitate faster skin switching & addon installation without interrupting playback 
related to 0019009 closedLudek localRequirejs doesn't work correctly in install.js/uninstall.js 
related to 0019010 closeddrakinite Install / uninstall of add-ons without restart 

Activities

drakinite

2022-04-24 19:25

developer   ~0067712

Doing this would introduce performance challenges, because sorting the items and preparing a Menu object takes time; and controls cache the already-built Menu object.

Do you need to be able to add an arbitrary number of menu items, or can you get away with creating a limited number of pre-cached menu items and changing their title/contents programmatically? You can also create submenus asynchronously with a Promise. A working example addon which does that is Copy and Swap Fields: https://www.mediamonkey.com/addons/browse/item/copy-and-swap-fields/

Example:
window.menus.tracklistMenuItems.push({
    action: {
        title: () => myChangeableTitle,
        visible: () => isThisOneVisible,
        execute: () => {
            switch(myState) {
                case 'state1': doAction1();
                case 'state2': doAction2();
            }
        },
        submenu: () => {
            return new Promise((resolve, reject) => {
                // you can also do asynchronous stuff here, like let list = uitools.getSelectedTracklist(); await list.whenLoaded();
                let arr = [
                    {
                        action: myAction1,
                        order: 10,
                        grouporder: 10
                    }, {
                        action: myAction2,
                        order: 20,
                        grouporder: 10
                    }
                ];
                resolve(arr);
            });
        }
    },
    order: 10,
    grouporder: 10,
});

zvezdan

2022-04-24 19:42

updater   ~0067714

I am sorry, but I have no clue what are you talking about. I don't have problem to create menu items in the context menus, including Playing. I already have trackListView_add.js with this:
window.menus.tracklistMenuItems.push({
    action: actions.mnuQueueSelected,
    order: 60,
    grouporder: 20
});

I don't see how your example is different than that.

However, as I said, I need solution which would be useful in install.js without need to restart the program. In MM2-4 it was piece of cake.

You should make things easier for scripters, not for you. And you are again assigning the issue to me as I was employed by Ventis Media.

drakinite

2022-04-25 00:12

developer   ~0067745

Re "assigning the issue to me as I was employed by Ventis Media": I assigned it to you for feedback, because I was requesting feedback from you.

If your intention is to add menu items inside install.js, and to make your addon start working immediately without having the user restart, I am sorry but that is not feasible. If this was requested back in 2015, maybe it could have been done. But MM5 is designed such that controls and other data structures are created once at the first time they are needed (either at the program startup or at the first time a particular control/view is enabled). Initializing a control takes a significant amount of processing time, and after a a control/view is initialized, it can safely assume certain things will not change (e.g. menu items, actions, tracklistFieldDefs, and translation strings) until it is cleaned up. This approach genuinely improves performance by a lot, and MM5 is way too far along in its development cycle to introduce such a significant change in its structure.

It would be *possible* to add ways of refreshing these controls after any of the items I listed change, but there is a 110% chance it would introduce nasty bugs in unexpected edge cases; and the only surefire way to ensure nothing bad happens would be to re-initialize everything. And we can do that by reloading the window. After 0017898 is introduced, the window should be able to reload much faster after installing most addons (anything that only includes JS/HTML/LESS, i.e. anything other than plugins and language packs). It takes a lot less time to reload the HTML window than it takes to reload the entire app.

zvezdan

2022-04-25 07:02

updater   ~0067750

It is not true that such thing is "not feasible", it is just that you don't want to bother with it. Even your latter comment proves otherwise ("It would be *possible*...)

If you read my another issue report (19010), you would know that the menu items could be added already in the install.js:
- to the main menu, e.g. Play;
- to the context menus of the newly opened tracklists.

The new menu item is not added to the Playing menu if its tracklist was already displayed, but if you change its layout to the simple one and again to the advanced one, then even the Playing tracklist would have the new menu item. The same apply to the main tracklist which is currently displayed - the menu item is not added to its context menu, but if you switch to another node, its tracklist will have added the new menu item.

Why would be their adding different and more easier than that to the already displayed tracklists?

It is just matter of traversing to the all displayed tracklists and adding menu items to them. You cannot convince me that reloading the whole GUI and all add-ons would be faster than that.

Of course there is a chance that you could introduce bugs doing that, but there is even more chance if you leave that to scripters to do the same in their scripts. I am sure I could do that with a lot of effort, but why would I bother with it if you don't want to.

This comment should go the the other issue that I mentioned, but here it is anyway: in my opinion it is just plain dumb to reload the whole GUI and all add-ons whenever user install every add-on, even if these add-ons are simple ones.

Ludek

2022-04-25 10:45

developer   ~0067757

Last edited: 2022-04-25 10:55

Defining the /controls/trackListView_add.js is the right way.

1) it ensures that all necessary items (be it cached or not) are re-loaded -- no matter of window context
2) You don't need to write the code twice (once in install.js and also in trackListView_add.js )

In addition just adding something to window.menus.tracklistMenuItems in install.js will update it just in the main window (and not others already opened dialog windows).
And as other code (be it our or third party) can cache window.menus.tracklistMenuItems in some way -- then you won't be never 100% sure that everything will work correctly (until restart).

zvezdan

2022-04-25 16:12

updater   ~0067767

You are responding as if asking something for myself. After 16 years you still don't understand that my requests here in Mantis are because of your own good. It is your own program that will benefit of my suggestions, not mine.

In my opinion, any modern program that requires restart of the program whenever some add-on will be added, even if that add-on is some dumb ten-liners one that don't have any impact on GUI, is not behaving professional. Your own program from MM3 to MM4 didn't require such thing. Many other programs do not require such thing. VSCode could uninstall almost all extensions without need to restart the app (and even when it restarts, it is much faster then MM5), and I don't know for any VSCode extension that need restart after installation.

1) It is you and your program which should ensure that all necessary items are re-loaded;
2) we don't need to write the code twice, if you fix this localRequirejs thing.
2a) if you do the 1), then we don't need this silly things with trackListView_add.js and similar at all. I don't like my code scattered on hundred files like you do. I like it all inside one file. And I don't see any reason why it should not be all inside init.js. But, here you have it, as you want.

The context menus should not be updated in each and every tracklist. I don't need my menu items in the tracklists of the opened dialog windows. I didn't have such ability in MM3-4, and I don't need it now. But I would like to have menu items in the context menus of the main tracklist and Playling list and the tree, since I had that in MM3-4. Without restart of the program after installation of the add-ons.

Ludek

2022-08-31 16:12

developer   ~0069116

2) The localRequirejs thing has been fixed as 0019009