diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-31 11:55:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-31 11:55:11 -0500 |
commit | 08a87bd0075cec19d037573261cca012dacaefb9 (patch) | |
tree | 83a2e4732ebd5428a95a06267153979aa48f3bc6 /ext/bg/js/settings/settings-controller.js | |
parent | 855234a15708d28895145dfad0073a3f07248750 (diff) |
Settings permissions info display (#1338)
* Add getAllPermissions function
* Add permissionsChanged event
* Update ClipboardPopupsController to show permissions validation info
* Add invalid indicator
* Display invalid indicator when permissions are not valid
* Fix border color transition not being necessary on input-suffix-button
Diffstat (limited to 'ext/bg/js/settings/settings-controller.js')
-rw-r--r-- | ext/bg/js/settings/settings-controller.js | 25 |
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}); + } } |