2019-12-14 19:15:17 +00:00
|
|
|
/*
|
2022-02-03 01:43:10 +00:00
|
|
|
* Copyright (C) 2019-2022 Yomichan Authors
|
2019-12-14 19:15:17 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2021-02-26 01:21:05 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-12-14 19:15:17 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-01-01 17:00:31 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-12-14 19:15:17 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-11 02:30:36 +00:00
|
|
|
/* global
|
2020-11-15 19:14:52 +00:00
|
|
|
* DictionaryController
|
2020-08-01 15:46:35 +00:00
|
|
|
* OptionsUtil
|
2021-07-31 17:04:16 +00:00
|
|
|
* StringUtil
|
2020-03-11 02:30:36 +00:00
|
|
|
*/
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-09-09 21:37:58 +00:00
|
|
|
class BackupController {
|
2020-10-11 00:58:38 +00:00
|
|
|
constructor(settingsController, modalController) {
|
2020-05-30 13:33:13 +00:00
|
|
|
this._settingsController = settingsController;
|
2020-10-11 00:58:38 +00:00
|
|
|
this._modalController = modalController;
|
2020-05-24 17:56:46 +00:00
|
|
|
this._settingsExportToken = null;
|
|
|
|
this._settingsExportRevoke = null;
|
|
|
|
this._currentVersion = 0;
|
2020-09-19 21:14:51 +00:00
|
|
|
this._settingsResetModal = null;
|
|
|
|
this._settingsImportErrorModal = null;
|
|
|
|
this._settingsImportWarningModal = null;
|
2020-12-12 19:57:24 +00:00
|
|
|
this._optionsUtil = null;
|
|
|
|
try {
|
|
|
|
this._optionsUtil = new OptionsUtil();
|
|
|
|
} catch (e) {
|
|
|
|
// NOP
|
|
|
|
}
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-09-11 18:15:08 +00:00
|
|
|
async prepare() {
|
2020-12-12 19:57:24 +00:00
|
|
|
if (this._optionsUtil !== null) {
|
|
|
|
await this._optionsUtil.prepare();
|
|
|
|
}
|
2020-09-11 18:15:08 +00:00
|
|
|
|
2020-12-12 19:57:24 +00:00
|
|
|
if (this._modalController !== null) {
|
|
|
|
this._settingsResetModal = this._modalController.getModal('settings-reset');
|
|
|
|
this._settingsImportErrorModal = this._modalController.getModal('settings-import-error');
|
|
|
|
this._settingsImportWarningModal = this._modalController.getModal('settings-import-warning');
|
|
|
|
}
|
2020-09-19 21:14:51 +00:00
|
|
|
|
2020-12-12 19:57:24 +00:00
|
|
|
this._addNodeEventListener('#settings-export-button', 'click', this._onSettingsExportClick.bind(this), false);
|
|
|
|
this._addNodeEventListener('#settings-import-button', 'click', this._onSettingsImportClick.bind(this), false);
|
|
|
|
this._addNodeEventListener('#settings-import-file', 'change', this._onSettingsImportFileChange.bind(this), false);
|
|
|
|
this._addNodeEventListener('#settings-reset-button', 'click', this._onSettingsResetClick.bind(this), false);
|
|
|
|
this._addNodeEventListener('#settings-reset-confirm-button', 'click', this._onSettingsResetConfirmClick.bind(this), false);
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Private
|
|
|
|
|
2020-12-12 19:57:24 +00:00
|
|
|
_addNodeEventListener(selector, ...args) {
|
|
|
|
const node = document.querySelector(selector);
|
|
|
|
if (node === null) { return; }
|
|
|
|
|
|
|
|
node.addEventListener(...args);
|
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_getSettingsExportDateString(date, dateSeparator, dateTimeSeparator, timeSeparator, resolution) {
|
|
|
|
const values = [
|
|
|
|
date.getUTCFullYear().toString(),
|
|
|
|
dateSeparator,
|
|
|
|
(date.getUTCMonth() + 1).toString().padStart(2, '0'),
|
|
|
|
dateSeparator,
|
|
|
|
date.getUTCDate().toString().padStart(2, '0'),
|
|
|
|
dateTimeSeparator,
|
|
|
|
date.getUTCHours().toString().padStart(2, '0'),
|
|
|
|
timeSeparator,
|
|
|
|
date.getUTCMinutes().toString().padStart(2, '0'),
|
|
|
|
timeSeparator,
|
|
|
|
date.getUTCSeconds().toString().padStart(2, '0')
|
|
|
|
];
|
|
|
|
return values.slice(0, resolution * 2 - 1).join('');
|
2019-12-14 19:15:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
async _getSettingsExportData(date) {
|
2020-05-30 13:33:13 +00:00
|
|
|
const optionsFull = await this._settingsController.getOptionsFull();
|
2021-02-14 20:53:35 +00:00
|
|
|
const environment = await yomichan.api.getEnvironmentInfo();
|
|
|
|
const fieldTemplatesDefault = await yomichan.api.getDefaultAnkiFieldTemplates();
|
2021-02-11 23:55:09 +00:00
|
|
|
const permissions = await this._settingsController.permissionsUtil.getAllPermissions();
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Format options
|
|
|
|
for (const {options} of optionsFull.profiles) {
|
|
|
|
if (options.anki.fieldTemplates === fieldTemplatesDefault || !options.anki.fieldTemplates) {
|
2020-10-20 00:05:45 +00:00
|
|
|
options.anki.fieldTemplates = null;
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2019-12-14 19:15:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const data = {
|
|
|
|
version: this._currentVersion,
|
|
|
|
date: this._getSettingsExportDateString(date, '-', ' ', ':', 6),
|
|
|
|
url: chrome.runtime.getURL('/'),
|
|
|
|
manifest: chrome.runtime.getManifest(),
|
|
|
|
environment,
|
|
|
|
userAgent: navigator.userAgent,
|
2020-12-17 03:26:19 +00:00
|
|
|
permissions,
|
2020-05-24 17:56:46 +00:00
|
|
|
options: optionsFull
|
|
|
|
};
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
return data;
|
|
|
|
}
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_saveBlob(blob, fileName) {
|
|
|
|
if (typeof navigator === 'object' && typeof navigator.msSaveBlob === 'function') {
|
|
|
|
if (navigator.msSaveBlob(blob)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const blobUrl = URL.createObjectURL(blob);
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const a = document.createElement('a');
|
|
|
|
a.href = blobUrl;
|
|
|
|
a.download = fileName;
|
|
|
|
a.rel = 'noopener';
|
|
|
|
a.target = '_blank';
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const revoke = () => {
|
|
|
|
URL.revokeObjectURL(blobUrl);
|
|
|
|
a.href = '';
|
|
|
|
this._settingsExportRevoke = null;
|
|
|
|
};
|
|
|
|
this._settingsExportRevoke = revoke;
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
a.dispatchEvent(new MouseEvent('click'));
|
|
|
|
setTimeout(revoke, 60000);
|
2019-12-14 19:15:17 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
async _onSettingsExportClick() {
|
|
|
|
if (this._settingsExportRevoke !== null) {
|
|
|
|
this._settingsExportRevoke();
|
|
|
|
this._settingsExportRevoke = null;
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const date = new Date(Date.now());
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const token = {};
|
|
|
|
this._settingsExportToken = token;
|
|
|
|
const data = await this._getSettingsExportData(date);
|
|
|
|
if (this._settingsExportToken !== token) {
|
|
|
|
// A new export has been started
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._settingsExportToken = null;
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const fileName = `yomichan-settings-${this._getSettingsExportDateString(date, '-', '-', '-', 6)}.json`;
|
|
|
|
const blob = new Blob([JSON.stringify(data, null, 4)], {type: 'application/json'});
|
|
|
|
this._saveBlob(blob, fileName);
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_readFileArrayBuffer(file) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = () => resolve(reader.result);
|
|
|
|
reader.onerror = () => reject(reader.error);
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
});
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Importing
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
async _settingsImportSetOptionsFull(optionsFull) {
|
2020-10-20 00:05:45 +00:00
|
|
|
await this._settingsController.setAllSettings(optionsFull);
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_showSettingsImportError(error) {
|
2021-02-14 22:52:01 +00:00
|
|
|
log.error(error);
|
2020-10-20 00:05:45 +00:00
|
|
|
document.querySelector('#settings-import-error-message').textContent = `${error}`;
|
2020-09-19 21:14:51 +00:00
|
|
|
this._settingsImportErrorModal.setVisible(true);
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
async _showSettingsImportWarnings(warnings) {
|
2020-09-19 21:14:51 +00:00
|
|
|
const modal = this._settingsImportWarningModal;
|
2020-10-20 00:05:45 +00:00
|
|
|
const buttons = document.querySelectorAll('.settings-import-warning-import-button');
|
|
|
|
const messageContainer = document.querySelector('#settings-import-warning-message');
|
2020-09-19 21:14:51 +00:00
|
|
|
if (buttons.length === 0 || messageContainer === null) {
|
2020-05-24 17:56:46 +00:00
|
|
|
return {result: false};
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Set message
|
|
|
|
const fragment = document.createDocumentFragment();
|
|
|
|
for (const warning of warnings) {
|
|
|
|
const node = document.createElement('li');
|
|
|
|
node.textContent = `${warning}`;
|
|
|
|
fragment.appendChild(node);
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
2020-05-24 17:56:46 +00:00
|
|
|
messageContainer.textContent = '';
|
|
|
|
messageContainer.appendChild(fragment);
|
|
|
|
|
|
|
|
// Show modal
|
2020-09-19 21:14:51 +00:00
|
|
|
modal.setVisible(true);
|
2020-05-24 17:56:46 +00:00
|
|
|
|
|
|
|
// Wait for modal to close
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
const onButtonClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
complete({
|
|
|
|
result: true,
|
|
|
|
sanitize: e.currentTarget.dataset.importSanitize === 'true'
|
|
|
|
});
|
2020-09-19 21:14:51 +00:00
|
|
|
modal.setVisible(false);
|
2020-05-24 17:56:46 +00:00
|
|
|
};
|
2020-09-19 21:14:51 +00:00
|
|
|
const onModalVisibilityChanged = ({visible}) => {
|
|
|
|
if (visible) { return; }
|
2020-05-24 17:56:46 +00:00
|
|
|
complete({result: false});
|
|
|
|
};
|
|
|
|
|
|
|
|
let completed = false;
|
|
|
|
const complete = (result) => {
|
|
|
|
if (completed) { return; }
|
|
|
|
completed = true;
|
|
|
|
|
2020-09-19 21:14:51 +00:00
|
|
|
modal.off('visibilityChanged', onModalVisibilityChanged);
|
2020-05-24 17:56:46 +00:00
|
|
|
for (const button of buttons) {
|
|
|
|
button.removeEventListener('click', onButtonClick, false);
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
resolve(result);
|
|
|
|
};
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Hook events
|
2020-09-19 21:14:51 +00:00
|
|
|
modal.on('visibilityChanged', onModalVisibilityChanged);
|
2020-05-24 17:56:46 +00:00
|
|
|
for (const button of buttons) {
|
|
|
|
button.addEventListener('click', onButtonClick, false);
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
2020-05-24 17:56:46 +00:00
|
|
|
});
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_isLocalhostUrl(urlString) {
|
|
|
|
try {
|
|
|
|
const url = new URL(urlString);
|
|
|
|
switch (url.hostname.toLowerCase()) {
|
|
|
|
case 'localhost':
|
|
|
|
case '127.0.0.1':
|
|
|
|
case '[::1]':
|
|
|
|
switch (url.protocol.toLowerCase()) {
|
|
|
|
case 'http:':
|
|
|
|
case 'https:':
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
2020-05-24 17:56:46 +00:00
|
|
|
} catch (e) {
|
|
|
|
// NOP
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
2020-05-24 17:56:46 +00:00
|
|
|
return false;
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_settingsImportSanitizeProfileOptions(options, dryRun) {
|
|
|
|
const warnings = [];
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const anki = options.anki;
|
|
|
|
if (isObject(anki)) {
|
|
|
|
const fieldTemplates = anki.fieldTemplates;
|
|
|
|
if (typeof fieldTemplates === 'string') {
|
|
|
|
warnings.push('anki.fieldTemplates contains a non-default value');
|
|
|
|
if (!dryRun) {
|
2020-09-19 21:15:34 +00:00
|
|
|
anki.fieldTemplates = null;
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const server = anki.server;
|
|
|
|
if (typeof server === 'string' && server.length > 0 && !this._isLocalhostUrl(server)) {
|
|
|
|
warnings.push('anki.server uses a non-localhost URL');
|
|
|
|
if (!dryRun) {
|
2020-09-19 21:15:34 +00:00
|
|
|
anki.server = 'http://127.0.0.1:8765';
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const audio = options.audio;
|
|
|
|
if (isObject(audio)) {
|
2021-05-30 16:41:19 +00:00
|
|
|
const sources = audio.sources;
|
|
|
|
if (Array.isArray(sources)) {
|
|
|
|
for (let i = 0, ii = sources.length; i < ii; ++i) {
|
|
|
|
const source = sources[i];
|
|
|
|
if (!isObject(source)) { continue; }
|
|
|
|
const {url} = source;
|
|
|
|
if (typeof url === 'string' && url.length > 0 && !this._isLocalhostUrl(url)) {
|
|
|
|
warnings.push(`audio.sources[${i}].url uses a non-localhost URL`);
|
|
|
|
if (!dryRun) {
|
|
|
|
sources[i].url = '';
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
return warnings;
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_settingsImportSanitizeOptions(optionsFull, dryRun) {
|
|
|
|
const warnings = new Set();
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const profiles = optionsFull.profiles;
|
|
|
|
if (Array.isArray(profiles)) {
|
|
|
|
for (const profile of profiles) {
|
|
|
|
if (!isObject(profile)) { continue; }
|
|
|
|
const options = profile.options;
|
|
|
|
if (!isObject(options)) { continue; }
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const warnings2 = this._settingsImportSanitizeProfileOptions(options, dryRun);
|
|
|
|
for (const warning of warnings2) {
|
|
|
|
warnings.add(warning);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
return warnings;
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
async _importSettingsFile(file) {
|
2021-07-31 17:04:16 +00:00
|
|
|
const dataString = StringUtil.arrayBufferUtf8Decode(await this._readFileArrayBuffer(file));
|
2020-05-24 17:56:46 +00:00
|
|
|
const data = JSON.parse(dataString);
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Type check
|
|
|
|
if (!isObject(data)) {
|
|
|
|
throw new Error(`Invalid data type: ${typeof data}`);
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Version check
|
|
|
|
const version = data.version;
|
|
|
|
if (!(
|
|
|
|
typeof version === 'number' &&
|
|
|
|
Number.isFinite(version) &&
|
|
|
|
version === Math.floor(version)
|
|
|
|
)) {
|
|
|
|
throw new Error(`Invalid version: ${version}`);
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
if (!(
|
|
|
|
version >= 0 &&
|
|
|
|
version <= this._currentVersion
|
|
|
|
)) {
|
|
|
|
throw new Error(`Unsupported version: ${version}`);
|
2019-12-14 21:37:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Verify options exists
|
|
|
|
let optionsFull = data.options;
|
|
|
|
if (!isObject(optionsFull)) {
|
|
|
|
throw new Error(`Invalid options type: ${typeof optionsFull}`);
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Upgrade options
|
2020-09-11 18:15:08 +00:00
|
|
|
optionsFull = await this._optionsUtil.update(optionsFull);
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Check for warnings
|
|
|
|
const sanitizationWarnings = this._settingsImportSanitizeOptions(optionsFull, true);
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Show sanitization warnings
|
|
|
|
if (sanitizationWarnings.size > 0) {
|
|
|
|
const {result, sanitize} = await this._showSettingsImportWarnings(sanitizationWarnings);
|
|
|
|
if (!result) { return; }
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
if (sanitize !== false) {
|
|
|
|
this._settingsImportSanitizeOptions(optionsFull, false);
|
|
|
|
}
|
|
|
|
}
|
2019-12-14 21:37:37 +00:00
|
|
|
|
2021-03-31 22:32:17 +00:00
|
|
|
// Update dictionaries
|
2021-04-03 17:02:49 +00:00
|
|
|
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, false, false);
|
2021-03-31 22:32:17 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Assign options
|
|
|
|
await this._settingsImportSetOptionsFull(optionsFull);
|
|
|
|
}
|
2019-12-15 04:06:44 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_onSettingsImportClick() {
|
|
|
|
document.querySelector('#settings-import-file').click();
|
|
|
|
}
|
2019-12-15 04:06:44 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
async _onSettingsImportFileChange(e) {
|
|
|
|
const files = e.target.files;
|
|
|
|
if (files.length === 0) { return; }
|
2019-12-15 04:06:44 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
const file = files[0];
|
|
|
|
e.target.value = null;
|
|
|
|
try {
|
|
|
|
await this._importSettingsFile(file);
|
|
|
|
} catch (error) {
|
|
|
|
this._showSettingsImportError(error);
|
|
|
|
}
|
|
|
|
}
|
2019-12-15 04:06:44 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Resetting
|
2019-12-15 04:06:44 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
_onSettingsResetClick() {
|
2020-09-19 21:14:51 +00:00
|
|
|
this._settingsResetModal.setVisible(true);
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2019-12-15 04:06:44 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
async _onSettingsResetConfirmClick() {
|
2020-09-19 21:14:51 +00:00
|
|
|
this._settingsResetModal.setVisible(false);
|
2019-12-15 04:06:44 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Get default options
|
2020-09-11 18:15:08 +00:00
|
|
|
const optionsFull = this._optionsUtil.getDefault();
|
2019-12-14 19:15:17 +00:00
|
|
|
|
2020-11-15 19:14:52 +00:00
|
|
|
// Update dictionaries
|
2021-04-03 17:02:49 +00:00
|
|
|
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, false, false);
|
2020-11-15 19:14:52 +00:00
|
|
|
|
2020-05-24 17:56:46 +00:00
|
|
|
// Assign options
|
2020-10-20 00:05:45 +00:00
|
|
|
try {
|
|
|
|
await this._settingsImportSetOptionsFull(optionsFull);
|
|
|
|
} catch (e) {
|
2021-02-14 22:52:01 +00:00
|
|
|
log.error(e);
|
2020-10-20 00:05:45 +00:00
|
|
|
}
|
2020-05-24 17:56:46 +00:00
|
|
|
}
|
2020-03-02 09:18:09 +00:00
|
|
|
}
|