Missing property in window.mainMenuItems
Posted: Sun Jun 02, 2019 4:40 pm
Hi,
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:
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:
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.
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.push(newMenu);
window.mainMenuItems = window.mainMenuItems.sort((a,b) => a.order > b.order);
uitools.switchMainMenu(false);
uitools.switchMainMenu(true);
Code: Select all
window.mainMenuItems
(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)
window.mainMenuItems[6].action
{title: "MediaMonkey Gold", visible: ƒ, submenu: Array(2), order: 70, grouporder: 10}
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.