-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Implement
browser_action
manifest key backend
- Loading branch information
Showing
24 changed files
with
507 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// @ts-check | ||
/// <reference path="../types/index.d.ts" /> | ||
/// <reference path="./ext-browser.js" /> | ||
/// <reference types="@browser/link" /> | ||
|
||
this.browserAction = class extends ExtensionAPIPersistent { | ||
/** @type {import("resource://app/modules/EBrowserActions.sys.mjs").IBrowserAction | undefined} */ | ||
browserAction | ||
|
||
async onManifestEntry() { | ||
const { extension } = this | ||
/** @type {browser_action__manifest.WebExtensionManifest__extended['browser_action']} */ | ||
const options = extension.manifest.browser_action | ||
|
||
if (!options) { | ||
return | ||
} | ||
|
||
this.browserAction = lazy.EBrowserActions.BrowserAction(extension.id, { | ||
icons: lazy.ExtensionParent.IconDetails.normalize( | ||
{ | ||
path: options.default_icon || extension.manifest.icons, | ||
iconType: 'browserAction', | ||
themeIcon: options.theme_icons, | ||
}, | ||
extension, | ||
), | ||
title: options.default_title || extension.id, | ||
popupUrl: options.default_popup, | ||
}) | ||
|
||
lazy.EBrowserActions.actions.addKey(extension.id, this.browserAction) | ||
} | ||
|
||
onShutdown() { | ||
lazy.EBrowserActions.actions.removeKey(this.extension.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[ | ||
{ | ||
"namespace": "manifest", | ||
"types": [ | ||
{ | ||
"$extend": "WebExtensionManifest", | ||
"properties": { | ||
"browser_action": { | ||
"type": "object", | ||
"optional": true, | ||
"properties": { | ||
"default_icon": { | ||
"optional": true, | ||
"$ref": "IconPath" | ||
}, | ||
"default_popup": { | ||
"optional": true, | ||
"type": "string" | ||
}, | ||
"default_title": { | ||
"optional": true, | ||
"type": "string" | ||
}, | ||
"theme_icons": { | ||
"optional": true, | ||
"type": "array", | ||
"items": { "$ref": "ThemeIcons" } | ||
}, | ||
"browser_style": { | ||
"optional": true, | ||
"type": "boolean" | ||
}, | ||
"default_area": { | ||
"optional": true, | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
"types": [ | ||
{ | ||
"$extend": "OptionalPermission", | ||
"id": "ExtraPerms1", | ||
"choices": [ | ||
{ | ||
"type": "string", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// @ts-check | ||
/// <reference types="@browser/link" /> | ||
import { map, writable } from 'resource://app/modules/SvelteStore.sys.mjs' | ||
import mitt from 'resource://app/modules/mitt.sys.mjs' | ||
|
||
import { derived } from './SvelteStore.sys.mjs' | ||
|
||
/** @typedef {import('resource://app/modules/EBrowserActions.sys.mjs').IBrowserAction} IBrowserAction */ | ||
/** @implements {IBrowserAction} */ | ||
class BrowserAction { | ||
id | ||
/** @type {ReturnType<IBrowserAction['getEmmiter']>} */ | ||
emmiter = mitt() | ||
|
||
/** @type{import('resource://app/modules/SvelteStore.sys.mjs').IWritable<Record<number, string>>} */ | ||
icons = writable({}) | ||
/** @type {import('resource://app/modules/SvelteStore.sys.mjs').IWritable<string>} */ | ||
title = writable('') | ||
/** @type {import('resource://app/modules/SvelteStore.sys.mjs').IWritable<string | undefined>} */ | ||
popupUrl = writable(undefined) | ||
|
||
/** | ||
* @param {string} id | ||
*/ | ||
constructor(id) { | ||
this.id = id | ||
} | ||
|
||
getEmmiter() { | ||
return this.emmiter | ||
} | ||
|
||
getExtensionId() { | ||
return this.id | ||
} | ||
|
||
/** | ||
* @param {Record<number, string>} icons | ||
*/ | ||
setIcons(icons) { | ||
this.icons.set(icons) | ||
} | ||
getIcons() { | ||
return this.icons | ||
} | ||
/** @param {number} preferredSize */ | ||
getIcon(preferredSize) { | ||
return derived([this.icons], (icon) => { | ||
let bestSize | ||
|
||
if (icon[preferredSize]) { | ||
bestSize = preferredSize | ||
} else if (icon[preferredSize * 2]) { | ||
bestSize = preferredSize * 2 | ||
} else { | ||
const sizes = Object.keys(icon) | ||
.map((key) => parseInt(key, 10)) | ||
.sort((a, b) => a - b) | ||
bestSize = | ||
sizes.find((candidate) => candidate > preferredSize) || | ||
sizes.pop() || | ||
0 | ||
} | ||
|
||
return icon[bestSize] | ||
}) | ||
} | ||
|
||
setTitle(title) { | ||
this.title.set(title) | ||
} | ||
getTitle() { | ||
return this.title | ||
} | ||
|
||
setPopupUrl(url) { | ||
this.popupUrl.set(url) | ||
} | ||
getPopupUrl() { | ||
return this.popupUrl | ||
} | ||
} | ||
|
||
/** @type {typeof import('resource://app/modules/EBrowserActions.sys.mjs').EBrowserActions} */ | ||
export const EBrowserActions = { | ||
BrowserAction: (id, options) => { | ||
const action = new BrowserAction(id) | ||
|
||
action.setIcons(options.icons) | ||
action.setTitle(options.title) | ||
action.setPopupUrl(options.popupUrl) | ||
|
||
return action | ||
}, | ||
actions: map({}), | ||
} | ||
|
||
EBrowserActions.actions.subscribe((a) => console.log(JSON.stringify(a))) |
Oops, something went wrong.