aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/settings')
-rw-r--r--ext/bg/js/settings/anki-controller.js9
-rw-r--r--ext/bg/js/settings/clipboard-popups-controller.js4
-rw-r--r--ext/bg/js/settings/settings-controller.js33
3 files changed, 35 insertions, 11 deletions
diff --git a/ext/bg/js/settings/anki-controller.js b/ext/bg/js/settings/anki-controller.js
index e7c8db15..26abebeb 100644
--- a/ext/bg/js/settings/anki-controller.js
+++ b/ext/bg/js/settings/anki-controller.js
@@ -339,14 +339,7 @@ class AnkiController {
}
async _requestClipboardReadPermission() {
- const permissions = ['clipboardRead'];
-
- if (await new Promise((resolve) => chrome.permissions.contains({permissions}, resolve))) {
- // Already has permission
- return;
- }
-
- return await new Promise((resolve) => chrome.permissions.request({permissions}, resolve));
+ return await this._settingsController.setPermissionsGranted(['clipboardRead'], true);
}
_getFieldMarkers(fieldValue) {
diff --git a/ext/bg/js/settings/clipboard-popups-controller.js b/ext/bg/js/settings/clipboard-popups-controller.js
index ab1a8288..ec1d20ec 100644
--- a/ext/bg/js/settings/clipboard-popups-controller.js
+++ b/ext/bg/js/settings/clipboard-popups-controller.js
@@ -58,9 +58,7 @@ class ClipboardPopupsController {
let value = checkbox.checked;
if (value) {
- value = await new Promise((resolve) => {
- chrome.permissions.request({permissions: ['clipboardRead']}, resolve);
- });
+ value = await this._settingsController.setPermissionsGranted(['clipboardRead'], true);
checkbox.checked = value;
}
diff --git a/ext/bg/js/settings/settings-controller.js b/ext/bg/js/settings/settings-controller.js
index 107e8004..e59ab7db 100644
--- a/ext/bg/js/settings/settings-controller.js
+++ b/ext/bg/js/settings/settings-controller.js
@@ -132,6 +132,39 @@ class SettingsController extends EventDispatcher {
return optionsFull;
}
+ hasPermissions(permissions) {
+ return new Promise((resolve, reject) => chrome.permissions.contains({permissions}, (result) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(result);
+ }
+ }));
+ }
+
+ setPermissionsGranted(permissions, shouldHave) {
+ return (
+ shouldHave ?
+ new Promise((resolve, reject) => chrome.permissions.request({permissions}, (result) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(result);
+ }
+ })) :
+ new Promise((resolve, reject) => chrome.permissions.remove({permissions}, (result) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(!result);
+ }
+ }))
+ );
+ }
+
// Private
_setProfileIndex(value) {