aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings/settings-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-11 18:55:09 -0500
committerGitHub <noreply@github.com>2021-02-11 18:55:09 -0500
commit94db6c69fa4aa25231e213c6d0e185197bfe3418 (patch)
tree711696bc44954c7e480ac7ed6d528f11dd2ac580 /ext/bg/js/settings/settings-controller.js
parent07cd006127c23c17e5c750122a4ac6916994bc76 (diff)
Permissions button in browser action popup (#1368)
* Add key icon * Update context icon styles * Add permissions links * Show warning badge if permissions are insufficient for certain settings * Create PermissionsUtil * Use PermissionsUtil in Backend * Update SettingsController to use PermissionsUtil * Update AnkiController to use getRequiredPermissionsForAnkiFieldValue * Show the permissions buttons/links on the context page when necessary * Update MV3 compatibility
Diffstat (limited to 'ext/bg/js/settings/settings-controller.js')
-rw-r--r--ext/bg/js/settings/settings-controller.js52
1 files changed, 7 insertions, 45 deletions
diff --git a/ext/bg/js/settings/settings-controller.js b/ext/bg/js/settings/settings-controller.js
index a3885ef6..11a9435c 100644
--- a/ext/bg/js/settings/settings-controller.js
+++ b/ext/bg/js/settings/settings-controller.js
@@ -18,6 +18,7 @@
/* global
* HtmlTemplateCollection
* OptionsUtil
+ * PermissionsUtil
* api
*/
@@ -29,6 +30,7 @@ class SettingsController extends EventDispatcher {
this._pageExitPreventions = new Set();
this._pageExitPreventionEventListeners = new EventListenerCollection();
this._templates = new HtmlTemplateCollection(document);
+ this._permissionsUtil = new PermissionsUtil();
}
get source() {
@@ -44,6 +46,10 @@ class SettingsController extends EventDispatcher {
this._setProfileIndex(value);
}
+ get permissionsUtil() {
+ return this._permissionsUtil;
+ }
+
prepare() {
yomichan.on('optionsUpdated', this._onOptionsUpdated.bind(this));
chrome.permissions.onAdded.addListener(this._onPermissionsChanged.bind(this));
@@ -134,50 +140,6 @@ 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);
- }
- }))
- );
- }
-
- getAllPermissions() {
- return new Promise((resolve, reject) => chrome.permissions.getAll((result) => {
- const e = chrome.runtime.lastError;
- if (e) {
- reject(new Error(e.message));
- } else {
- resolve(result);
- }
- }));
- }
-
// Private
_setProfileIndex(value) {
@@ -242,7 +204,7 @@ class SettingsController extends EventDispatcher {
const event = 'permissionsChanged';
if (!this.hasListeners(event)) { return; }
- const permissions = await this.getAllPermissions();
+ const permissions = await this._permissionsUtil.getAllPermissions();
this.trigger(event, {permissions});
}
}