aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/permissions-util.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/data/permissions-util.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/data/permissions-util.js')
-rw-r--r--ext/js/data/permissions-util.js22
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);