diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-11-27 12:48:14 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-11-27 12:48:14 -0500 |
commit | 4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch) | |
tree | a8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/data/permissions-util.js | |
parent | fd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff) |
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/data/permissions-util.js')
-rw-r--r-- | ext/js/data/permissions-util.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ext/js/data/permissions-util.js b/ext/js/data/permissions-util.js index d645f21e..76c5031b 100644 --- a/ext/js/data/permissions-util.js +++ b/ext/js/data/permissions-util.js @@ -20,12 +20,17 @@ import {AnkiUtil} from './anki-util.js'; export class PermissionsUtil { constructor() { + /** @type {Set<string>} */ this._ankiFieldMarkersRequiringClipboardPermission = new Set([ 'clipboard-image', 'clipboard-text' ]); } + /** + * @param {chrome.permissions.Permissions} permissions + * @returns {Promise<boolean>} + */ hasPermissions(permissions) { return new Promise((resolve, reject) => chrome.permissions.contains(permissions, (result) => { const e = chrome.runtime.lastError; @@ -37,6 +42,11 @@ export class PermissionsUtil { })); } + /** + * @param {chrome.permissions.Permissions} permissions + * @param {boolean} shouldHave + * @returns {Promise<boolean>} + */ setPermissionsGranted(permissions, shouldHave) { return ( shouldHave ? @@ -59,6 +69,9 @@ export class PermissionsUtil { ); } + /** + * @returns {Promise<chrome.permissions.Permissions>} + */ getAllPermissions() { return new Promise((resolve, reject) => chrome.permissions.getAll((result) => { const e = chrome.runtime.lastError; @@ -70,6 +83,10 @@ export class PermissionsUtil { })); } + /** + * @param {string} fieldValue + * @returns {string[]} + */ getRequiredPermissionsForAnkiFieldValue(fieldValue) { const markers = AnkiUtil.getFieldMarkers(fieldValue); const markerPermissions = this._ankiFieldMarkersRequiringClipboardPermission; @@ -81,6 +98,11 @@ export class PermissionsUtil { return []; } + /** + * @param {chrome.permissions.Permissions} permissions + * @param {import('settings').ProfileOptions} options + * @returns {boolean} + */ hasRequiredPermissionsForOptions(permissions, options) { const permissionsSet = new Set(permissions.permissions); |