Skip to content

Commit

Permalink
Merge branch 'master' into bee-add-welsh
Browse files Browse the repository at this point in the history
  • Loading branch information
bee-san authored Jan 21, 2025
2 parents 19f6b63 + 70de0f3 commit 7092f7a
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 11 deletions.
4 changes: 4 additions & 0 deletions ext/data/schemas/dictionary-index-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@
"scanOnPenPress": true,
"scanOnPenRelease": false,
"preventTouchScrolling": false,
"preventPenScrolling": false
"preventPenScrolling": false,
"minimumTouchTime": 0
}
},
{
Expand All @@ -524,7 +525,8 @@
"scanOnPenPress": true,
"scanOnPenRelease": false,
"preventTouchScrolling": true,
"preventPenScrolling": true
"preventPenScrolling": true,
"minimumTouchTime": 0
}
}
],
Expand Down Expand Up @@ -583,7 +585,8 @@
"scanOnPenPress",
"scanOnPenRelease",
"preventTouchScrolling",
"preventPenScrolling"
"preventPenScrolling",
"minimumTouchTime"
],
"properties": {
"showAdvanced": {
Expand Down Expand Up @@ -641,6 +644,10 @@
"preventPenScrolling": {
"type": "boolean",
"default": true
},
"minimumTouchTime": {
"type": "number",
"default": 0
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ export class OptionsUtil {
this._updateVersion54,
this._updateVersion55,
this._updateVersion56,
this._updateVersion57,
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -642,6 +643,7 @@ export class OptionsUtil {
scanOnPenPress: true,
scanOnPenRelease: false,
preventTouchScrolling: true,
minimumTouchTime: 0,
});
for (const {options: profileOptions} of options.profiles) {
profileOptions.general.usePopupWindow = false;
Expand Down Expand Up @@ -1553,6 +1555,18 @@ export class OptionsUtil {
}
}

/**
* - Added scanning.inputs[].options.minimumTouchTime.
* @type {import('options-util').UpdateFunction}
*/
async _updateVersion57(options) {
for (const profile of options.profiles) {
for (const input of profile.options.scanning.inputs) {
input.options.minimumTouchTime = 0;
}
}
}

/**
* @param {string} url
* @returns {Promise<chrome.tabs.Tab>}
Expand Down
14 changes: 12 additions & 2 deletions ext/js/dictionary/dictionary-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -180,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 @@ -328,7 +330,15 @@ 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') {
if (details.yomitanVersion === '0.0.0.0') {
// Running a development version of Yomitan
} 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;
}
if (typeof author === 'string') { summary.author = author; }
if (typeof url === 'string') { summary.url = url; }
if (typeof description === 'string') { summary.description = description; }
Expand Down
1 change: 1 addition & 0 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,7 @@ export class Display extends EventDispatcher {
scanOnPenRelease: false,
preventTouchScrolling: false,
preventPenScrolling: false,
minimumTouchTime: 0,
},
}],
deepContentScan: scanningOptions.deepDomScan,
Expand Down
14 changes: 14 additions & 0 deletions ext/js/language/text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export class TextScanner extends EventDispatcher {

/** @type {boolean} */
this._touchTapValid = false;
/** @type {number} */
this._touchPressTime = 0;
/** @type {?number} */
this._primaryTouchIdentifier = null;
/** @type {boolean} */
Expand Down Expand Up @@ -723,6 +725,7 @@ export class TextScanner extends EventDispatcher {
this._preventNextMouseDown = false;
this._preventNextClick = false;
this._touchTapValid = true;
this._touchPressTime = Date.now();

const languageNotNull = this._language !== null ? this._language : '';
const selection = window.getSelection();
Expand Down Expand Up @@ -760,6 +763,7 @@ export class TextScanner extends EventDispatcher {
* @param {boolean} allowSearch
*/
_onPrimaryTouchEnd(e, x, y, allowSearch) {
const touchReleaseTime = Date.now();
this._primaryTouchIdentifier = null;
this._preventScroll = false;
this._preventNextClick = false;
Expand All @@ -770,6 +774,7 @@ export class TextScanner extends EventDispatcher {

const inputInfo = this._getMatchingInputGroupFromEvent('touch', 'touchEnd', e);
if (inputInfo === null || inputInfo.input === null) { return; }
if (touchReleaseTime - this._touchPressTime < inputInfo.input.minimumTouchTime) { return; }
if (inputInfo.input.scanOnTouchRelease || (inputInfo.input.scanOnTouchTap && this._touchTapValid)) {
void this._searchAtFromTouchEnd(x, y, inputInfo);
}
Expand Down Expand Up @@ -1493,6 +1498,7 @@ export class TextScanner extends EventDispatcher {
scanOnPenRelease: this._getInputBoolean(options.scanOnPenRelease),
preventTouchScrolling: this._getInputBoolean(options.preventTouchScrolling),
preventPenScrolling: this._getInputBoolean(options.preventPenScrolling),
minimumTouchTime: this._getInputNumber(options.minimumTouchTime),
};
}

Expand Down Expand Up @@ -1528,6 +1534,14 @@ export class TextScanner extends EventDispatcher {
return typeof value === 'boolean' && value;
}

/**
* @param {unknown} value
* @returns {number}
*/
_getInputNumber(value) {
return typeof value === 'number' ? value : -1;
}

/**
* @param {PointerEvent} e
* @returns {string}
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
5 changes: 5 additions & 0 deletions ext/js/pages/settings/scan-inputs-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class ScanInputsController {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
};
}
Expand Down Expand Up @@ -392,6 +393,10 @@ class ScanInputField {
const {property} = typeCheckbox.dataset;
typeCheckbox.dataset.setting = `scanning.inputs[${index}].${property}`;
}
for (const typeInput of /** @type {NodeListOf<HTMLElement>} */ (this._node.querySelectorAll('.scan-input-settings-input'))) {
const {property} = typeInput.dataset;
typeInput.dataset.setting = `scanning.inputs[${index}].${property}`;
}
}

/** */
Expand Down
4 changes: 4 additions & 0 deletions ext/templates-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
<label class="checkbox"><input type="checkbox" class="scan-input-settings-checkbox" data-property="options.preventTouchScrolling"><span class="checkbox-body"><span class="checkbox-fill"></span><span class="checkbox-border"></span><span class="checkbox-check"></span></span></label>
<span>Prevent touch scrolling</span>
</label>
<label class="scan-input-input-item">
<span>Minimum Touch Time <span class="light">(in milliseconds)</span>:</span>
<label class="input"><input type="number" class="scan-input-settings-input" data-property="options.minimumTouchTime"></label>
</label>
</div>

<div class="scan-input-prefix-cell scan-input-options-cell scan-input-advanced-only" data-property="pen-options"><span>Pen options:</span></div>
Expand Down
8 changes: 4 additions & 4 deletions test/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Database', () => {
// Setup database
const dictionaryDatabase = new DictionaryDatabase();
/** @type {import('dictionary-importer').ImportDetails} */
const defaultImportDetails = {prefixWildcardsSupported: false};
const defaultImportDetails = {prefixWildcardsSupported: false, yomitanVersion: '0.0.0.0'};

// Database not open
await expect.soft(dictionaryDatabase.deleteDictionary(title, 1000, () => {})).rejects.toThrow('Database not open');
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('Database', () => {
const testDictionarySource = await createTestDictionaryArchiveData(name);

/** @type {import('dictionary-importer').ImportDetails} */
const detaultImportDetails = {prefixWildcardsSupported: false};
const detaultImportDetails = {prefixWildcardsSupported: false, yomitanVersion: '0.0.0.0'};
await expect.soft(createDictionaryImporter(expect).importDictionary(dictionaryDatabase, testDictionarySource, detaultImportDetails)).rejects.toThrow('Dictionary has invalid data');
await dictionaryDatabase.close();
});
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Database', () => {
const {result: importDictionaryResult, errors: importDictionaryErrors} = await dictionaryImporter.importDictionary(
dictionaryDatabase,
testDictionarySource,
{prefixWildcardsSupported: true},
{prefixWildcardsSupported: true, yomitanVersion: '0.0.0.0'},
);

if (importDictionaryResult) {
Expand Down Expand Up @@ -324,7 +324,7 @@ describe('Database', () => {

// Import data
const dictionaryImporter = createDictionaryImporter(expect);
await dictionaryImporter.importDictionary(dictionaryDatabase, testDictionarySource, {prefixWildcardsSupported: true});
await dictionaryImporter.importDictionary(dictionaryDatabase, testDictionarySource, {prefixWildcardsSupported: true, yomitanVersion: '0.0.0.0'});

// Clear
switch (clearMethod) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/translator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function createTranslatorContext(dictionaryDirectory, dictionaryNam
const {errors, result} = await dictionaryImporter.importDictionary(
dictionaryDatabase,
testDictionaryData,
{prefixWildcardsSupported: true},
{prefixWildcardsSupported: true, yomitanVersion: '0.0.0.0'},
);

expect(errors.length).toEqual(0);
Expand Down
5 changes: 4 additions & 1 deletion test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ function createProfileOptionsUpdatedTestData1() {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
},
{
Expand All @@ -412,6 +413,7 @@ function createProfileOptionsUpdatedTestData1() {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
},
{
Expand All @@ -437,6 +439,7 @@ function createProfileOptionsUpdatedTestData1() {
scanOnPenRelease: false,
preventTouchScrolling: true,
preventPenScrolling: true,
minimumTouchTime: 0,
},
},
],
Expand Down Expand Up @@ -669,7 +672,7 @@ function createOptionsUpdatedTestData1() {
},
],
profileCurrent: 0,
version: 56,
version: 57,
global: {
database: {
prefixWildcardsSupported: false,
Expand Down
1 change: 1 addition & 0 deletions types/ext/dictionary-data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type Index = {
version?: IndexVersion;
title: string;
revision: string;
minimumYomitanVersion?: string;
sequenced?: boolean;
isUpdatable?: true;
indexUrl?: string;
Expand Down
3 changes: 3 additions & 0 deletions types/ext/dictionary-importer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ export type ImportResult = {

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

export type Summary = {
title: string;
revision: string;
sequenced: boolean;
minimumYomitanVersion?: string;
version: number;
importDate: number;
prefixWildcardsSupported: boolean;
Expand All @@ -67,6 +69,7 @@ export type SummaryDetails = {
prefixWildcardsSupported: boolean;
counts: SummaryCounts;
styles: string;
yomitanVersion: string;
};

export type SummaryCounts = {
Expand Down
1 change: 1 addition & 0 deletions types/ext/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export type ScanningInputOptions = {
scanOnPenRelease: boolean;
preventTouchScrolling: boolean;
preventPenScrolling: boolean;
minimumTouchTime: number;
};

export type ScanningPreventMiddleMouseOptions = {
Expand Down
2 changes: 2 additions & 0 deletions types/ext/text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type InputOptions = {
scanOnPenRelease: boolean;
preventTouchScrolling: boolean;
preventPenScrolling: boolean;
minimumTouchTime: number;
};

export type SentenceParsingOptions = {
Expand All @@ -93,6 +94,7 @@ export type InputConfig = {
scanOnPenRelease: boolean;
preventTouchScrolling: boolean;
preventPenScrolling: boolean;
minimumTouchTime: number;
};

export type InputInfo = {
Expand Down

0 comments on commit 7092f7a

Please sign in to comment.