Skip to content

Commit

Permalink
♻️ Scope window api
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Dec 8, 2023
1 parent 897f056 commit 69b7d78
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/actors/ContextMenuParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ContextMenuParent extends JSWindowActorParent {
receiveMessage(event: ContextMenuEvent) {
if (event.name == 'contextmenu') {
const win = event.target.browsingContext.embedderElement.ownerGlobal
win.windowApi.showContextMenu(event.data, this)
win.windowApi.contextMenu.showContextMenu(event.data, this)
}
}
}
51 changes: 29 additions & 22 deletions src/content/browser/lib/window/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,37 @@ export type WindowTriggers = {

export const windowApi = {
windowTriggers: mitt<WindowTriggers>(),
closeTab,
openTab,
get tabs() {
return tabs.readOnce()
tabs: {
closeTab,
openTab,
get tabs() {
return tabs.readOnce()
},
setIcon: (browser: XULBrowserElement, iconURL: string) =>
tabs
.readOnce()
.find((tab) => tab.getTabId() == browser.browserId)
?.icon.set(iconURL),
},
setIcon: (browser: XULBrowserElement, iconURL: string) =>
tabs
.readOnce()
.find((tab) => tab.getTabId() == browser.browserId)
?.icon.set(iconURL),
showContextMenu: (menuInfo: ContextMenuInfo, actor: JSWindowActorParent) => {
browserContextMenuInfo.set(menuInfo)
setContextMenuParentActor(actor)
contextMenu: {
showContextMenu: (
menuInfo: ContextMenuInfo,
actor: JSWindowActorParent,
) => {
browserContextMenuInfo.set(menuInfo)
setContextMenuParentActor(actor)

requestAnimationFrame(() => {
const contextMenu = document.getElementById(
'browser_context_menu',
) as XULMenuPopup
contextMenu.openPopupAtScreen(
menuInfo.position.screenX,
menuInfo.position.screenY,
true,
)
})
requestAnimationFrame(() => {
const contextMenu = document.getElementById(
'browser_context_menu',
) as XULMenuPopup
contextMenu.openPopupAtScreen(
menuInfo.position.screenX,
menuInfo.position.screenY,
true,
)
})
},
},
}

Expand Down
3 changes: 1 addition & 2 deletions src/content/shared/customizableUI/items.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* 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/. */

import { readable } from 'svelte/store'

import type { Component, ExportComponent } from '.'
Expand Down Expand Up @@ -67,7 +66,7 @@ export const cuiPreviewItems: CUIPreviewItem[] = [
type: 'icon',
icon: 'add-line',
enabled: ALWAYS_ENABLE,
action: () => window.windowApi.openTab(),
action: () => window.windowApi.tabs.openTab(),
},
},
{
Expand Down

0 comments on commit 69b7d78

Please sign in to comment.