From 8d292363d4d7363134a66e6d35e549f4634521a1 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 26 Jan 2021 18:30:01 -0500 Subject: Update clipboard options organization (#1318) * Update options organization * Update general.enableClipboardPopups to clipboard.enableBackgroundMonitor * Update general.enableClipboardMonitor to clipboard.enableSearchPageMonitor * Update general.maximumClipboardSearchLength to clipboard.maximumSearchLength * Update general.autoSearchClipboardContent to clipboard.autoSearchContent --- ext/bg/data/options-schema.json | 54 +++++++++++++---------- ext/bg/js/backend.js | 8 ++-- ext/bg/js/options.js | 17 +++++-- ext/bg/js/search.js | 12 ++--- ext/bg/js/settings/clipboard-popups-controller.js | 10 ++--- ext/bg/settings.html | 2 +- ext/bg/settings2.html | 6 +-- 7 files changed, 63 insertions(+), 46 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json index b03f0234..f4f5d0ca 100644 --- a/ext/bg/data/options-schema.json +++ b/ext/bg/data/options-schema.json @@ -71,14 +71,14 @@ "parsing", "anki", "sentenceParsing", - "inputs" + "inputs", + "clipboard" ], "properties": { "general": { "type": "object", "required": [ "enable", - "enableClipboardPopups", "resultOutputMode", "debugInfo", "maxResults", @@ -104,7 +104,6 @@ "customPopupCss", "customPopupOuterCss", "enableWanakana", - "enableClipboardMonitor", "showPitchAccentDownstepNotation", "showPitchAccentPositionNotation", "showPitchAccentGraph", @@ -112,21 +111,15 @@ "useSecurePopupFrameUrl", "usePopupShadowDom", "usePopupWindow", - "maximumClipboardSearchLength", "popupCurrentIndicatorMode", "popupActionBarVisibility", - "popupActionBarLocation", - "autoSearchClipboardContent" + "popupActionBarLocation" ], "properties": { "enable": { "type": "boolean", "default": true }, - "enableClipboardPopups": { - "type": "boolean", - "default": false - }, "resultOutputMode": { "type": "string", "enum": ["group", "merge", "split"], @@ -236,10 +229,6 @@ "type": "boolean", "default": true }, - "enableClipboardMonitor": { - "type": "boolean", - "default": false - }, "showPitchAccentDownstepNotation": { "type": "boolean", "default": true @@ -268,11 +257,6 @@ "type": "boolean", "default": false }, - "maximumClipboardSearchLength": { - "type": "integer", - "default": 1000, - "minimum": 0 - }, "popupCurrentIndicatorMode": { "type": "string", "enum": ["none", "asterisk", "triangle", "bar-left", "bar-right", "dot-left", "dot-right"], @@ -287,10 +271,6 @@ "type": "string", "enum": ["left", "right", "top", "bottom"], "default": "top" - }, - "autoSearchClipboardContent": { - "type": "boolean", - "default": true } } }, @@ -1053,6 +1033,34 @@ ] } } + }, + "clipboard": { + "type": "object", + "required": [ + "enableBackgroundMonitor", + "enableSearchPageMonitor", + "autoSearchContent", + "maximumSearchLength" + ], + "properties": { + "enableBackgroundMonitor": { + "type": "boolean", + "default": false + }, + "enableSearchPageMonitor": { + "type": "boolean", + "default": false + }, + "autoSearchContent": { + "type": "boolean", + "default": true + }, + "maximumSearchLength": { + "type": "integer", + "default": 1000, + "minimum": 0 + } + } } } } diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index fb0596d5..9a8844c5 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -233,9 +233,9 @@ class Backend { // Event handlers async _onClipboardTextChange({text}) { - const {general: {maximumClipboardSearchLength}} = this._getProfileOptions({current: true}); - if (text.length > maximumClipboardSearchLength) { - text = text.substring(0, maximumClipboardSearchLength); + const {clipboard: {maximumSearchLength}} = this._getProfileOptions({current: true}); + if (text.length > maximumSearchLength) { + text = text.substring(0, maximumSearchLength); } try { const {tab, created} = await this._getOrCreateSearchPopup(); @@ -912,7 +912,7 @@ class Backend { this._mecab.stopListener(); } - if (options.general.enableClipboardPopups) { + if (options.clipboard.enableBackgroundMonitor) { this._clipboardMonitor.start(); } else { this._clipboardMonitor.stop(); diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 14b858aa..02caa5a2 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -669,8 +669,10 @@ class OptionsUtil { // Updated handlebars templates to include "stroke-count" definition. // Updated global.useSettingsV2 to be true (opt-out). // Added audio.customSourceType. - // Added general.autoSearchClipboardContent. - // Forced general.enableClipboardMonitor to false due to a bug which caused its value to not be read. + // Moved general.enableClipboardPopups => clipboard.enableBackgroundMonitor. + // Moved general.enableClipboardMonitor => clipboard.enableSearchPageMonitor. Forced value to false due to a bug which caused its value to not be read. + // Moved general.maximumClipboardSearchLength => clipboard.maximumSearchLength. + // Added clipboard.autoSearchContent. await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v8.handlebars'); options.global.useSettingsV2 = true; for (const profile of options.profiles) { @@ -730,8 +732,15 @@ class OptionsUtil { windowState: 'normal' }; profile.options.audio.customSourceType = 'audio'; - profile.options.general.autoSearchClipboardContent = true; - profile.options.general.enableClipboardMonitor = false; + profile.options.clipboard = { + enableBackgroundMonitor: profile.options.general.enableClipboardPopups, + enableSearchPageMonitor: false, + autoSearchContent: true, + maximumSearchLength: profile.options.general.maximumClipboardSearchLength + }; + delete profile.options.general.enableClipboardPopups; + delete profile.options.general.enableClipboardMonitor; + delete profile.options.general.maximumClipboardSearchLength; } return options; } diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index c17ae1ac..27cba50f 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -126,7 +126,7 @@ class DisplaySearch extends Display { } _onDisplayOptionsUpdated({options}) { - this._clipboardMonitorEnabled = options.general.enableClipboardMonitor; + this._clipboardMonitorEnabled = options.clipboard.enableSearchPageMonitor; this._updateClipboardMonitorEnabled(); } @@ -182,13 +182,13 @@ class DisplaySearch extends Display { } _onExternalSearchUpdate({text, animate=true}) { - const {general: {maximumClipboardSearchLength, autoSearchClipboardContent}} = this.getOptions(); - if (text.length > maximumClipboardSearchLength) { - text = text.substring(0, maximumClipboardSearchLength); + const {clipboard: {autoSearchContent, maximumSearchLength}} = this.getOptions(); + if (text.length > maximumSearchLength) { + text = text.substring(0, maximumSearchLength); } this._queryInput.value = text; this._updateSearchHeight(true); - this._search(animate, false, autoSearchClipboardContent); + this._search(animate, false, autoSearchContent); } _onWanakanaEnableChange(e) { @@ -303,7 +303,7 @@ class DisplaySearch extends Display { await api.modifySettings([{ action: 'set', - path: 'general.enableClipboardMonitor', + path: 'clipboard.enableSearchPageMonitor', value, scope: 'profile', optionsContext: this.getOptionsContext() diff --git a/ext/bg/js/settings/clipboard-popups-controller.js b/ext/bg/js/settings/clipboard-popups-controller.js index 810b1bc6..fcff444c 100644 --- a/ext/bg/js/settings/clipboard-popups-controller.js +++ b/ext/bg/js/settings/clipboard-popups-controller.js @@ -18,11 +18,11 @@ class ClipboardPopupsController { constructor(settingsController) { this._settingsController = settingsController; - this._checkbox = document.querySelector('#enable-clipboard-popups'); + this._checkbox = document.querySelector('#clipboard-enable-background-monitor'); } async prepare() { - this._checkbox.addEventListener('change', this._onEnableClipboardPopupsChanged.bind(this), false); + this._checkbox.addEventListener('change', this._onEnableBackgroundMonitorChanged.bind(this), false); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); const options = await this._settingsController.getOptions(); @@ -32,10 +32,10 @@ class ClipboardPopupsController { // Private _onOptionsChanged({options}) { - this._checkbox.checked = options.general.enableClipboardPopups; + this._checkbox.checked = options.clipboard.enableBackgroundMonitor; } - async _onEnableClipboardPopupsChanged(e) { + async _onEnableBackgroundMonitorChanged(e) { const checkbox = e.currentTarget; let value = checkbox.checked; @@ -46,6 +46,6 @@ class ClipboardPopupsController { checkbox.checked = value; } - await this._settingsController.setProfileSetting('general.enableClipboardPopups', value); + await this._settingsController.setProfileSetting('clipboard.enableBackgroundMonitor', value); } } diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 71da3fb3..208ac27c 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -162,7 +162,7 @@
- +
diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html index ba37c860..c8c35c3d 100644 --- a/ext/bg/settings2.html +++ b/ext/bg/settings2.html @@ -960,7 +960,7 @@
- +
- +
@@ -997,7 +997,7 @@
Change how the search page reacts to new text in the clipboard.
-