From 898498c8a33c0a2d1af9a4177852cc6c00c32f53 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Jan 2021 19:58:58 -0500 Subject: Clipboard settings organization (#1319) * Create clipboard icon * Move clipboard options * Update clipboard options * Update labels * Add info * Update all clipboard settings to request permissions --- ext/bg/js/settings/clipboard-popups-controller.js | 26 +++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'ext/bg/js') 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 . */ +/* 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; -- cgit v1.2.3