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

Chrome types update #614

Merged
merged 3 commits into from
Feb 3, 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: 17 additions & 1 deletion dev/data/manifest-variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"name": "Yomitan",
"version": "$YOMITAN_VERSION",
"description": "Japanese dictionary with Anki integration",
"author": "TheMoeWay",
"author": {
"email": "[email protected]"
},
"icons": {
"16": "images/icon16.png",
"19": "images/icon19.png",
Expand Down Expand Up @@ -178,6 +180,13 @@
"inherit": "base",
"fileName": "yomitan-firefox.zip",
"modifications": [
{
"action": "set",
"path": [
"author"
],
"value": "TheMoeWay"
},
{
"action": "delete",
"path": [
Expand Down Expand Up @@ -312,6 +321,13 @@
{
"name": "safari",
"modifications": [
{
"action": "set",
"path": [
"author"
],
"value": "TheMoeWay"
},
{
"action": "remove",
"path": [
Expand Down
8 changes: 4 additions & 4 deletions ext/js/background/offscreen-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class OffscreenProxy {
*/
async _hasOffscreenDocument() {
const offscreenUrl = chrome.runtime.getURL('offscreen.html');
// @ts-expect-error - API not defined yet
if (!chrome.runtime.getContexts) { // chrome version below 116
// Clients: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/clients
// @ts-expect-error - Types not set up for service workers yet
Expand All @@ -68,12 +67,13 @@ export class OffscreenProxy {
return await matchedClients.some((client) => client.url === offscreenUrl);
}

// @ts-expect-error - API not defined yet
const contexts = await chrome.runtime.getContexts({
contextTypes: ['OFFSCREEN_DOCUMENT'],
contextTypes: [
/** @type {chrome.runtime.ContextType} */ ('OFFSCREEN_DOCUMENT')
],
documentUrls: [offscreenUrl]
});
return !!contexts.length;
return contexts.length > 0;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@stylistic/stylelint-plugin": "^2.0.0",
"@types/assert": "^1.5.10",
"@types/browserify": "^12.0.40",
"@types/chrome": "^0.0.254",
"@types/chrome": "^0.0.260",
"@types/css": "^0.0.37",
"@types/events": "^3.0.3",
"@types/firefox-webext-browser": "^120.0.0",
Expand Down
10 changes: 9 additions & 1 deletion types/dev/manifest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

export type Manifest = chrome.runtime.Manifest;
/**
* These overrides provide compatibility between the default chrome types and the minor
* differences that other browsers such as Firefox use.
*/
export type ManifestOverrides = {
author?: chrome.runtime.Manifest['author'] | string;
};

export type Manifest = Omit<chrome.runtime.Manifest, keyof ManifestOverrides> & ManifestOverrides;

export type ManifestConfig = {
manifest: Manifest;
Expand Down
Loading