summaryrefslogtreecommitdiff
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.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/ext/bg/js/settings/settings-controller.js b/ext/bg/js/settings/settings-controller.js
index e59ab7db..a3885ef6 100644
--- a/ext/bg/js/settings/settings-controller.js
+++ b/ext/bg/js/settings/settings-controller.js
@@ -46,6 +46,8 @@ class SettingsController extends EventDispatcher {
prepare() {
yomichan.on('optionsUpdated', this._onOptionsUpdated.bind(this));
+ chrome.permissions.onAdded.addListener(this._onPermissionsChanged.bind(this));
+ chrome.permissions.onRemoved.addListener(this._onPermissionsChanged.bind(this));
}
async refresh() {
@@ -165,6 +167,17 @@ class SettingsController extends EventDispatcher {
);
}
+ 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) {
@@ -220,4 +233,16 @@ class SettingsController extends EventDispatcher {
this._pageExitPreventionEventListeners.removeAllEventListeners();
}
}
+
+ _onPermissionsChanged() {
+ this._triggerPermissionsChanged();
+ }
+
+ async _triggerPermissionsChanged() {
+ const event = 'permissionsChanged';
+ if (!this.hasListeners(event)) { return; }
+
+ const permissions = await this.getAllPermissions();
+ this.trigger(event, {permissions});
+ }
}