Update dictionaries for all profile options

This commit is contained in:
toasted-nutbread 2019-09-08 13:27:32 -04:00
parent 6c571bf828
commit c002e1bbd2

View File

@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
async function getOptionsArray() {
const optionsFull = await apiOptionsGetFull();
return optionsFull.profiles.map(profile => profile.options);
}
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');
@ -415,12 +420,14 @@ async function onDictionaryPurge(e) {
dictionarySpinnerShow(true); dictionarySpinnerShow(true);
await utilDatabasePurge(); await utilDatabasePurge();
const optionsContext = getOptionsContext(); for (const options of await getOptionsArray()) {
const options = await apiOptionsGet(optionsContext); options.dictionaries = utilBackgroundIsolate({});
options.dictionaries = utilBackgroundIsolate({}); options.general.mainDictionary = '';
options.general.mainDictionary = ''; }
await settingsSaveOptions(); await settingsSaveOptions();
const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
await dictionaryGroupsPopulate(options); await dictionaryGroupsPopulate(options);
await formMainDictionaryOptionsPopulate(options); await formMainDictionaryOptionsPopulate(options);
} catch (e) { } catch (e) {
@ -457,24 +464,25 @@ async function onDictionaryImport(e) {
const exceptions = []; const exceptions = [];
const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions); const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions);
const optionsContext = getOptionsContext(); for (const options of await getOptionsArray()) {
const options = await apiOptionsGet(optionsContext); options.dictionaries[summary.title] = utilBackgroundIsolate({
options.dictionaries[summary.title] = utilBackgroundIsolate({ enabled: true,
enabled: true, priority: 0,
priority: 0, allowSecondarySearches: false
allowSecondarySearches: false });
}); if (summary.sequenced && options.general.mainDictionary === '') {
if (summary.sequenced && options.general.mainDictionary === '') { options.general.mainDictionary = summary.title;
options.general.mainDictionary = summary.title; }
} }
await settingsSaveOptions();
if (exceptions.length > 0) { if (exceptions.length > 0) {
exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`); exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`);
dictionaryErrorsShow(exceptions); dictionaryErrorsShow(exceptions);
} }
await settingsSaveOptions(); const optionsContext = getOptionsContext();
const options = await apiOptionsGet(optionsContext);
await dictionaryGroupsPopulate(options); await dictionaryGroupsPopulate(options);
await formMainDictionaryOptionsPopulate(options); await formMainDictionaryOptionsPopulate(options);
} catch (e) { } catch (e) {