Skip to content

Commit

Permalink
Merge pull request #2 from mmuffins/dev
Browse files Browse the repository at this point in the history
Rename extension
  • Loading branch information
mmuffins authored May 26, 2019
2 parents e790ea2 + bc9ca38 commit fdb21f1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Addons Menu for MediaMonkey
[![Build status](https://dev.azure.com/mmuffins/github/_apis/build/status/MediaMonkey.AddonsMenu)](https://dev.azure.com/mmuffins/github/_build/latest?definitionId=79)
# Extensions Menu for MediaMonkey
[![Build status](https://dev.azure.com/mmuffins/github/_apis/build/status/MediaMonkey.ExtensionsMenu)](https://dev.azure.com/mmuffins/github/_build/latest?definitionId=79)

This extension adds an additional item to the MediaMonkey 5 main menu bar that allows extension developers to present an entry point or functionality of their extension in a central and consistent way to the user.

## Installation
Download the latest release from the releases section and double click addonsMenu.mmip. An MediaMonkey dialog will automatically pop up, prompting you to confirm the installation.
Download the latest release from the releases section and double click extensionsMenu.mmip. An MediaMonkey dialog will automatically pop up, prompting you to confirm the installation.

## Registering actions
To add an action to the addons menu, follow the steps below.
Create an action for the function of the calling addon
To add an action to the Extensions menu, follow the steps below.
Create an action for the function of the calling Extensions
```javascript
actions.testAddon = {
actions.testExtensions = {
create: {
title: function() {
return _('&TestAddon Create Action')
return _('&TestExtension Create Action')
},
hotkeyAble: false,
category: actionCategories.addons,
category: actionCategories.extensions,
icon: 'createIcon',
execute: function() {
...
Expand All @@ -25,41 +25,41 @@ actions.testAddon = {

delete: {
title: function() {
return _('&TestAddon Delete Action')
return _('&TestExtension Delete Action')
},
hotkeyAble: false,
category: actionCategories.addons,
category: actionCategories.extensions,
icon: 'deleteIcon',
execute: function() {
...
}
},
}
```
Since it's not possible to enforce a load order for extensions or otherwise ensure that the Addons Menu extension is loaded before an extension wants to register an action, new menu items are added indirectly by pushing them into an import queue, which is picked up and processed once the Addons Menu extension is loaded.
Since it's not possible to enforce a load order for extensions or otherwise ensure that the Extensions Menu extension is loaded before an extension wants to register an action, new menu items are added indirectly by pushing them into an import queue, which is picked up and processed once the Extensions Menu extension is loaded.

```javascript
// Add global section to register addon actions if it doesn't exist yet
if (typeof addons == "undefined")
var addons = {}
// Add global section to register extension actions if it doesn't exist yet
if (typeof extensions == "undefined")
var extensions = {}

// If the Addons Menu was not loaded yet, not import queue exists.
if (!addons.hasOwnProperty('addonsMenuImportQueue'))
addons.addonsMenuImportQueue = []
// If the Extensions Menu was not loaded yet, not import queue exists.
if (!extensions.hasOwnProperty('extensionsMenuImportQueue'))
extensions.extensionsMenuImportQueue = []

// Push actions that should be added to the menu to the import queue.
// Do not replace the import queue with a new array as this might remove already queued actions from other extensions
testAddonActions.push({action:actions.testAddon.create, order: 10, category:'TestAddon'})
testAddonActions.push({action:actions.testAddon.delete, order: 20, category:'TestAddon'})
extensions.extensionsMenuImportQueue.push({action:actions.testExtension.create, order: 10, category:'TestExtension'})
extensions.extensionsMenuImportQueue.push({action:actions.testExtension.delete, order: 20, category:'TestExtension'})

// Refresh the menu to import actions that were added to the queue.
// No need to worry if the menu can't be refreshed at this point because it's not loaded yet.
// It will automatically import all pending entries in the import queue as soon as its loaded.
if(addons.addonsMenu != null)
addons.addonsMenu.refresh();
if(extensions.extensionsMenu != null)
extensions.extensionsMenu.refresh();
```

Each pushed to the import queue needs to have three properties:
* action: Contains the action to be executed.
* category: Category/Grouping name for all entries. This should usually be the name of the addon.
* category: Category/Grouping name for all entries. This should usually be the name of the extension.
* order: Sort order for the respective entry within its category.
32 changes: 16 additions & 16 deletions actions_add.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
"use strict";

window.actionCategories.addons = function(){
window.actionCategories.extensions = function(){
return _('Extensions');
}

// Add global section to register addon actions if it doesn't exist yet
if (typeof addons == "undefined")
var addons = {}
// Add global section to register extension actions if it doesn't exist yet
if (typeof extensions == "undefined")
var extensions = {}

addons.addonsMenu = {
extensions.extensionsMenu = {
menuOrder: 55,
menuGrouporder: 10,
menu: [],

refresh: async function(){
let _this = this;
if (!addons.hasOwnProperty('addonsMenuImportQueue') || !addons.addonsMenuImportQueue instanceof Array) {
addons.addonsMenuImportQueue = [];
if (!extensions.hasOwnProperty('extensionsMenuImportQueue') || !extensions.extensionsMenuImportQueue instanceof Array) {
extensions.extensionsMenuImportQueue = [];
return;
}

if(addons.addonsMenuImportQueue.length == 0)
if(extensions.extensionsMenuImportQueue.length == 0)
return;

let importItems = addons.addonsMenuImportQueue;
addons.addonsMenuImportQueue = [];
let importItems = extensions.extensionsMenuImportQueue;
extensions.extensionsMenuImportQueue = [];

// filter out items with missing properties
importItems = importItems.filter(menuItm => {
Expand All @@ -40,12 +40,12 @@ addons.addonsMenu = {
});

// Add imported entries to menu, but skip duplicates
importItems.forEach(addonItm => {
if (typeof (_this.menu.find(item => item.action.title() == addonItm.action.title() && item.category == addonItm.category)) != "undefined") {
importItems.forEach(extensionItm => {
if (typeof (_this.menu.find(item => item.action.title() == extensionItm.action.title() && item.category == extensionItm.category)) != "undefined") {
return Promise.reject('Item already exists');
}

_this.menu.push({action: addonItm.action, order: addonItm.order, category: addonItm.category, grouporder: 100});
_this.menu.push({action: extensionItm.action, order: extensionItm.order, category: extensionItm.category, grouporder: 100});
})

_this.sortMenu();
Expand All @@ -63,7 +63,7 @@ addons.addonsMenu = {
for (let i = 0; i < window.mainMenuItems.length; i++) {
const itm = window.mainMenuItems[i].action;

if(itm.hasOwnProperty('title') && itm.title instanceof Function && itm.title() == '&Addons'){
if(itm.hasOwnProperty('title') && itm.title instanceof Function && itm.title() == '&Extensions'){
itm.submenu = _this.menu;
return;
}
Expand All @@ -72,7 +72,7 @@ addons.addonsMenu = {
let newMenu = {
action: {
title: function () {
return _('&Addons');
return _('&Extensions');
},
visible: !webApp,
submenu: _this.menu
Expand Down Expand Up @@ -108,4 +108,4 @@ addons.addonsMenu = {
}
}

addons.addonsMenu.refresh()
extensions.extensionsMenu.refresh()
6 changes: 3 additions & 3 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Addons Menu",
"id": "AddonsMenu",
"description": "Adds an Addons Section to the Main Menu",
"title": "Extensions Menu",
"id": "extensionsMenu",
"description": "Adds an Extensions Section to the Main Menu",
"version": "1.0.0",
"type": "general",
"author": "Michael Kellner"
Expand Down

0 comments on commit fdb21f1

Please sign in to comment.