Skip to content

Commit

Permalink
✨ Add support for show and hide
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Dec 24, 2023
1 parent fc55569 commit 1e91e6a
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 18 deletions.
6 changes: 5 additions & 1 deletion scripts/lib/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const MPL_HEADER = [

const FIXES = [
{
regex: new RegExp('.*\\.(css|((j|t)s))'),
regex: new RegExp('.*\\.(css|(m?(j|t)s))'),
commentOpen: '/* ',
comment: ' * ',
commentClose: ' */\n',
Expand All @@ -22,6 +22,10 @@ const FIXES = [
comment: ' - ',
commentClose: ' -->\n',
},
{
regex: new RegExp('.*\\.(py|ftl)'),
comment: '# ',
},
]

export function isValidLicense(file: string): boolean {
Expand Down
3 changes: 2 additions & 1 deletion scripts/license-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { readFileSync } from 'node:fs'
import { argv } from 'node:process'

import { SCRIPTS_PATH, SRC_PATH } from './lib/constants.js'
import { SCRIPTS_PATH, SRC_PATH, STATIC_PATH } from './lib/constants.js'
import { walkDirectory } from './lib/fs.js'
import { autoFix, isValidLicense } from './lib/license.js'
import { failure } from './lib/logging.js'
Expand All @@ -17,6 +17,7 @@ const shouldFix = argv.includes('--fix')
const filesToCheck = [
...(await walkDirectory(SCRIPTS_PATH)),
...(await walkDirectory(SRC_PATH)),
...(await walkDirectory(STATIC_PATH)),
]

const invalidFiles = filesToCheck
Expand Down
2 changes: 1 addition & 1 deletion src/content/browser/components/omnibox/Omnibox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
/>

{#each $pageActions as [_extId, pageAction]}
{#if pageAction.shouldShow($uri.asciiSpec)}
{#if pageAction.shouldShow($uri.asciiSpec, tab.getTabId())}
<PageAction {pageAction} />
{/if}
{/each}
Expand Down
23 changes: 21 additions & 2 deletions src/modules/EPageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,40 @@ export class PageAction implements PageActionOptions {
hideMatches: MatchPatternSet
icons?: Record<number, string>

showTabIds = new Set<number>()
hideTabIds = new Set<number>()

constructor(data: PageActionOptions<string[]>) {
this.tooltip = data.tooltip
this.popupUrl = data.popupUrl
this.showMatches = new MatchPatternSet(data.showMatches || [])
this.hideMatches = new MatchPatternSet(data.hideMatches || [])
}

shouldShow(url: string) {
return this.showMatches.matches(url) && !this.hideMatches.matches(url, true)
shouldShow(url: string, tabId: number) {
const urlMatch =
this.showMatches.matches(url) &&
!this.hideMatches.matches(url, true) &&
!this.hideTabIds.has(tabId)
const idMatch = this.showTabIds.has(tabId)

return urlMatch || idMatch
}

setIcons(icons: Record<number, string>) {
this.icons = icons
this.events.emit('updateIcon', icons)
}

addShow(id: number) {
this.showTabIds.add(id)
this.hideTabIds.delete(id)
}

addHide(id: number) {
this.hideTabIds.add(id)
this.showTabIds.delete(id)
}
}

export const EPageActions = {
Expand Down
4 changes: 4 additions & 0 deletions static/extensions/parent/ext-browser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// @ts-check
/* eslint-disable no-undef */
/// <reference path="../types/index.d.ts" />
Expand Down
31 changes: 18 additions & 13 deletions static/extensions/parent/ext-pageAction.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
/* eslint-disable no-undef */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// @ts-check
/// <reference path="../types/index.d.ts" />

/* eslint-disable no-undef */
// Imports are pulled from ext-browser

this.pageAction = class extends ExtensionAPIPersistent {
async onManifestEntry(entryName) {
/** @type {import('resource://app/modules/EPageActions.sys.mjs').PageAction | null} */
pageAction = null

async onManifestEntry() {
const { extension } = this
const options = extension.manifest.page_action

console.log(entryName, options, extension)

const pageAction = new lazy.EPageActions.PageAction({
this.pageAction = new lazy.EPageActions.PageAction({
tooltip: options.default_title,
popupUrl: options.default_popup,
showMatches: options.show_matches,
hideMatches: options.hide_matches,
})

pageAction.setIcons(
this.pageAction.events.on('click', (v) => this.emit('click', v))
this.pageAction.setIcons(
lazy.ExtensionParent.IconDetails.normalize(
{
path: options.default_icon || extension.manifest.icons,
Expand All @@ -27,12 +34,7 @@ this.pageAction = class extends ExtensionAPIPersistent {
),
)

pageAction.events.on('click', (v) => {
console.log('Click Value', v)
this.emit('click', v)
})

lazy.EPageActions.registerPageAction(extension.id, pageAction)
lazy.EPageActions.registerPageAction(extension.id, this.pageAction)
}

onShutdown() {
Expand Down Expand Up @@ -88,6 +90,9 @@ this.pageAction = class extends ExtensionAPIPersistent {
getAPI(context) {
return {
pageAction: {
show: (id) => this.pageAction?.addShow(id),
hide: (id) => this.pageAction?.addHide(id),

onClicked: new EventManager({
context,
module: 'pageAction',
Expand Down
4 changes: 4 additions & 0 deletions static/extensions/sharedTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
* The following features are not going to be supported, primarily because I see
* no good reason for including support
Expand Down
4 changes: 4 additions & 0 deletions static/extensions/types/ConduitChild.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* eslint-disable @typescript-eslint/ban-types */

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down
4 changes: 4 additions & 0 deletions static/extensions/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/// <reference path="../../../src/link.d.ts" />

/// <reference path="./ConduitChild.d.ts" />
Expand Down
4 changes: 4 additions & 0 deletions static/extensions/types/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* eslint-disable @typescript-eslint/ban-types */
/// <reference types="gecko-types" />
import { ConduitAddress } from 'resource://gre/modules/ConduitsParent.sys.mjs'
Expand Down
3 changes: 3 additions & 0 deletions static/localization/en-US/branding/brand.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 changes: 4 additions & 0 deletions static/modules/mitt.sys.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
* MIT License
*
Expand Down
3 changes: 3 additions & 0 deletions static/modules/sessionstore/SessionStore.sys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

0 comments on commit 1e91e6a

Please sign in to comment.