From 2446520309e1b4b517da540e724eb795ee4be1c2 Mon Sep 17 00:00:00 2001 From: stephenmk Date: Wed, 8 Jan 2025 17:01:35 -0600 Subject: [PATCH] Add `minimumYomitanVersion` parameter to dictionary index schema --- ext/data/schemas/dictionary-index-schema.json | 4 ++++ ext/js/dictionary/dictionary-importer.js | 12 +++++++++++- types/ext/dictionary-data.d.ts | 1 + types/ext/dictionary-importer.d.ts | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ext/data/schemas/dictionary-index-schema.json b/ext/data/schemas/dictionary-index-schema.json index ec8b73b20d..f68e321e11 100644 --- a/ext/data/schemas/dictionary-index-schema.json +++ b/ext/data/schemas/dictionary-index-schema.json @@ -23,6 +23,10 @@ "type": "string", "description": "Revision of the dictionary. This value is displayed, and used to check for dictionary updates." }, + "minimumYomitanVersion": { + "type": "string", + "description": "Minimum version of Yomitan that is compatible with this dictionary." + }, "sequenced": { "type": "boolean", "default": false, diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js index e8a72ba821..021046410f 100644 --- a/ext/js/dictionary/dictionary-importer.js +++ b/ext/js/dictionary/dictionary-importer.js @@ -24,6 +24,7 @@ import { ZipReader as ZipReader0, configure, } from '../../lib/zip.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'; @@ -328,7 +329,16 @@ export class DictionaryImporter { styles, }; - const {author, url, description, attribution, frequencyMode, isUpdatable, sourceLanguage, targetLanguage} = index; + 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") { + // 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})`); + } + summary.minimumYomitanVersion = minimumYomitanVersion; + } if (typeof author === 'string') { summary.author = author; } if (typeof url === 'string') { summary.url = url; } if (typeof description === 'string') { summary.description = description; } diff --git a/types/ext/dictionary-data.d.ts b/types/ext/dictionary-data.d.ts index 92e52b8d61..1b1d7c3306 100644 --- a/types/ext/dictionary-data.d.ts +++ b/types/ext/dictionary-data.d.ts @@ -24,6 +24,7 @@ export type Index = { version?: IndexVersion; title: string; revision: string; + minimumYomitanVersion?: string; sequenced?: boolean; isUpdatable?: true; indexUrl?: string; diff --git a/types/ext/dictionary-importer.d.ts b/types/ext/dictionary-importer.d.ts index 97472e6cfa..5f42b8f684 100644 --- a/types/ext/dictionary-importer.d.ts +++ b/types/ext/dictionary-importer.d.ts @@ -46,6 +46,7 @@ export type Summary = { title: string; revision: string; sequenced: boolean; + minimumYomitanVersion?: string; version: number; importDate: number; prefixWildcardsSupported: boolean;