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

✨ First pass tab api implementation #57

Merged
merged 7 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
12 changes: 9 additions & 3 deletions apps/content/src/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
// @ts-check
import BrowserWindow from './BrowserWindow.svelte'
import './browser.css'
import { browserImports } from './browserImports.js'
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>} */
/** @type {Record<string, string | string[]>} */
let args = {}

if (rawArgs && rawArgs instanceof Ci.nsISupports) {
Expand All @@ -18,12 +19,17 @@ if (rawArgs && rawArgs instanceof Ci.nsISupports) {
args = rawArgs
}

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

WindowTabs.initialize(initialUrls)

registerEventBus()

new BrowserWindow({ target: document.body })

browserImports.WindowTracker.registerWindow(window)
window.addEventListener('unload', () =>
browserImports.WindowTracker.removeWindow(window),
)
1 change: 1 addition & 0 deletions apps/content/src/browser/browserImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const browserImports = lazyESModuleGetters({
EPageActions: 'resource://app/modules/EPageActions.sys.mjs',
NetUtil: 'resource://gre/modules/NetUtil.sys.mjs',
PageThumbs: 'resource://gre/modules/PageThumbs.sys.mjs',
WindowTracker: 'resource://app/modules/BrowserWindowTracker.sys.mjs',
})
11 changes: 11 additions & 0 deletions apps/content/src/browser/windowApi/WebsiteView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mitt from 'mitt'
import { readable } from 'svelte/store'

import { browserImports } from '../browserImports.js'
import { createBrowser } from '../utils/browserElement.js'
import { eventBus } from './eventBus.js'

Expand All @@ -31,6 +32,8 @@ export function create(uri) {
const view = {
windowBrowserId: nextWindowBrowserId++,
browser: createBrowser(uri),
uri,
websiteState: 'loading',

/** @type {import('mitt').Emitter<WebsiteViewEvents>} */
events: mitt(),
Expand All @@ -49,6 +52,13 @@ export function create(uri) {
registerViewThemeListener(view)
})

view.events.on('goTo', (e) => goTo(view, browserImports.NetUtil.newURI(e)))
view.events.on('locationChange', (e) => (view.uri = e.aLocation))
view.events.on(
'loadingChange',
(e) => (view.websiteState = e ? 'loading' : 'complete'),
)

eventBus.on('iconUpdate', ({ browserId, iconUrl }) => {
if (view.browser.browserId === browserId) {
view.iconUrl = iconUrl
Expand Down Expand Up @@ -293,6 +303,7 @@ class TabProgressListener {
* @returns {void}
*/
onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {
if (!aWebProgress || !aWebProgress.isTopLevel) return
this.view.events.emit('locationChange', {
aWebProgress,
aRequest,
Expand Down
17 changes: 8 additions & 9 deletions apps/content/src/browser/windowApi/WindowTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
* 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
import { writable } from '@amadeus-it-group/tansu'
import { derived } from 'svelte/store'
import { derived, writable } from '@amadeus-it-group/tansu'

import { browserImports } from '../browserImports.js'
import * as WebsiteViewApi from './WebsiteView.js'

/**
* @typedef {object} WebsiteTab
* @property {'website'} kind
* @property {WebsiteView} view
*/

export const activeTabId = writable(0)

/**
Expand All @@ -23,6 +16,9 @@ export const activeTabId = writable(0)
*/
export const selectedTabIds = writable([])

window.activeTabId = activeTabId
window.selectedTabIds = selectedTabIds

/**
* @param {number[]} ids
*/
Expand Down Expand Up @@ -53,7 +49,7 @@ activeTabId.subscribe((activeId) => {
})

/**
* @type {import('@amadeus-it-group/tansu').WritableSignal<WebsiteTab[]>}
* @type {import('@amadeus-it-group/tansu').WritableSignal<import('@browser/tabs').WindowTabs>}
*/
export const windowTabs = writable([])

Expand All @@ -63,6 +59,9 @@ export const activeTab = derived(
$windowTabs.find((tab) => tab.view.windowBrowserId === $activeTabId),
)

window.windowTabs = windowTabs
window.activeTab = activeTab

/**
* @param {string[]} urls
*/
Expand Down
6 changes: 6 additions & 0 deletions apps/extensions/lib/ext-browser.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"scopes": ["addon_parent"],
"manifest": ["page_action"],
"paths": [["pageAction"]]
},
"tabs": {
"schema": "chrome://bextensions/content/schemas/tabs.json",
"url": "chrome://bextensions/content/parent/ext-tabs.js",
"scopes": ["addon_parent"],
"paths": [["tabs"]]
}
}
2 changes: 0 additions & 2 deletions apps/extensions/lib/parent/ext-pageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ this.pageAction = class extends ExtensionAPIPersistent {
*/
onClicked({ fire }) {
const callback = async (_name, clickInfo) => {
console.log(fire, fire.wakeup, !!fire.wakeup)
if (fire.wakeup) await fire.wakeup()
console.log('fire')
fire.sync(clickInfo)
}

Expand Down
Loading
Loading