Skip to content

Commit

Permalink
Can't use chrome.runtime in DictionaryImporter class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmk committed Jan 9, 2025
1 parent 2446520 commit 12eaf86
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ext/js/dictionary/dictionary-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
ZipReader as ZipReader0,
configure,
} from '../../lib/zip.js';
import {compareRevisions} from 'dictionary-data-util.js';
import {compareRevisions} from './dictionary-data-util.js';
import {ExtensionError} from '../core/extension-error.js';
import {parseJson} from '../core/json.js';
import {toError} from '../core/to-error.js';
Expand Down Expand Up @@ -181,8 +181,9 @@ export class DictionaryImporter {
}
}

const yomitanVersion = details.yomitanVersion;
/** @type {import('dictionary-importer').SummaryDetails} */
const summaryDetails = {prefixWildcardsSupported, counts, styles};
const summaryDetails = {prefixWildcardsSupported, counts, styles, yomitanVersion};

const summary = this._createSummary(dictionaryTitle, version, index, summaryDetails);
await dictionaryDatabase.bulkAdd('dictionaries', [summary], 0, 1);
Expand Down Expand Up @@ -331,11 +332,10 @@ export class DictionaryImporter {

const {minimumYomitanVersion, author, url, description, attribution, frequencyMode, isUpdatable, sourceLanguage, targetLanguage} = index;
if (typeof minimumYomitanVersion === 'string') {
const {version} = chrome.runtime.getManifest();
if (version === "0.0.0.0") {
if (details.yomitanVersion === "0.0.0.0") {
// Running a development version of Yomitan
} else if (compareRevisions(version, minimumYomitanVersion)) {
throw new Error(`Dictionary is incompatible with this version of Yomitan (${version}; minimum required: ${minimumYomitanVersion})`);
} else if (compareRevisions(details.yomitanVersion, minimumYomitanVersion)) {
throw new Error(`Dictionary is incompatible with this version of Yomitan (${details.yomitanVersion}; minimum required: ${minimumYomitanVersion})`);
}
summary.minimumYomitanVersion = minimumYomitanVersion;
}
Expand Down
1 change: 1 addition & 0 deletions ext/js/pages/settings/dictionary-import-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ export class DictionaryImportController {
const optionsFull = await this._settingsController.getOptionsFull();
const importDetails = {
prefixWildcardsSupported: optionsFull.global.database.prefixWildcardsSupported,
yomitanVersion: chrome.runtime.getManifest().version,
};

for (let i = 0; i < importProgressTracker.dictionaryCount; ++i) {
Expand Down
2 changes: 2 additions & 0 deletions types/ext/dictionary-importer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type ImportResult = {

export type ImportDetails = {
prefixWildcardsSupported: boolean;
yomitanVersion: string;
};

export type Summary = {
Expand Down Expand Up @@ -68,6 +69,7 @@ export type SummaryDetails = {
prefixWildcardsSupported: boolean;
counts: SummaryCounts;
styles: string;
yomitanVersion: string;
};

export type SummaryCounts = {
Expand Down

0 comments on commit 12eaf86

Please sign in to comment.