Skip to content

Commit

Permalink
🐛 Add conditional check for browserAction
Browse files Browse the repository at this point in the history
  • Loading branch information
nilooy committed Jun 20, 2022
2 parents ddb5614 + ff9ae83 commit ad27efd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.DS_Store
.idea
node_modules
extension/chrome
extension/firefox
chrome/build
firefox/build
chrome.pem
firefox.pem
chrome/
firefox/
extension/chrome
extension/firefox
7 changes: 4 additions & 3 deletions extension/manifest-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"background": {
"scripts": [
".dist/background.js"
"/dist/background.js"
],
"persistent": false
},
Expand All @@ -24,15 +24,16 @@
"<all_urls>"
],
"js": [
".dist/content.js"
"/dist/content.js"
],
"run_at": "document_start",
"all_frames": true
}
],
"permissions": [
"https://api.github.com/*",
"https://www.google-analytics.com/*"
"https://www.google-analytics.com/*",
"tabs"
],
"content_security_policy": "script-src 'self'; object-src 'self'",
"web_accessible_resources": [
Expand Down
22 changes: 21 additions & 1 deletion src/Browser/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const tabRemovalListener = () => {
})
}

browser.browserAction.onClicked.addListener(e => {
// For cross-browser support
const action = browser.browserAction || browser.action

action.onClicked.addListener(e => {
console.debug('action.onClicked', e)

browser.tabs
Expand Down Expand Up @@ -113,6 +116,23 @@ const contentListener = () => {
})
}

const tabListener = () => {
const tabEvent = {
'create-tab': request =>
browser.tabs
.create({
url: request.data.url,
})
.catch(console.error),
}
chrome.runtime.onMessage.addListener(function (request, sender) {
if (request.source !== 'meteor-devtools-evolved') return null

tabEvent[request.eventType]?.(request)
})
}

panelListener()
tabRemovalListener()
contentListener()
tabListener()
23 changes: 6 additions & 17 deletions src/Pages/Panel/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IMenuItem, ITab, TabBar } from '@/Components/TabBar'
import { Tag } from '@blueprintjs/core'
import { isNumber } from 'lodash'
import { useAnalytics } from '@/Utils/Hooks/useAnalytics'
import browser from 'webextension-polyfill'
import { openTab } from '@/Utils/BackgroundEvents'

export const Navigation: FunctionComponent = observer(() => {
const panelStore = usePanelStore()
Expand Down Expand Up @@ -64,11 +64,9 @@ export const Navigation: FunctionComponent = observer(() => {
key: 'community',
content: '👥 Community',
handler: () => {
browser.tabs
.create({
url: 'https://join.slack.com/t/meteor-community/shared_invite/zt-a9lwcfb7-~UwR3Ng6whEqRxcP5rORZw',
})
.catch(console.error)
openTab(
'https://join.slack.com/t/meteor-community/shared_invite/zt-a9lwcfb7-~UwR3Ng6whEqRxcP5rORZw',
)

analytics?.event('navigation', 'click', { label: 'community' })
},
Expand Down Expand Up @@ -105,12 +103,7 @@ export const Navigation: FunctionComponent = observer(() => {
</>
),
handler: () => {
browser.tabs
.create({
url: repositoryData.html_url.concat('/issues'),
})
.catch(console.error)

openTab(repositoryData.html_url.concat('/issues'))
analytics?.event('navigation', 'click', { label: 'feedback' })
},
shine: true,
Expand All @@ -130,11 +123,7 @@ export const Navigation: FunctionComponent = observer(() => {
),
shine: true,
handler: () => {
browser.tabs
.create({
url: repositoryData.html_url.concat('/stargazers'),
})
.catch(console.error)
openTab(repositoryData.html_url.concat('/stargazers'))

analytics?.event('navigation', 'click', { label: 'star' })
},
Expand Down
10 changes: 3 additions & 7 deletions src/Pages/Panel/Sponsor/SponsorHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { FC } from 'react'
import { StringUtils } from '@/Utils/StringUtils'
import { AppToaster } from '@/AppToaster'
import MeteorCloudLogo from '@/Assets/meteor-cloud-logo.png'
import browser from 'webextension-polyfill'
import { openTab } from '@/Utils/BackgroundEvents'

import '@/Assets/meteor-shower.jpg'

Expand Down Expand Up @@ -77,19 +77,15 @@ export const SponsorHero: FC<Props> = () => {
<button
className='btn btn-primary'
onClick={() =>
browser.tabs.create({
url: 'https://social.meteor.com/devtools-evolved',
})
openTab('https://social.meteor.com/devtools-evolved')
}
>
Sign Up
</button>

<button
className='btn bg-orange-500 hover:bg-orange-600'
onClick={() =>
browser.tabs.create({ url: 'mailto:marketing@meteor.com' })
}
onClick={() => openTab('mailto:marketing@meteor.com')}
>
Email Us the Code
</button>
Expand Down
9 changes: 9 additions & 0 deletions src/Utils/BackgroundEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import browser from 'webextension-polyfill'

export const openTab = (url: string): void => {
browser.runtime.sendMessage({
source: 'meteor-devtools-evolved',
eventType: 'create-tab',
data: { url: url },
})
}

0 comments on commit ad27efd

Please sign in to comment.