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
This commit is contained in:
toasted-nutbread 2021-01-26 18:30:01 -05:00 committed by GitHub
parent d11cd7b28f
commit 8d292363d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 51 deletions

View File

@ -71,14 +71,14 @@
"parsing", "parsing",
"anki", "anki",
"sentenceParsing", "sentenceParsing",
"inputs" "inputs",
"clipboard"
], ],
"properties": { "properties": {
"general": { "general": {
"type": "object", "type": "object",
"required": [ "required": [
"enable", "enable",
"enableClipboardPopups",
"resultOutputMode", "resultOutputMode",
"debugInfo", "debugInfo",
"maxResults", "maxResults",
@ -104,7 +104,6 @@
"customPopupCss", "customPopupCss",
"customPopupOuterCss", "customPopupOuterCss",
"enableWanakana", "enableWanakana",
"enableClipboardMonitor",
"showPitchAccentDownstepNotation", "showPitchAccentDownstepNotation",
"showPitchAccentPositionNotation", "showPitchAccentPositionNotation",
"showPitchAccentGraph", "showPitchAccentGraph",
@ -112,21 +111,15 @@
"useSecurePopupFrameUrl", "useSecurePopupFrameUrl",
"usePopupShadowDom", "usePopupShadowDom",
"usePopupWindow", "usePopupWindow",
"maximumClipboardSearchLength",
"popupCurrentIndicatorMode", "popupCurrentIndicatorMode",
"popupActionBarVisibility", "popupActionBarVisibility",
"popupActionBarLocation", "popupActionBarLocation"
"autoSearchClipboardContent"
], ],
"properties": { "properties": {
"enable": { "enable": {
"type": "boolean", "type": "boolean",
"default": true "default": true
}, },
"enableClipboardPopups": {
"type": "boolean",
"default": false
},
"resultOutputMode": { "resultOutputMode": {
"type": "string", "type": "string",
"enum": ["group", "merge", "split"], "enum": ["group", "merge", "split"],
@ -236,10 +229,6 @@
"type": "boolean", "type": "boolean",
"default": true "default": true
}, },
"enableClipboardMonitor": {
"type": "boolean",
"default": false
},
"showPitchAccentDownstepNotation": { "showPitchAccentDownstepNotation": {
"type": "boolean", "type": "boolean",
"default": true "default": true
@ -268,11 +257,6 @@
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"maximumClipboardSearchLength": {
"type": "integer",
"default": 1000,
"minimum": 0
},
"popupCurrentIndicatorMode": { "popupCurrentIndicatorMode": {
"type": "string", "type": "string",
"enum": ["none", "asterisk", "triangle", "bar-left", "bar-right", "dot-left", "dot-right"], "enum": ["none", "asterisk", "triangle", "bar-left", "bar-right", "dot-left", "dot-right"],
@ -287,10 +271,6 @@
"type": "string", "type": "string",
"enum": ["left", "right", "top", "bottom"], "enum": ["left", "right", "top", "bottom"],
"default": "top" "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
}
}
} }
} }
} }

View File

@ -233,9 +233,9 @@ class Backend {
// Event handlers // Event handlers
async _onClipboardTextChange({text}) { async _onClipboardTextChange({text}) {
const {general: {maximumClipboardSearchLength}} = this._getProfileOptions({current: true}); const {clipboard: {maximumSearchLength}} = this._getProfileOptions({current: true});
if (text.length > maximumClipboardSearchLength) { if (text.length > maximumSearchLength) {
text = text.substring(0, maximumClipboardSearchLength); text = text.substring(0, maximumSearchLength);
} }
try { try {
const {tab, created} = await this._getOrCreateSearchPopup(); const {tab, created} = await this._getOrCreateSearchPopup();
@ -912,7 +912,7 @@ class Backend {
this._mecab.stopListener(); this._mecab.stopListener();
} }
if (options.general.enableClipboardPopups) { if (options.clipboard.enableBackgroundMonitor) {
this._clipboardMonitor.start(); this._clipboardMonitor.start();
} else { } else {
this._clipboardMonitor.stop(); this._clipboardMonitor.stop();

View File

@ -669,8 +669,10 @@ class OptionsUtil {
// Updated handlebars templates to include "stroke-count" definition. // Updated handlebars templates to include "stroke-count" definition.
// Updated global.useSettingsV2 to be true (opt-out). // Updated global.useSettingsV2 to be true (opt-out).
// Added audio.customSourceType. // Added audio.customSourceType.
// Added general.autoSearchClipboardContent. // Moved general.enableClipboardPopups => clipboard.enableBackgroundMonitor.
// Forced general.enableClipboardMonitor to false due to a bug which caused its value to not be read. // 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'); await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v8.handlebars');
options.global.useSettingsV2 = true; options.global.useSettingsV2 = true;
for (const profile of options.profiles) { for (const profile of options.profiles) {
@ -730,8 +732,15 @@ class OptionsUtil {
windowState: 'normal' windowState: 'normal'
}; };
profile.options.audio.customSourceType = 'audio'; profile.options.audio.customSourceType = 'audio';
profile.options.general.autoSearchClipboardContent = true; profile.options.clipboard = {
profile.options.general.enableClipboardMonitor = false; 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; return options;
} }

View File

@ -126,7 +126,7 @@ class DisplaySearch extends Display {
} }
_onDisplayOptionsUpdated({options}) { _onDisplayOptionsUpdated({options}) {
this._clipboardMonitorEnabled = options.general.enableClipboardMonitor; this._clipboardMonitorEnabled = options.clipboard.enableSearchPageMonitor;
this._updateClipboardMonitorEnabled(); this._updateClipboardMonitorEnabled();
} }
@ -182,13 +182,13 @@ class DisplaySearch extends Display {
} }
_onExternalSearchUpdate({text, animate=true}) { _onExternalSearchUpdate({text, animate=true}) {
const {general: {maximumClipboardSearchLength, autoSearchClipboardContent}} = this.getOptions(); const {clipboard: {autoSearchContent, maximumSearchLength}} = this.getOptions();
if (text.length > maximumClipboardSearchLength) { if (text.length > maximumSearchLength) {
text = text.substring(0, maximumClipboardSearchLength); text = text.substring(0, maximumSearchLength);
} }
this._queryInput.value = text; this._queryInput.value = text;
this._updateSearchHeight(true); this._updateSearchHeight(true);
this._search(animate, false, autoSearchClipboardContent); this._search(animate, false, autoSearchContent);
} }
_onWanakanaEnableChange(e) { _onWanakanaEnableChange(e) {
@ -303,7 +303,7 @@ class DisplaySearch extends Display {
await api.modifySettings([{ await api.modifySettings([{
action: 'set', action: 'set',
path: 'general.enableClipboardMonitor', path: 'clipboard.enableSearchPageMonitor',
value, value,
scope: 'profile', scope: 'profile',
optionsContext: this.getOptionsContext() optionsContext: this.getOptionsContext()

View File

@ -18,11 +18,11 @@
class ClipboardPopupsController { class ClipboardPopupsController {
constructor(settingsController) { constructor(settingsController) {
this._settingsController = settingsController; this._settingsController = settingsController;
this._checkbox = document.querySelector('#enable-clipboard-popups'); this._checkbox = document.querySelector('#clipboard-enable-background-monitor');
} }
async prepare() { 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)); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
const options = await this._settingsController.getOptions(); const options = await this._settingsController.getOptions();
@ -32,10 +32,10 @@ class ClipboardPopupsController {
// Private // Private
_onOptionsChanged({options}) { _onOptionsChanged({options}) {
this._checkbox.checked = options.general.enableClipboardPopups; this._checkbox.checked = options.clipboard.enableBackgroundMonitor;
} }
async _onEnableClipboardPopupsChanged(e) { async _onEnableBackgroundMonitorChanged(e) {
const checkbox = e.currentTarget; const checkbox = e.currentTarget;
let value = checkbox.checked; let value = checkbox.checked;
@ -46,6 +46,6 @@ class ClipboardPopupsController {
checkbox.checked = value; checkbox.checked = value;
} }
await this._settingsController.setProfileSetting('general.enableClipboardPopups', value); await this._settingsController.setProfileSetting('clipboard.enableBackgroundMonitor', value);
} }
} }

View File

@ -162,7 +162,7 @@
</div> </div>
<div class="checkbox options-advanced ignore-form-changes" data-hide-for-browser="firefox-mobile"> <div class="checkbox options-advanced ignore-form-changes" data-hide-for-browser="firefox-mobile">
<label><input type="checkbox" id="enable-clipboard-popups"> Enable native popups when copying Japanese text</label> <label><input type="checkbox" id="clipboard-enable-background-monitor"> Enable native popups when copying Japanese text</label>
</div> </div>
<div class="checkbox options-advanced"> <div class="checkbox options-advanced">

View File

@ -960,7 +960,7 @@
</div> </div>
</div> </div>
<div class="settings-item-right"> <div class="settings-item-right">
<label class="toggle"><input type="checkbox" id="enable-clipboard-popups"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label> <label class="toggle"><input type="checkbox" id="clipboard-enable-background-monitor"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label>
</div> </div>
</div> </div>
<div class="settings-item-children more" hidden> <div class="settings-item-children more" hidden>
@ -988,7 +988,7 @@
<div class="settings-item-description">Limit the number of text characters used when searching clipboard content.</div> <div class="settings-item-description">Limit the number of text characters used when searching clipboard content.</div>
</div> </div>
<div class="settings-item-right"> <div class="settings-item-right">
<input type="number" min="0" step="1" data-setting="general.maximumClipboardSearchLength"> <input type="number" min="0" step="1" data-setting="clipboard.maximumSearchLength">
</div> </div>
</div></div> </div></div>
<div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable"> <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable">
@ -997,7 +997,7 @@
<div class="settings-item-description">Change how the search page reacts to new text in the clipboard.</div> <div class="settings-item-description">Change how the search page reacts to new text in the clipboard.</div>
</div> </div>
<div class="settings-item-right"> <div class="settings-item-right">
<select data-setting="general.autoSearchClipboardContent" <select data-setting="clipboard.autoSearchContent"
data-transform='[ data-transform='[
{ {
"step": "pre", "step": "pre",

View File

@ -259,7 +259,6 @@ function createProfileOptionsUpdatedTestData1() {
return { return {
general: { general: {
enable: true, enable: true,
enableClipboardPopups: false,
resultOutputMode: 'group', resultOutputMode: 'group',
debugInfo: false, debugInfo: false,
maxResults: 32, maxResults: 32,
@ -285,7 +284,6 @@ function createProfileOptionsUpdatedTestData1() {
customPopupCss: '', customPopupCss: '',
customPopupOuterCss: '', customPopupOuterCss: '',
enableWanakana: true, enableWanakana: true,
enableClipboardMonitor: false,
showPitchAccentDownstepNotation: true, showPitchAccentDownstepNotation: true,
showPitchAccentPositionNotation: true, showPitchAccentPositionNotation: true,
showPitchAccentGraph: false, showPitchAccentGraph: false,
@ -293,11 +291,9 @@ function createProfileOptionsUpdatedTestData1() {
useSecurePopupFrameUrl: true, useSecurePopupFrameUrl: true,
usePopupShadowDom: true, usePopupShadowDom: true,
usePopupWindow: false, usePopupWindow: false,
maximumClipboardSearchLength: 1000,
popupCurrentIndicatorMode: 'triangle', popupCurrentIndicatorMode: 'triangle',
popupActionBarVisibility: 'auto', popupActionBarVisibility: 'auto',
popupActionBarLocation: 'top', popupActionBarLocation: 'top'
autoSearchClipboardContent: true
}, },
audio: { audio: {
enabled: true, enabled: true,
@ -469,6 +465,12 @@ function createProfileOptionsUpdatedTestData1() {
useTop: false, useTop: false,
windowType: 'popup', windowType: 'popup',
windowState: 'normal' windowState: 'normal'
},
clipboard: {
enableBackgroundMonitor: false,
enableSearchPageMonitor: false,
autoSearchContent: true,
maximumSearchLength: 1000
} }
}; };
} }