Missing property in window.mainMenuItems

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

Moderator: jiri

Posts: 108
Joined: Sat Nov 12, 2011 1:31 pm

Missing property in window.mainMenuItems

Post by TIV73 »

I'm currently working on an extension that adds a new menu item which allows for easy access to extension actions. For that I'm creating a new menu with some submenus, add it to the mainMenuItems array, sort the array and force a refresh:

Code: Select all

let newMenu = {
	action: {
		title: function () {
				return _('&Extensions');
		visible: !webApp,
		submenu: _this.menu
	order: 55,
	grouporder: 10,

window.mainMenuItems = window.mainMenuItems.sort((a,b) => a.order > b.order);
Setting the order property to 55 should put the new menu between Tools and Help on the main menu. Unfortunately the sort function stops midway and isn't able to properly sort all items. Checking window.mainMenuItems reveals why it isn't working:

Code: Select all

(9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {action: {…}, order: 10, grouporder: 10, identifier: 1}
1: {action: {…}, order: 20, grouporder: 10, identifier: 8}
2: {action: {…}, order: 30, grouporder: 10, identifier: 22}
3: {action: {…}, order: 40, grouporder: 10, identifier: 39}
4: {action: {…}, order: 50, grouporder: 10, identifier: 66}
5: {action: {…}, order: 60, grouporder: 10, identifier: 81}
6: {action: {…}, identifier: 82}
7: {action: {…}, order: 55, grouporder: 10}
8: {action: {…}, order: 100, grouporder: 10, identifier: 85}
length: 9
__proto__: Array(0)

{title: "MediaMonkey Gold", visible: ƒ, submenu: Array(2), order: 70, grouporder: 10}
It looks like the order and grouporder properties of the MediaMonkey Gold item were accidently nested one level too deep. If I manually change that item in the actions.js file to match the other items, sorting works as expected. Nevertheless, I can't be sure if this is really a typo or intended behavior.

Is this a bug or is there a different method for extensions to add a main menu item?

Update: I just noticed that the mediamonkey gold item is generally a bit different from the other ones. Its title property contains a plain string instead of returning the title via function as the other items do.
Posts: 1702
Joined: Tue Mar 07, 2006 5:31 pm
Location: Czech

Re: Missing property in window.mainMenuItems

Post by PetrCBR »

You're right. Thanks ... will be fixed in next build.
re title: you can define it directly or using method (same for visible, disabled and some more properties) ... to get the value from such a property we're using our method resolveToValue ... you can check mminit.js for that method and usage.
Post Reply