Skip to content

Commit c637a96

Browse files
committed
make sure contextmenu item is only shown when Vue devtools is active
1 parent 24812e5 commit c637a96

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

shells/chrome/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"http://*/*",
3333
"https://*/*",
3434
"file:///*",
35+
"tabs",
3536
"contextMenus"
3637
],
3738

shells/chrome/src/background.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ function doublePipe (id, one, two) {
6868
one.disconnect()
6969
two.disconnect()
7070
ports[id] = null
71+
updateContextMenuItem()
7172
}
7273
one.onDisconnect.addListener(shutdown)
7374
two.onDisconnect.addListener(shutdown)
7475
console.log('tab ' + id + ' connected.')
76+
updateContextMenuItem()
7577
}
7678

7779
chrome.runtime.onMessage.addListener((req, sender) => {
@@ -92,13 +94,24 @@ chrome.runtime.onMessage.addListener((req, sender) => {
9294
})
9395

9496
// Right-click inspect context menu entry
95-
96-
chrome.contextMenus.create({
97-
id: 'vue-inspect-instance',
98-
title: 'Inspect Vue component',
99-
contexts: ['all']
97+
let activeTabId
98+
chrome.tabs.onActivated.addListener(({ tabId }) => {
99+
activeTabId = tabId
100+
updateContextMenuItem()
100101
})
101102

103+
function updateContextMenuItem () {
104+
if (ports[activeTabId]) {
105+
chrome.contextMenus.create({
106+
id: 'vue-inspect-instance',
107+
title: 'Inspect Vue component',
108+
contexts: ['all']
109+
})
110+
} else {
111+
chrome.contextMenus.remove('vue-inspect-instance')
112+
}
113+
}
114+
102115
chrome.contextMenus.onClicked.addListener((info, tab) => {
103116
chrome.runtime.sendMessage({
104117
vueContextMenu: {

0 commit comments

Comments
 (0)