Skip to content

Commit

Permalink
🏷️ Fix windowApi types for globals
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Jan 2, 2024
1 parent 1c4d336 commit 1848665
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 25 deletions.
18 changes: 2 additions & 16 deletions apps/content/src/browser/lib/window/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,12 @@ import {
} from './tabs'
import { id, setId } from './window'

export type WindowTriggers = {
bookmarkCurrentPage: undefined
}

export const windowApi = {
/**
* Identify which window this is. This should be used for actions like tab
* moving that go across windows
*
* Note: You need to wait for the window watcher to register this window
* before you get a valid id
*/
export const windowApi: WindowApi = {
id,

/**
* Sets the window ID. You should only use this if you are the WindowWatcher
*/
setId,

windowTriggers: mitt<WindowTriggers>(),
windowTriggers: mitt(),
window: {
/**
* @todo Move this into BrowserWindowTracker
Expand Down
7 changes: 0 additions & 7 deletions apps/content/src/browser/lib/window/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
* 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/. */

export interface WindowConfiguration {
/**
* The initial page to show when the window is opened
*/
initialUrl: string
}

const defaultWindowConfiguration: WindowConfiguration = {
initialUrl: Services.prefs.getStringPref(
'browser.newwindow.default',
Expand Down
2 changes: 1 addition & 1 deletion apps/content/src/browser/lib/window/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function setCurrentTab(tab: Tab) {
setCurrentTabIndex(index)
}

export function runOnCurrentTab<R>(method: (tab: Tab) => R): R | void {
export function runOnCurrentTab<R>(method: (tab: Tab) => R): R | undefined {
const currentTab = getCurrentTab()
if (currentTab) return method(currentTab)
}
Expand Down
1 change: 0 additions & 1 deletion apps/content/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ declare module '*.txt' {
}

declare interface Window {
windowApi: typeof import('./browser/lib/window/api').windowApi
browserDOMWindow: nsIBrowserDOMWindowType
/**
* Arguments that may be passed into a specific window. We control these types
Expand Down
1 change: 1 addition & 0 deletions libs/link/types/_link.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/// <reference path="./globals/Elements.d.ts" />
/// <reference path="./globals/MatchPattern.d.ts" />
/// <reference path="./globals/MessageManager.d.ts" />
/// <reference path="./globals/WindowApi.d.ts" />

/// <reference path="./interfaces/ClickHandler.d.ts" />
/// <reference path="./interfaces/ContextMenu.d.ts" />
Expand Down
50 changes: 50 additions & 0 deletions libs/link/types/globals/WindowApi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
type WindowTriggers = {
bookmarkCurrentPage: undefined
}

declare interface WindowConfiguration {
/**
* The initial page to show when the window is opened
*/
initialUrl: string
}

declare type WindowApi = {
/**
* Identify which window this is. This should be used for actions like tab
* moving that go across windows
*
* Note: You need to wait for the window watcher to register this window
* before you get a valid id
*/
id: number
/**
* Sets the window ID. You should only use this if you are the WindowWatcher
*/
setId: (id: number) => void

windowTriggers: import('mitt').Emitter<WindowTriggers>

window: {
new: (args?: WindowArguments) => unknown
}

tabs: {
closeTab(tab: Tab): void
openTab(url?: nsIURIType): Tab
runOnCurrentTab<R>(callback: (tab: Tab) => R): R | undefined
setCurrentTab(tab: Tab): void
getCurrentTab(): Tab | undefined
getTabById(id: number): Tab | undefined
tabs: Tab[]
setIcon(browser: XULBrowserElement, iconURL: string): void
}

contextMenu: {
showContextMenu(menuInfo: ContextMenuInfo, actor: JSWindowActorParent): void
}
}

declare interface Window {
windowApi: WindowApi
}

0 comments on commit 1848665

Please sign in to comment.