Add functions for modifying mutable options
This commit is contained in:
parent
17277a6450
commit
b1f72905cf
@ -154,7 +154,7 @@ async function _onAnkiModelChanged(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
options.anki[tabId].fields = utilBackgroundIsolate(fields);
|
options.anki[tabId].fields = utilBackgroundIsolate(fields);
|
||||||
await settingsSaveOptions();
|
await settingsSaveOptions();
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ let audioSourceUI = null;
|
|||||||
|
|
||||||
async function audioSettingsInitialize() {
|
async function audioSettingsInitialize() {
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
audioSourceUI = new AudioSourceUI.Container(
|
audioSourceUI = new AudioSourceUI.Container(
|
||||||
options.audio.sources,
|
options.audio.sources,
|
||||||
document.querySelector('.audio-source-list'),
|
document.querySelector('.audio-source-list'),
|
||||||
|
@ -273,7 +273,7 @@ class SettingsDictionaryEntryUI {
|
|||||||
progress.hidden = true;
|
progress.hidden = true;
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
onDatabaseUpdated(options);
|
onDatabaseUpdated(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,7 +360,7 @@ async function dictSettingsInitialize() {
|
|||||||
document.querySelector('#database-enable-prefix-wildcard-searches').addEventListener('change', (e) => onDatabaseEnablePrefixWildcardSearchesChanged(e), false);
|
document.querySelector('#database-enable-prefix-wildcard-searches').addEventListener('change', (e) => onDatabaseEnablePrefixWildcardSearchesChanged(e), false);
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
onDictionaryOptionsChanged(options);
|
onDictionaryOptionsChanged(options);
|
||||||
onDatabaseUpdated(options);
|
onDatabaseUpdated(options);
|
||||||
}
|
}
|
||||||
@ -425,7 +425,7 @@ async function updateMainDictionarySelect(options, dictionaries) {
|
|||||||
async function onDictionaryMainChanged(e) {
|
async function onDictionaryMainChanged(e) {
|
||||||
const value = e.target.value;
|
const value = e.target.value;
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
options.general.mainDictionary = value;
|
options.general.mainDictionary = value;
|
||||||
settingsSaveOptions();
|
settingsSaveOptions();
|
||||||
}
|
}
|
||||||
@ -531,14 +531,14 @@ async function onDictionaryPurge(e) {
|
|||||||
dictionarySpinnerShow(true);
|
dictionarySpinnerShow(true);
|
||||||
|
|
||||||
await utilDatabasePurge();
|
await utilDatabasePurge();
|
||||||
for (const {options} of toIterable((await apiOptionsGetFull()).profiles)) {
|
for (const {options} of toIterable((await getOptionsFullMutable()).profiles)) {
|
||||||
options.dictionaries = utilBackgroundIsolate({});
|
options.dictionaries = utilBackgroundIsolate({});
|
||||||
options.general.mainDictionary = '';
|
options.general.mainDictionary = '';
|
||||||
}
|
}
|
||||||
await settingsSaveOptions();
|
await settingsSaveOptions();
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
onDatabaseUpdated(options);
|
onDatabaseUpdated(options);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
dictionaryErrorsShow([err]);
|
dictionaryErrorsShow([err]);
|
||||||
@ -593,7 +593,7 @@ async function onDictionaryImport(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {result, errors} = await utilDatabaseImport(files[i], updateProgress, importDetails);
|
const {result, errors} = await utilDatabaseImport(files[i], updateProgress, importDetails);
|
||||||
for (const {options} of toIterable((await apiOptionsGetFull()).profiles)) {
|
for (const {options} of toIterable((await getOptionsFullMutable()).profiles)) {
|
||||||
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
|
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
|
||||||
dictionaryOptions.enabled = true;
|
dictionaryOptions.enabled = true;
|
||||||
options.dictionaries[result.title] = dictionaryOptions;
|
options.dictionaries[result.title] = dictionaryOptions;
|
||||||
@ -611,7 +611,7 @@ async function onDictionaryImport(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
onDatabaseUpdated(options);
|
onDatabaseUpdated(options);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -630,7 +630,7 @@ async function onDictionaryImport(e) {
|
|||||||
|
|
||||||
|
|
||||||
async function onDatabaseEnablePrefixWildcardSearchesChanged(e) {
|
async function onDatabaseEnablePrefixWildcardSearchesChanged(e) {
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
const v = !!e.target.checked;
|
const v = !!e.target.checked;
|
||||||
if (optionsFull.global.database.prefixWildcardsSupported === v) { return; }
|
if (optionsFull.global.database.prefixWildcardsSupported === v) { return; }
|
||||||
optionsFull.global.database.prefixWildcardsSupported = !!e.target.checked;
|
optionsFull.global.database.prefixWildcardsSupported = !!e.target.checked;
|
||||||
|
@ -16,6 +16,14 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function getOptionsMutable(optionsContext) {
|
||||||
|
return utilBackend().getOptions(optionsContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOptionsFullMutable() {
|
||||||
|
return utilBackend().getFullOptions();
|
||||||
|
}
|
||||||
|
|
||||||
async function formRead(options) {
|
async function formRead(options) {
|
||||||
options.general.enable = $('#enable').prop('checked');
|
options.general.enable = $('#enable').prop('checked');
|
||||||
options.general.showGuide = $('#show-usage-guide').prop('checked');
|
options.general.showGuide = $('#show-usage-guide').prop('checked');
|
||||||
@ -164,7 +172,7 @@ function formUpdateVisibility(options) {
|
|||||||
|
|
||||||
async function onFormOptionsChanged() {
|
async function onFormOptionsChanged() {
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
|
|
||||||
await formRead(options);
|
await formRead(options);
|
||||||
await settingsSaveOptions();
|
await settingsSaveOptions();
|
||||||
@ -190,7 +198,7 @@ async function onOptionsUpdate({source}) {
|
|||||||
if (source === thisSource) { return; }
|
if (source === thisSource) { return; }
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
await formWrite(options);
|
await formWrite(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ function getOptionsContext() {
|
|||||||
|
|
||||||
|
|
||||||
async function profileOptionsSetup() {
|
async function profileOptionsSetup() {
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
currentProfileIndex = optionsFull.profileCurrent;
|
currentProfileIndex = optionsFull.profileCurrent;
|
||||||
|
|
||||||
profileOptionsSetupEventListeners();
|
profileOptionsSetupEventListeners();
|
||||||
@ -120,7 +120,7 @@ async function profileOptionsUpdateTarget(optionsFull) {
|
|||||||
profileFormWrite(optionsFull);
|
profileFormWrite(optionsFull);
|
||||||
|
|
||||||
const optionsContext = getOptionsContext();
|
const optionsContext = getOptionsContext();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await getOptionsMutable(optionsContext);
|
||||||
await formWrite(options);
|
await formWrite(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,13 +164,13 @@ async function onProfileOptionsChanged(e) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
await profileFormRead(optionsFull);
|
await profileFormRead(optionsFull);
|
||||||
await settingsSaveOptions();
|
await settingsSaveOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onTargetProfileChanged() {
|
async function onTargetProfileChanged() {
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
const index = tryGetIntegerValue('#profile-target', 0, optionsFull.profiles.length);
|
const index = tryGetIntegerValue('#profile-target', 0, optionsFull.profiles.length);
|
||||||
if (index === null || currentProfileIndex === index) {
|
if (index === null || currentProfileIndex === index) {
|
||||||
return;
|
return;
|
||||||
@ -182,7 +182,7 @@ async function onTargetProfileChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onProfileAdd() {
|
async function onProfileAdd() {
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
const profile = utilBackgroundIsolate(optionsFull.profiles[currentProfileIndex]);
|
const profile = utilBackgroundIsolate(optionsFull.profiles[currentProfileIndex]);
|
||||||
profile.name = profileOptionsCreateCopyName(profile.name, optionsFull.profiles, 100);
|
profile.name = profileOptionsCreateCopyName(profile.name, optionsFull.profiles, 100);
|
||||||
optionsFull.profiles.push(profile);
|
optionsFull.profiles.push(profile);
|
||||||
@ -210,7 +210,7 @@ async function onProfileRemove(e) {
|
|||||||
async function onProfileRemoveConfirm() {
|
async function onProfileRemoveConfirm() {
|
||||||
$('#profile-remove-modal').modal('hide');
|
$('#profile-remove-modal').modal('hide');
|
||||||
|
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
if (optionsFull.profiles.length <= 1) {
|
if (optionsFull.profiles.length <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -234,7 +234,7 @@ function onProfileNameChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onProfileMove(offset) {
|
async function onProfileMove(offset) {
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
const index = currentProfileIndex + offset;
|
const index = currentProfileIndex + offset;
|
||||||
if (index < 0 || index >= optionsFull.profiles.length) {
|
if (index < 0 || index >= optionsFull.profiles.length) {
|
||||||
return;
|
return;
|
||||||
@ -267,7 +267,7 @@ async function onProfileCopy() {
|
|||||||
async function onProfileCopyConfirm() {
|
async function onProfileCopyConfirm() {
|
||||||
$('#profile-copy-modal').modal('hide');
|
$('#profile-copy-modal').modal('hide');
|
||||||
|
|
||||||
const optionsFull = await apiOptionsGetFull();
|
const optionsFull = await getOptionsFullMutable();
|
||||||
const index = tryGetIntegerValue('#profile-copy-source', 0, optionsFull.profiles.length);
|
const index = tryGetIntegerValue('#profile-copy-source', 0, optionsFull.profiles.length);
|
||||||
if (index === null || index === currentProfileIndex) {
|
if (index === null || index === currentProfileIndex) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user