aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings/settings-controller.js
diff options
context:
space:
mode:
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});
}
}