Skip to content

Commit

Permalink
♻️ Move browserAction to tabManager
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Apr 26, 2024
1 parent 998e379 commit c79fc64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
16 changes: 3 additions & 13 deletions apps/extensions/lib/parent/ext-browserAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ this.browserAction = class extends ExtensionAPIPersistent {

async onManifestEntry() {
const { extension } = this
/** @type {browser_action__manifest.WebExtensionManifest__extended['browser_action']} */
const options = extension.manifest.browser_action

if (!options) {
Expand Down Expand Up @@ -67,25 +66,16 @@ this.browserAction = class extends ExtensionAPIPersistent {
* running extension context.
*/
onClicked({ fire }) {
const { extension } = this
const /** @type {Extension} */ extension = this.extension

/**
* @param {import("resource://app/modules/EBrowserActions.sys.mjs").IBrowserActionEvents['click']} clickInfo
*/
const callback = async (_name, clickInfo) => {
if (fire.wakeup) await fire.wakeup()
const { tab, window } = lazy.WindowTracker.getWindowWithBrowserId(
clickInfo.tabId,
) || { tab: null, window: null }

if (!tab || !window) {
return fire.sync(null, clickInfo.clickData)
}

fire.sync(
tabTracker.serializeTab(extension, tab, window),
clickInfo.clickData,
)
const tab = extension.tabManager.get(clickInfo.tabId)
fire.sync(tab.convert(), clickInfo.clickData)
}

this.on('click', callback)
Expand Down
17 changes: 16 additions & 1 deletion apps/extensions/lib/types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* eslint-disable @typescript-eslint/ban-types */
/// <reference types="gecko-types" />
import { ConduitAddress } from 'resource://gre/modules/ConduitsParent.sys.mjs'
import { Extension } from 'resource://gre/modules/Extension.sys.mjs'
import { Extension as ToolkitExtension } from 'resource://gre/modules/Extension.sys.mjs'
import { SchemaRoot } from 'resource://gre/modules/Schemas.sys.mjs'

import { PointConduit } from './ConduitChild'
Expand All @@ -15,6 +15,12 @@ declare global {
type NativeTab = import('@browser/tabs').WindowTab
type XULElement = Element

interface Extension extends ToolkitExtension {
tabManager: TabManagerBase
manifest: Omit<browser._manifest.WebExtensionManifest, 'browser_action'> &
browser_action__manifest.WebExtensionManifest__extended
}

/* eslint-disable @typescript-eslint/no-explicit-any */
function getConsole(): any
function runSafeSyncWithoutClone(f: any, ...args: any[]): any
Expand Down Expand Up @@ -1532,6 +1538,15 @@ declare global {

matches(queryInfo: QueryInfo): boolean

/**
* Converts this tab object to a JSON-compatible object containing the values
* of its properties which the extension is permitted to access, in the format
* required to be returned by WebExtension APIs.
*
* @param [fallbackTabSize]
* A geometry data if the lazy geometry data for this tab hasn't been
* initialized yet.
*/
convert(fallbackTabSize?: any): any

queryContent(message: string, options: Options): Promise<any>[]
Expand Down

0 comments on commit c79fc64

Please sign in to comment.