diff --git a/apps/extensions/lib/parent/ext-browser.js b/apps/extensions/lib/parent/ext-browser.js index 2fd48cc..5f2a7b2 100644 --- a/apps/extensions/lib/parent/ext-browser.js +++ b/apps/extensions/lib/parent/ext-browser.js @@ -19,9 +19,8 @@ const lazy = lazyESModuleGetters({ class TabTracker extends TabTrackerBase { get activeTab() { - /** @type {any | null} */ const window = lazy.WindowTracker.getActiveWindow() - return window?.windowApi?.tabs?.getCurrentTab() + return window?.activeTab() } init() { @@ -30,30 +29,34 @@ class TabTracker extends TabTrackerBase { } /** - * @param {*} nativeTab + * @param {import('@browser/tabs').WindowTab} nativeTab */ getId(nativeTab) { - return nativeTab.getTabId() + return nativeTab.view.browserId || -1 } + /** + * @param {number} tabId + * @param {import('@browser/tabs').WindowTab} default_ + */ getTab(tabId, default_) { - const { tab } = lazy.WindowTracker.getWindowWithBrowser(tabId) || { + const { tab } = lazy.WindowTracker.getWindowWithBrowserId(tabId) || { tab: default_, } return tab } + /** + * @param {XULBrowserElement} browser + */ getBrowserData(browser) { const data = lazy.WindowTracker.getWindowWithBrowser(browser) if (!data) return { windowId: -1, tabId: -1 } return { - /** @type {number} */ - // @ts-expect-error bad imported types - windowId: data.window.windowApi.id, - /** @type {number} */ - tabId: data.tab.getTabId(), + windowId: data.window.windowId, + tabId: data.tab.view.browserId || -1, } } } diff --git a/apps/modules/lib/BrowserWindowTracker.sys.mjs b/apps/modules/lib/BrowserWindowTracker.sys.mjs index 17805c3..08525e8 100644 --- a/apps/modules/lib/BrowserWindowTracker.sys.mjs +++ b/apps/modules/lib/BrowserWindowTracker.sys.mjs @@ -37,16 +37,20 @@ export const WindowTracker = { return this.registeredWindows.get(wid) }, - getWindowWithBrowser(browser) { + getWindowWithBrowserId(browserId) { for (const window of this.registeredWindows.values()) { const tab = window .windowTabs() - .find((t) => t.view.browserId === browser.browserId) + .find((t) => t.view.browserId === browserId) if (tab) return { window, tab } } return null }, + getWindowWithBrowser(browser) { + return this.getWindowWithBrowserId(browser.browserId) + }, + focusWindow(id) { this.activeWindow = id this.events.emit('focus', this.getActiveWindow()) diff --git a/libs/link/types/modules/BrowserWindowTracker.d.ts b/libs/link/types/modules/BrowserWindowTracker.d.ts index f8ac3af..0f10336 100644 --- a/libs/link/types/modules/BrowserWindowTracker.d.ts +++ b/libs/link/types/modules/BrowserWindowTracker.d.ts @@ -5,9 +5,7 @@ declare module 'resource://app/modules/BrowserWindowTracker.sys.mjs' { import type { Emitter } from 'resource://app/modules/mitt.sys.mjs' - // TODO: Replace this with the correct tab type - // eslint-disable-next-line @typescript-eslint/no-explicit-any - type Tab = any + type Tab = import('@browser/tabs').WindowTab export type WindowTrackerEvents = { windowCreated: Window & typeof globalThis @@ -35,6 +33,10 @@ declare module 'resource://app/modules/BrowserWindowTracker.sys.mjs' { getWindowById(wid: number): typeof window | undefined + getWindowWithBrowserId( + browserId: number, + ): { window: Window & typeof globalThis; tab: Tab } | null + getWindowWithBrowser( browser: XULBrowserElement, ): { window: Window & typeof globalThis; tab: Tab } | null