Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Jul 6, 2024
1 parent 1846ba4 commit b5a9895
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
11 changes: 10 additions & 1 deletion ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,16 @@ export class DictionaryController {
* @param {string} dictionaryTitle
*/
async _updateDictionary(dictionaryTitle) {
console.log('Updating dictionary:', dictionaryTitle);
if (this._checkingIntegrity || this._checkingUpdates || this._isDeleting || this._dictionaries === null) { return; }

const dictionaryInfo = this._dictionaries.find((entry) => entry.title === dictionaryTitle);
if (typeof dictionaryInfo === 'undefined') { throw new Error('Dictionary not found'); }
const {downloadUrl} = dictionaryInfo;
if (typeof downloadUrl !== 'string') { throw new Error('Attempted to update dictionary without download URL'); }

await this._deleteDictionary(dictionaryTitle);

this._settingsController.trigger('importDictionaryFromUrl', {url: downloadUrl});
}

/**
Expand Down
26 changes: 21 additions & 5 deletions ext/js/pages/settings/dictionary-import-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,19 @@ export class DictionaryImportController {
this._importFileDrop.addEventListener('dragover', this._onFileDropOver.bind(this), false);
this._importFileDrop.addEventListener('dragleave', this._onFileDropLeave.bind(this), false);
this._importFileDrop.addEventListener('drop', this._onFileDrop.bind(this), false);

this._settingsController.on('importDictionaryFromUrl', this._onEventImportDictionaryFromUrl.bind(this));
}

// Private

/**
* @param {import('settings-controller').EventArgument<'importDictionaryFromUrl'>} details
*/
_onEventImportDictionaryFromUrl({url}) {
void this.importFilesFromURLs(url);
}

/** */
_onImportFileButtonClick() {
/** @type {HTMLInputElement} */ (this._importFileInput).click();
Expand Down Expand Up @@ -253,6 +262,13 @@ export class DictionaryImportController {
async _onImportFromURL() {
const text = this._importURLText.value.trim();
if (!text) { return; }
await this.importFilesFromURLs(text);
}

/**
* @param {string} text
*/
async importFilesFromURLs(text) {
const urls = text.split('\n');
const files = [];
for (const url of urls) {
Expand Down Expand Up @@ -309,6 +325,11 @@ export class DictionaryImportController {

const prevention = this._preventPageExit();

const optionsFull = await this._settingsController.getOptionsFull();
const importDetails = {
prefixWildcardsSupported: optionsFull.global.database.prefixWildcardsSupported,
};

/** @type {Error[]} */
let errors = [];
try {
Expand All @@ -317,11 +338,6 @@ export class DictionaryImportController {

for (const progress of progressContainers) { progress.hidden = false; }

const optionsFull = await this._settingsController.getOptionsFull();
const importDetails = {
prefixWildcardsSupported: optionsFull.global.database.prefixWildcardsSupported,
};

let statusPrefix = '';
/** @type {import('dictionary-importer.js').ImportStep} */
let stepIndex = -2;
Expand Down
6 changes: 3 additions & 3 deletions ext/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -2493,15 +2493,15 @@ <h5>or click here to upload</h5>
<div class="modal-body">
<p>Are you sure you want to update the dictionary:</p>
<p><strong id="dictionary-confirm-update-name"></strong>?</p>
<p class="warning-text">
<section>
Updating a dictionary involves:
<ul>
<li>Deleting the installed version</li>
<li>Downloading the latest version </li>
<li>Importing the latest version</li>
</ul>
Especially for large dictionaries, this process can take a while, and downloading will use your network.
</p>
<p class="warning-text">Especially for large dictionaries, this process can take a while, and downloading will use your network.</p>
</section>
</div>
<div class="modal-footer">
<button type="button" class="low-emphasis" data-modal-action="hide">Cancel</button>
Expand Down
3 changes: 3 additions & 0 deletions types/ext/settings-controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export type Events = {
dictionarySettingsReordered: {
source: DictionaryController;
};
importDictionaryFromUrl: {
url: string;
};
scanInputsChanged: {
source: ScanInputsController | ScanInputsSimpleController;
};
Expand Down

0 comments on commit b5a9895

Please sign in to comment.