Skip to content

Commit

Permalink
Improve the timing of updating context menus on options.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobynet committed May 22, 2013
1 parent 581b1e8 commit 70b7157
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion extension/background.js
Expand Up @@ -15,6 +15,8 @@ chrome.extension.onMessage.addListener(
function (request, sender, sendResponse) {
if ( request.command == 'setClipboard' ) {
copyToClipboard(request.data);
} else if ( request.command == 'updateContextMenus' ) {
updateContextMenus();
}
}
);
Expand Down Expand Up @@ -95,7 +97,7 @@ function onMenuItemClick(contextMenuIdList, info, tab) {
copyToClipboard(linkText);
}

window.addEventListener('load', function () {
function updateContextMenus() {
var contextMenuIdList = {};

chrome.contextMenus.removeAll();
Expand All @@ -122,5 +124,8 @@ window.addEventListener('load', function () {
var n = Number(info.menuItemId.split(/-/).pop());
onMenuItemClick(contextMenuIdList, info, tab);
})
}

window.addEventListener('load', function () {
updateContextMenus();
}, false);
5 changes: 5 additions & 0 deletions extension/options.js
Expand Up @@ -15,6 +15,11 @@ window.addEventListener( 'load', function () {
ctable._listener.onUpdated = function () {
var json = ctable.serialize();
localStorage[localStorageKey] = json;

// Update context menus
chrome.extension.sendMessage({
command: 'updateContextMenus',
});
}
window.ctable = ctable;
}catch(e){
Expand Down

0 comments on commit 70b7157

Please sign in to comment.