Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 8a907b6

Browse files
authored
fix: cannot create context menu item with duplicate id (#231)
1 parent 42a5dc7 commit 8a907b6

File tree

4 files changed

+10
-32
lines changed

4 files changed

+10
-32
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"ts-key-enum": "^2.0.0",
126126
"uuid": "^3.3.2",
127127
"vscode-languageserver-types": "3.12.0",
128+
"webext-domain-permission-toggle": "^0.0.2",
128129
"whatwg-url": "^6.2.1"
129130
}
130131
}

src/browser/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export interface StorageItems {
5555
* Overrides settings from Sourcegraph.
5656
*/
5757
clientSettings: string
58-
hasEnableDomainContextMenu: boolean
5958
}
6059

6160
interface ClientConfigurationDetails {
@@ -94,7 +93,6 @@ export const defaultStorageItems: StorageItems = {
9493
},
9594
},
9695
clientSettings: '',
97-
hasEnableDomainContextMenu: false,
9896
}
9997

10098
export type StorageChange = { [key in keyof StorageItems]: chrome.storage.StorageChange }

src/extension/scripts/background.tsx

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import '../../config/polyfill'
55
import { without } from 'lodash'
66
import { ajax } from 'rxjs/ajax'
77
import { InitData } from 'sourcegraph/module/extension/extensionHost'
8+
import DPT from 'webext-domain-permission-toggle'
89
import ExtensionHostWorker from 'worker-loader?inline!./extensionHost.worker'
910
import * as browserAction from '../../browser/browserAction'
10-
import * as contextMenus from '../../browser/contextMenu'
1111
import * as omnibox from '../../browser/omnibox'
1212
import * as permissions from '../../browser/permissions'
1313
import * as runtime from '../../browser/runtime'
@@ -162,11 +162,6 @@ permissions.onRemoved(permissions => {
162162
})
163163

164164
storage.addSyncMigration((items, set, remove) => {
165-
if (!items.hasEnableDomainContextMenu) {
166-
createEnableDomainContextMenu(() => {
167-
storage.setSync({ hasEnableDomainContextMenu: true })
168-
})
169-
}
170165
if (items.phabricatorURL) {
171166
remove('phabricatorURL')
172167

@@ -273,30 +268,6 @@ runtime.onMessage((message, _, cb) => {
273268
return
274269
})
275270

276-
const ENABLE_SOURCEGRAPH_CONTEXT_MENU = 'ENABLE_SOURCEGRAPH_CONTEXT_MENU'
277-
function createEnableDomainContextMenu(callback?: () => void): void {
278-
contextMenus.create(
279-
{
280-
id: ENABLE_SOURCEGRAPH_CONTEXT_MENU,
281-
title: 'Enable Sourcegraph on this domain',
282-
contexts: ['browser_action'],
283-
onclick: (_: chrome.contextMenus.OnClickData, tab: chrome.tabs.Tab): void => {
284-
if (!tab.url) {
285-
console.error('Could not get tab url to request permissions.')
286-
return
287-
}
288-
try {
289-
const url = new URL(tab.url)
290-
permissions.request([url.origin]).catch(err => console.error('Permissions request denied', err))
291-
} catch {
292-
console.error('Could not get tab url to request permissions')
293-
}
294-
},
295-
},
296-
callback
297-
)
298-
}
299-
300271
function requestPermissionsForEnterpriseUrls(urls: string[], cb: (res?: any) => void): void {
301272
storage.getSync(items => {
302273
const enterpriseUrls = items.enterpriseUrls || []
@@ -468,3 +439,6 @@ chrome.runtime.onConnect.addListener(port => {
468439
)
469440
})
470441
})
442+
443+
// Add "Enable Sourcegraph on this domain" context menu item
444+
DPT.addContextMenu()

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13648,6 +13648,11 @@ web-ext@^2.5.0:
1364813648
yargs "6.6.0"
1364913649
zip-dir "1.0.2"
1365013650

13651+
webext-domain-permission-toggle@^0.0.2:
13652+
version "0.0.2"
13653+
resolved "https://registry.yarnpkg.com/webext-domain-permission-toggle/-/webext-domain-permission-toggle-0.0.2.tgz#28003248699b869e5422b2ef60a7c2b03e1c3c15"
13654+
integrity sha512-obPAEocq/5uw0jaKc1N2bwux/HXDaYz9/8ltvxTRqr0iR6JaTh6/h56FL9uoAZYXcXxjFyE+PRrJicoQrJ8T6g==
13655+
1365113656
webidl-conversions@^4.0.1, webidl-conversions@^4.0.2:
1365213657
version "4.0.2"
1365313658
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"

0 commit comments

Comments
 (0)