diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-26 19:58:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-26 19:58:58 -0500 |
commit | 898498c8a33c0a2d1af9a4177852cc6c00c32f53 (patch) | |
tree | a0932dbb6a3a84361c12b39dec9669dec9674cf3 /ext/bg/js/settings/clipboard-popups-controller.js | |
parent | 8d292363d4d7363134a66e6d35e549f4634521a1 (diff) |
Clipboard settings organization (#1319)
* Create clipboard icon
* Move clipboard options
* Update clipboard options
* Update labels
* Add info
* Update all clipboard settings to request permissions
Diffstat (limited to 'ext/bg/js/settings/clipboard-popups-controller.js')
-rw-r--r-- | ext/bg/js/settings/clipboard-popups-controller.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/ext/bg/js/settings/clipboard-popups-controller.js b/ext/bg/js/settings/clipboard-popups-controller.js index fcff444c..ab1a8288 100644 --- a/ext/bg/js/settings/clipboard-popups-controller.js +++ b/ext/bg/js/settings/clipboard-popups-controller.js @@ -15,14 +15,22 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/* global + * ObjectPropertyAccessor + */ + class ClipboardPopupsController { constructor(settingsController) { this._settingsController = settingsController; - this._checkbox = document.querySelector('#clipboard-enable-background-monitor'); + this._toggles = null; } async prepare() { - this._checkbox.addEventListener('change', this._onEnableBackgroundMonitorChanged.bind(this), false); + this._toggles = document.querySelectorAll('.clipboard-toggle'); + + for (const toggle of this._toggles) { + toggle.addEventListener('change', this._onClipboardToggleChange.bind(this), false); + } this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); const options = await this._settingsController.getOptions(); @@ -32,10 +40,20 @@ class ClipboardPopupsController { // Private _onOptionsChanged({options}) { - this._checkbox.checked = options.clipboard.enableBackgroundMonitor; + const accessor = new ObjectPropertyAccessor(options); + for (const toggle of this._toggles) { + const path = ObjectPropertyAccessor.getPathArray(toggle.dataset.clipboardSetting); + let value; + try { + value = accessor.get(path, path.length); + } catch (e) { + continue; + } + toggle.checked = !!value; + } } - async _onEnableBackgroundMonitorChanged(e) { + async _onClipboardToggleChange(e) { const checkbox = e.currentTarget; let value = checkbox.checked; |