From 1e91e6a85a557e62dbb4a2d5de580bfe56de95bb Mon Sep 17 00:00:00 2001
From: trickypr <23250792+trickypr@users.noreply.github.com>
Date: Sun, 24 Dec 2023 21:23:09 +1100
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20`show`=20and?=
=?UTF-8?q?=20`hide`?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
scripts/lib/license.ts | 6 +++-
scripts/license-check.ts | 3 +-
.../browser/components/omnibox/Omnibox.svelte | 2 +-
src/modules/EPageActions.ts | 23 ++++++++++++--
static/extensions/parent/ext-browser.js | 4 +++
static/extensions/parent/ext-pageAction.js | 31 +++++++++++--------
static/extensions/sharedTypes.d.ts | 4 +++
static/extensions/types/ConduitChild.d.ts | 4 +++
static/extensions/types/index.d.ts | 4 +++
static/extensions/types/utils.d.ts | 4 +++
static/localization/en-US/branding/brand.ftl | 3 ++
.../browser/components/mozSupportLink.ftl | 3 ++
static/modules/mitt.sys.mjs | 4 +++
.../modules/sessionstore/SessionStore.sys.mjs | 3 ++
14 files changed, 80 insertions(+), 18 deletions(-)
diff --git a/scripts/lib/license.ts b/scripts/lib/license.ts
index 7fc5115..6635793 100644
--- a/scripts/lib/license.ts
+++ b/scripts/lib/license.ts
@@ -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',
@@ -22,6 +22,10 @@ const FIXES = [
comment: ' - ',
commentClose: ' -->\n',
},
+ {
+ regex: new RegExp('.*\\.(py|ftl)'),
+ comment: '# ',
+ },
]
export function isValidLicense(file: string): boolean {
diff --git a/scripts/license-check.ts b/scripts/license-check.ts
index 3d3e393..a365bea 100644
--- a/scripts/license-check.ts
+++ b/scripts/license-check.ts
@@ -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'
@@ -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
diff --git a/src/content/browser/components/omnibox/Omnibox.svelte b/src/content/browser/components/omnibox/Omnibox.svelte
index 872daea..d3d8496 100644
--- a/src/content/browser/components/omnibox/Omnibox.svelte
+++ b/src/content/browser/components/omnibox/Omnibox.svelte
@@ -90,7 +90,7 @@
/>
{#each $pageActions as [_extId, pageAction]}
- {#if pageAction.shouldShow($uri.asciiSpec)}
+ {#if pageAction.shouldShow($uri.asciiSpec, tab.getTabId())}
{/if}
{/each}
diff --git a/src/modules/EPageActions.ts b/src/modules/EPageActions.ts
index aada345..4fb1c55 100644
--- a/src/modules/EPageActions.ts
+++ b/src/modules/EPageActions.ts
@@ -69,6 +69,9 @@ export class PageAction implements PageActionOptions {
hideMatches: MatchPatternSet
icons?: Record
+ showTabIds = new Set()
+ hideTabIds = new Set()
+
constructor(data: PageActionOptions) {
this.tooltip = data.tooltip
this.popupUrl = data.popupUrl
@@ -76,14 +79,30 @@ export class PageAction implements PageActionOptions {
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) {
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 = {
diff --git a/static/extensions/parent/ext-browser.js b/static/extensions/parent/ext-browser.js
index 9cd757f..5c7b0b5 100644
--- a/static/extensions/parent/ext-browser.js
+++ b/static/extensions/parent/ext-browser.js
@@ -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 */
///
diff --git a/static/extensions/parent/ext-pageAction.js b/static/extensions/parent/ext-pageAction.js
index 19279a9..2cf4cdb 100644
--- a/static/extensions/parent/ext-pageAction.js
+++ b/static/extensions/parent/ext-pageAction.js
@@ -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
///
+/* 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,
@@ -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() {
@@ -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',
diff --git a/static/extensions/sharedTypes.d.ts b/static/extensions/sharedTypes.d.ts
index cd5389b..585010c 100644
--- a/static/extensions/sharedTypes.d.ts
+++ b/static/extensions/sharedTypes.d.ts
@@ -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
diff --git a/static/extensions/types/ConduitChild.d.ts b/static/extensions/types/ConduitChild.d.ts
index 009d417..f20bae0 100644
--- a/static/extensions/types/ConduitChild.d.ts
+++ b/static/extensions/types/ConduitChild.d.ts
@@ -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 */
diff --git a/static/extensions/types/index.d.ts b/static/extensions/types/index.d.ts
index bfba9ce..42b3819 100644
--- a/static/extensions/types/index.d.ts
+++ b/static/extensions/types/index.d.ts
@@ -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/. */
+
///
///
diff --git a/static/extensions/types/utils.d.ts b/static/extensions/types/utils.d.ts
index 3f2f1df..67febf3 100644
--- a/static/extensions/types/utils.d.ts
+++ b/static/extensions/types/utils.d.ts
@@ -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 */
///
import { ConduitAddress } from 'resource://gre/modules/ConduitsParent.sys.mjs'
diff --git a/static/localization/en-US/branding/brand.ftl b/static/localization/en-US/branding/brand.ftl
index e69de29..6fbe815 100644
--- a/static/localization/en-US/branding/brand.ftl
+++ b/static/localization/en-US/branding/brand.ftl
@@ -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/.
diff --git a/static/localization/en-US/browser/components/mozSupportLink.ftl b/static/localization/en-US/browser/components/mozSupportLink.ftl
index e69de29..6fbe815 100644
--- a/static/localization/en-US/browser/components/mozSupportLink.ftl
+++ b/static/localization/en-US/browser/components/mozSupportLink.ftl
@@ -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/.
diff --git a/static/modules/mitt.sys.mjs b/static/modules/mitt.sys.mjs
index 6133a56..5f436db 100644
--- a/static/modules/mitt.sys.mjs
+++ b/static/modules/mitt.sys.mjs
@@ -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
*
diff --git a/static/modules/sessionstore/SessionStore.sys.mjs b/static/modules/sessionstore/SessionStore.sys.mjs
index e69de29..e003224 100644
--- a/static/modules/sessionstore/SessionStore.sys.mjs
+++ b/static/modules/sessionstore/SessionStore.sys.mjs
@@ -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/. */