Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Extension test support #56

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/content/src/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@
// @ts-check
import BrowserWindow from './BrowserWindow.svelte'
import './browser.css'
import * as WindowTabs from './windowApi/WindowTabs.js'
import { registerEventBus } from './windowApi/eventBus.js'

// Handle window arguments
let rawArgs = window.arguments && window.arguments[0]
/** @type {Record<string, string>} */
let args = {}

if (rawArgs && rawArgs instanceof Ci.nsISupports) {
args = rawArgs.wrappedJSObject || {}
} else if (rawArgs) {
args = rawArgs
}

const initialUrls = args.initialUrl
? [args.initialUrl]
: ['https://google.com/', 'https://svelte.dev/']

WindowTabs.initialize(initialUrls)

registerEventBus()

new BrowserWindow({ target: document.body })
18 changes: 16 additions & 2 deletions apps/content/src/browser/components/PageAction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@

/** @type {import('resource://app/modules/EPageActions.sys.mjs').PageActionImpl} */
export let pageAction
/** @type {number} */
export let browserViewId

const view = PageActionApi.setup(pageAction)
const icons = PageActionApi.getIcons(view)
const extensionId = pageAction.extensionId
.replace('@', '')
.replace('}', '')
.replace('{', '')
const trigger = view.trigger
const panel = view.panel

Expand Down Expand Up @@ -45,7 +51,11 @@
})
</script>

<UrlBoxButton bind:button={$trigger} on:click={PageActionApi.handleClick(view)}>
<UrlBoxButton
bind:button={$trigger}
on:click={PageActionApi.handleClick(view)}
id={`page-action-icon__${extensionId}--${browserViewId}`}
>
{#if $icons}
<img src={getIconUrlForPreferredSize($icons, 16)} />
{:else}
Expand All @@ -54,7 +64,11 @@
</UrlBoxButton>

{#if pageAction.popupUrl}
<xul:panel bind:this={$panel} class="popup"></xul:panel>
<xul:panel
bind:this={$panel}
class="popup"
id={`page-action-panel__${extensionId}--${browserViewId}`}
></xul:panel>
{/if}

<style>
Expand Down
4 changes: 3 additions & 1 deletion apps/content/src/browser/components/UrlBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@
/>

{#each $pageActions as [_, pageAction]}
<PageAction {pageAction} />
{#if $uri && pageAction.shouldShow($uri.asciiSpec, view.browserId || 0)}
<PageAction {pageAction} browserViewId={view.windowBrowserId} />
{/if}
{/each}

<div
Expand Down
4 changes: 3 additions & 1 deletion apps/content/src/browser/components/UrlBoxButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

<script>
export let disabled = false
/** @type {string | undefined} */
export let id = undefined
/** @type {HTMLButtonElement | undefined} */
export let button = undefined
</script>

<button on:click bind:this={button} {disabled}>
<button on:click bind:this={button} {disabled} {id}>
<slot />
</button>

Expand Down
3 changes: 2 additions & 1 deletion apps/content/src/browser/components/pageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ export function handleClick(view) {
},
})

await buildPanelBrowser(view)
// Panel may not exist if there is no popupUrl
const panel = view.panel()
if (view.panel()) {
panel.openPopup(view.trigger(), 'bottomright topright')
}

await buildPanelBrowser(view)
}
}

Expand Down
28 changes: 13 additions & 15 deletions apps/content/src/browser/windowApi/WindowTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,23 @@ activeTabId.subscribe((activeId) => {
/**
* @type {import('@amadeus-it-group/tansu').WritableSignal<WebsiteTab[]>}
*/
export const windowTabs = writable([
{
kind: 'website',
view: WebsiteViewApi.create(
browserImports.NetUtil.newURI('https://google.com'),
),
},
{
kind: 'website',
view: WebsiteViewApi.create(
browserImports.NetUtil.newURI('https://svelte.dev'),
),
},
])
export const windowTabs = writable([])

export const activeTab = derived(
[activeTabId, windowTabs],
([$activeTabId, $windowTabs]) =>
$windowTabs.find((tab) => tab.view.windowBrowserId === $activeTabId),
)

activeTabId.set(windowTabs()[0].view.windowBrowserId)
/**
* @param {string[]} urls
*/
export function initialize(urls) {
windowTabs.set(
urls.map((url) => ({
kind: 'website',
view: WebsiteViewApi.create(browserImports.NetUtil.newURI(url)),
})),
)
activeTabId.set(windowTabs()[0].view.windowBrowserId)
}
7 changes: 1 addition & 6 deletions apps/content/static/gtests.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ <h1>Test runner</h1>

// @ts-check
/// <reference types="@browser/link" />
console.log('start import')

console.log('import int')

console.log('call')
TestManager.call()
TestManager.report()
</script>
</body>
</html>
1 change: 1 addition & 0 deletions apps/extensions/lib/parent/ext-pageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ this.pageAction = class extends ExtensionAPIPersistent {
const options = extension.manifest.page_action

this.pageAction = new lazy.EPageActions.PageAction({
extensionId: extension.id,
tooltip: options.default_title,
popupUrl: options.default_popup,
showMatches: options.show_matches,
Expand Down
3 changes: 2 additions & 1 deletion apps/modules/lib/EPageActions.sys.mjs
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/. */

/// @ts-check
/// <reference types="@browser/link" />
import mitt from 'resource://app/modules/mitt.sys.mjs'
Expand All @@ -15,6 +14,7 @@ export class PageAction {
/** @type {import('resource://app/modules/EPageActions.sys.mjs').PageActionImpl['events']} */
events = mitt()

extensionId
tooltip
popupUrl
showMatches
Expand All @@ -31,6 +31,7 @@ export class PageAction {
* @param {import('resource://app/modules/EPageActions.sys.mjs').PageActionOptions<string[]>} data
*/
constructor(data) {
this.extensionId = data.extensionId
this.tooltip = data.tooltip
this.popupUrl = data.popupUrl
this.showMatches = new MatchPatternSet(data.showMatches || [])
Expand Down
Loading
Loading