Skip to content

Commit 7e02b35

Browse files
authored
🐛 Fix ext-browser for new window api (#58)
Small bug fix pr. It: - Removes references to the old `windowApi` object - Improves type inferance - Fixes a bug not caught by old type inferance
1 parent bda4e07 commit 7e02b35

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

apps/extensions/lib/parent/ext-browser.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ const lazy = lazyESModuleGetters({
1919

2020
class TabTracker extends TabTrackerBase {
2121
get activeTab() {
22-
/** @type {any | null} */
2322
const window = lazy.WindowTracker.getActiveWindow()
24-
return window?.windowApi?.tabs?.getCurrentTab()
23+
return window?.activeTab()
2524
}
2625

2726
init() {
@@ -30,30 +29,34 @@ class TabTracker extends TabTrackerBase {
3029
}
3130

3231
/**
33-
* @param {*} nativeTab
32+
* @param {import('@browser/tabs').WindowTab} nativeTab
3433
*/
3534
getId(nativeTab) {
36-
return nativeTab.getTabId()
35+
return nativeTab.view.browserId || -1
3736
}
3837

38+
/**
39+
* @param {number} tabId
40+
* @param {import('@browser/tabs').WindowTab} default_
41+
*/
3942
getTab(tabId, default_) {
40-
const { tab } = lazy.WindowTracker.getWindowWithBrowser(tabId) || {
43+
const { tab } = lazy.WindowTracker.getWindowWithBrowserId(tabId) || {
4144
tab: default_,
4245
}
4346

4447
return tab
4548
}
4649

50+
/**
51+
* @param {XULBrowserElement} browser
52+
*/
4753
getBrowserData(browser) {
4854
const data = lazy.WindowTracker.getWindowWithBrowser(browser)
4955
if (!data) return { windowId: -1, tabId: -1 }
5056

5157
return {
52-
/** @type {number} */
53-
// @ts-expect-error bad imported types
54-
windowId: data.window.windowApi.id,
55-
/** @type {number} */
56-
tabId: data.tab.getTabId(),
58+
windowId: data.window.windowId,
59+
tabId: data.tab.view.browserId || -1,
5760
}
5861
}
5962
}

apps/modules/lib/BrowserWindowTracker.sys.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ export const WindowTracker = {
3737
return this.registeredWindows.get(wid)
3838
},
3939

40-
getWindowWithBrowser(browser) {
40+
getWindowWithBrowserId(browserId) {
4141
for (const window of this.registeredWindows.values()) {
4242
const tab = window
4343
.windowTabs()
44-
.find((t) => t.view.browserId === browser.browserId)
44+
.find((t) => t.view.browserId === browserId)
4545
if (tab) return { window, tab }
4646
}
4747
return null
4848
},
4949

50+
getWindowWithBrowser(browser) {
51+
return this.getWindowWithBrowserId(browser.browserId)
52+
},
53+
5054
focusWindow(id) {
5155
this.activeWindow = id
5256
this.events.emit('focus', this.getActiveWindow())

libs/link/types/modules/BrowserWindowTracker.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
declare module 'resource://app/modules/BrowserWindowTracker.sys.mjs' {
66
import type { Emitter } from 'resource://app/modules/mitt.sys.mjs'
77

8-
// TODO: Replace this with the correct tab type
9-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10-
type Tab = any
8+
type Tab = import('@browser/tabs').WindowTab
119

1210
export type WindowTrackerEvents = {
1311
windowCreated: Window & typeof globalThis
@@ -35,6 +33,10 @@ declare module 'resource://app/modules/BrowserWindowTracker.sys.mjs' {
3533

3634
getWindowById(wid: number): typeof window | undefined
3735

36+
getWindowWithBrowserId(
37+
browserId: number,
38+
): { window: Window & typeof globalThis; tab: Tab } | null
39+
3840
getWindowWithBrowser(
3941
browser: XULBrowserElement,
4042
): { window: Window & typeof globalThis; tab: Tab } | null

0 commit comments

Comments
 (0)