Skip to content

Commit

Permalink
#1 Add link to options page in context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
richardscarrott committed Apr 22, 2018
1 parent d9c2262 commit d5fff1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"default_locale": "en",
"background": {
"scripts": ["dist/background.js"]
"scripts": ["dist/background.js"],
"persistent": false
},
"options_page": "dist/options.html",
"options_ui": {
Expand Down
25 changes: 20 additions & 5 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,31 @@ const renderContentContextMenu = (content, parentId) => {
});
};

const OPTIONS_CONTEXT_MENU_ID = uuid();
const TOP_LEVEL_CONTEXT_MENU_ID = uuid();

const render = state => {
return removeAllContextMenus()
.then(() => {
const topLevelContextMenuId = uuid();
return createContextMenu({
id: topLevelContextMenuId,
id: TOP_LEVEL_CONTEXT_MENU_ID,
title: 'Snippets'
}).then(() => topLevelContextMenuId);
});
})
.then(topLevelContextMenuId => {
.then(() => {
const sources = sourcesSelector(state);
return Promise.all(
sources.map(source =>
renderContentContextMenu(source.content, topLevelContextMenuId)
renderContentContextMenu(source.content, TOP_LEVEL_CONTEXT_MENU_ID)
)
);
})
.then(() => {
return createContextMenu({
id: OPTIONS_CONTEXT_MENU_ID,
title: 'Add new snippets',
parentId: TOP_LEVEL_CONTEXT_MENU_ID
});
});
};

Expand All @@ -73,6 +82,12 @@ const start = store => {
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === OPTIONS_CONTEXT_MENU_ID) {
chrome.tabs.create({
url: 'dist/options.html'
});
return;
}
const menuItemIdParts = info.menuItemId.split(ID_DELIMITER);
const fileId = menuItemIdParts[menuItemIdParts.length - 1];
const file = store.getState().entities.files[fileId]; // TODO: Use selector.
Expand Down

0 comments on commit d5fff1b

Please sign in to comment.