Skip to content

Commit

Permalink
Chrome types update (#614)
Browse files Browse the repository at this point in the history
* Update chrome types

* Fix issues

* Update manifest author
  • Loading branch information
toasted-nutbread authored Feb 3, 2024
1 parent 17ffea6 commit d7db65a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
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

0 comments on commit d7db65a

Please sign in to comment.