diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-03-10 20:29:15 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-03-10 20:29:15 -0500 |
commit | 55ac05eba147edb3cc81e9f302055c15cf7fd7a4 (patch) | |
tree | d2a1de37430a29199b3e4028544239275daa5014 /ext/js | |
parent | 2acd9bd45d23838bbee61561aaa05c1443d5ebb0 (diff) |
Fix permissions changes not being supported on some browsers (#1513)
Diffstat (limited to 'ext/js')
-rw-r--r-- | ext/js/background/backend.js | 13 | ||||
-rw-r--r-- | ext/js/pages/settings/settings-controller.js | 10 |
2 files changed, 18 insertions, 5 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 9b35e9b1..5ab1b5bd 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -180,9 +180,11 @@ class Backend { const onMessage = this._onMessageWrapper.bind(this); chrome.runtime.onMessage.addListener(onMessage); - const onPermissionsChanged = this._onWebExtensionEventWrapper(this._onPermissionsChanged.bind(this)); - chrome.permissions.onAdded.addListener(onPermissionsChanged); - chrome.permissions.onRemoved.addListener(onPermissionsChanged); + if (this._canObservePermissionsChanges()) { + const onPermissionsChanged = this._onWebExtensionEventWrapper(this._onPermissionsChanged.bind(this)); + chrome.permissions.onAdded.addListener(onPermissionsChanged); + chrome.permissions.onRemoved.addListener(onPermissionsChanged); + } } async _prepareInternal() { @@ -2088,7 +2090,12 @@ class Backend { this._updateBadge(); } + _canObservePermissionsChanges() { + return isObject(chrome.permissions) && isObject(chrome.permissions.onAdded) && isObject(chrome.permissions.onRemoved); + } + _hasRequiredPermissionsForSettings(options) { + if (!this._canObservePermissionsChanges()) { return true; } return this._permissions === null || this._permissionsUtil.hasRequiredPermissionsForOptions(this._permissions, options); } } diff --git a/ext/js/pages/settings/settings-controller.js b/ext/js/pages/settings/settings-controller.js index 4a86470d..5fa5b660 100644 --- a/ext/js/pages/settings/settings-controller.js +++ b/ext/js/pages/settings/settings-controller.js @@ -51,8 +51,10 @@ 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)); + if (this._canObservePermissionsChanges()) { + chrome.permissions.onAdded.addListener(this._onPermissionsChanged.bind(this)); + chrome.permissions.onRemoved.addListener(this._onPermissionsChanged.bind(this)); + } } async refresh() { @@ -206,4 +208,8 @@ class SettingsController extends EventDispatcher { const permissions = await this._permissionsUtil.getAllPermissions(); this.trigger(event, {permissions}); } + + _canObservePermissionsChanges() { + return isObject(chrome.permissions) && isObject(chrome.permissions.onAdded) && isObject(chrome.permissions.onRemoved); + } } |