Skip to content

Commit

Permalink
Merge remote-tracking branch 'yomitan/master' into search-resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Dec 28, 2023
2 parents 668bc9a + 8d5d215 commit c2dffb1
Show file tree
Hide file tree
Showing 39 changed files with 2,107 additions and 724 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
"ext/js/general/text-source-map.js",
"ext/js/language/deinflector.js",
"ext/js/dictionary/dictionary-database.js",
"ext/js/language/sandbox/dictionary-data-util.js",
"ext/js/dictionary/dictionary-data-util.js",
"ext/js/language/sandbox/japanese-util.js",
"ext/js/language/translator.js",
"ext/js/media/audio-downloader.js",
Expand Down
2 changes: 1 addition & 1 deletion dev/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"../ext/js/language/deinflector.js",
"../ext/js/dictionary/dictionary-importer.js",
"../ext/js/dictionary/dictionary-database.js",
"../ext/js/language/sandbox/dictionary-data-util.js",
"../ext/js/dictionary/dictionary-data-util.js",
"../ext/js/language/sandbox/japanese-util.js",
"../ext/js/language/translator.js",
"../ext/js/media/media-util.js",
Expand Down
56 changes: 52 additions & 4 deletions ext/data/schemas/dictionary-term-meta-bank-v3-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
},
{
"type": "string",
"enum": ["freq", "pitch"],
"description": "Type of data. \"freq\" corresponds to frequency information; \"pitch\" corresponds to pitch information."
"enum": ["freq", "pitch", "ipa"],
"description": "Type of data. \"freq\" corresponds to frequency information; \"pitch\" corresponds to pitch information. \"ipa\" corresponds to IPA transcription."
},
{
"description": "Data for the term."
Expand All @@ -61,7 +61,7 @@
"description": "Frequency information for the term."
},
{
"type": ["object"],
"type": "object",
"required": [
"reading",
"frequency"
Expand Down Expand Up @@ -89,7 +89,7 @@
{},
{"const": "pitch"},
{
"type": ["object"],
"type": "object",
"description": "Pitch accent information for the term.",
"required": [
"reading",
Expand Down Expand Up @@ -164,6 +164,54 @@
}
}
]
},
{
"minItems": 3,
"maxItems": 3,
"items": [
{},
{"const": "ipa"},
{
"type": ["object"],
"description": "IPA transcription information for the term.",
"required": [
"reading",
"transcriptions"
],
"additionalProperties": false,
"properties": {
"reading": {
"type": "string",
"description": "Reading for the term."
},
"transcriptions": {
"type": "array",
"description": "List of different IPA transcription information for the term and reading combination.",
"items": {
"type": "object",
"required": [
"ipa"
],
"additionalProperties": false,
"properties": {
"ipa": {
"type": "string",
"description": "IPA transcription for the term."
},
"tags": {
"type": "array",
"description": "List of tags for this IPA transcription.",
"items": {
"type": "string",
"description": "Tag for this IPA transcription."
}
}
}
}
}
}
}
]
}
]
}
Expand Down
21 changes: 21 additions & 0 deletions ext/data/templates/default-anki-field-templates.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@
{{/inline}}
{{! End Pitch Accents }}

{{#*inline "phonetic-transcriptions"}}
{{~#if (op ">" definition.phoneticTranscriptions.length 0)~}}
<ul>
{{~#each definition.phoneticTranscriptions~}}
{{~#each phoneticTranscriptions~}}
<li>
{{~set "any" false~}}
{{~#each tags~}}
{{~#if (get "any")}}, {{else}}<i>({{/if~}}
{{name}}
{{~set "any" true~}}
{{~/each~}}
{{~#if (get "any")}})</i> {{/if~}}
{{ipa~}}
</li>
{{~/each~}}
{{~/each~}}
</ul>
{{~/if~}}
{{/inline}}

{{#*inline "clipboard-image"}}
{{~#if (hasMedia "clipboardImage")~}}
<img src="{{getMedia "clipboardImage"}}" />
Expand Down
17 changes: 5 additions & 12 deletions ext/js/accessibility/accessibility-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {isContentScriptRegistered, registerContentScript, unregisterContentScript} from '../background/script-manager.js';
import {log} from '../core.js';

/**
* This class controls the registration of accessibility handlers.
*/
export class AccessibilityController {
/**
* Creates a new instance.
* @param {import('../background/script-manager.js').ScriptManager} scriptManager An instance of the `ScriptManager` class.
*/
constructor(scriptManager) {
/** @type {import('../background/script-manager.js').ScriptManager} */
this._scriptManager = scriptManager;
constructor() {
/** @type {?import('core').TokenObject} */
this._updateGoogleDocsAccessibilityToken = null;
/** @type {?Promise<void>} */
Expand Down Expand Up @@ -90,19 +85,17 @@ export class AccessibilityController {
const id = 'googleDocsAccessibility';
try {
if (forceGoogleDocsHtmlRenderingAny) {
if (await this._scriptManager.isContentScriptRegistered(id)) { return; }
if (await isContentScriptRegistered(id)) { return; }
/** @type {import('script-manager').RegistrationDetails} */
const details = {
allFrames: true,
matchAboutBlank: true,
matches: ['*://docs.google.com/*'],
urlMatches: '^[^:]*://docs\\.google\\.com/[\\w\\W]*$',
runAt: 'document_start',
js: ['js/accessibility/google-docs.js']
};
await this._scriptManager.registerContentScript(id, details);
await registerContentScript(id, details);
} else {
await this._scriptManager.unregisterContentScript(id);
await unregisterContentScript(id);
}
} catch (e) {
log.error(e);
Expand Down
53 changes: 22 additions & 31 deletions ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {EventListenerCollection, invokeMessageHandler, log, promiseAnimationFrame} from '../core.js';
import {EventListenerCollection, log, promiseAnimationFrame} from '../core.js';
import {createApiMap, invokeApiMapHandler} from '../core/api-map.js';
import {DocumentUtil} from '../dom/document-util.js';
import {TextSourceElement} from '../dom/text-source-element.js';
import {TextSourceRange} from '../dom/text-source-range.js';
Expand Down Expand Up @@ -106,12 +107,12 @@ export class Frontend {
this._optionsContextOverride = null;

/* eslint-disable no-multi-spaces */
/** @type {import('core').MessageHandlerMap} */
this._runtimeMessageHandlers = new Map(/** @type {import('core').MessageHandlerMapInit} */ ([
['Frontend.requestReadyBroadcast', this._onMessageRequestFrontendReadyBroadcast.bind(this)],
['Frontend.setAllVisibleOverride', this._onApiSetAllVisibleOverride.bind(this)],
['Frontend.clearAllVisibleOverride', this._onApiClearAllVisibleOverride.bind(this)]
]));
/** @type {import('application').ApiMap} */
this._runtimeApiMap = createApiMap([
['frontendRequestReadyBroadcast', this._onMessageRequestFrontendReadyBroadcast.bind(this)],
['frontendSetAllVisibleOverride', this._onApiSetAllVisibleOverride.bind(this)],
['frontendClearAllVisibleOverride', this._onApiClearAllVisibleOverride.bind(this)]
]);

this._hotkeyHandler.registerActions([
['scanSelectedText', this._onActionScanSelectedText.bind(this)],
Expand Down Expand Up @@ -239,9 +240,7 @@ export class Frontend {

// Message handlers

/**
* @param {import('frontend').FrontendRequestReadyBroadcastParams} params
*/
/** @type {import('application').ApiHandler<'frontendRequestReadyBroadcast'>} */
_onMessageRequestFrontendReadyBroadcast({frameId}) {
this._signalFrontendReady(frameId);
}
Expand Down Expand Up @@ -313,10 +312,7 @@ export class Frontend {
};
}

/**
* @param {{value: boolean, priority: number, awaitFrame: boolean}} params
* @returns {Promise<import('core').TokenString>}
*/
/** @type {import('application').ApiHandler<'frontendSetAllVisibleOverride'>} */
async _onApiSetAllVisibleOverride({value, priority, awaitFrame}) {
const result = await this._popupFactory.setAllVisibleOverride(value, priority);
if (awaitFrame) {
Expand All @@ -325,10 +321,7 @@ export class Frontend {
return result;
}

/**
* @param {{token: import('core').TokenString}} params
* @returns {Promise<boolean>}
*/
/** @type {import('application').ApiHandler<'frontendClearAllVisibleOverride'>} */
async _onApiClearAllVisibleOverride({token}) {
return await this._popupFactory.clearAllVisibleOverride(token);
}
Expand All @@ -342,11 +335,9 @@ export class Frontend {
this._updatePopupPosition();
}

/** @type {import('extension').ChromeRuntimeOnMessageCallback} */
_onRuntimeMessage({action, params}, sender, callback) {
const messageHandler = this._runtimeMessageHandlers.get(action);
if (typeof messageHandler === 'undefined') { return false; }
return invokeMessageHandler(messageHandler, params, callback, sender);
/** @type {import('extension').ChromeRuntimeOnMessageCallback<import('application').ApiMessageAny>} */
_onRuntimeMessage({action, params}, _sender, callback) {
return invokeApiMapHandler(this._runtimeApiMap, action, params, [], callback);
}

/**
Expand Down Expand Up @@ -827,12 +818,12 @@ export class Frontend {
* @param {?number} targetFrameId
*/
_signalFrontendReady(targetFrameId) {
/** @type {import('frontend').FrontendReadyDetails} */
const params = {frameId: this._frameId};
/** @type {import('application').ApiMessageNoFrameId<'frontendReady'>} */
const message = {action: 'frontendReady', params: {frameId: this._frameId}};
if (targetFrameId === null) {
yomitan.api.broadcastTab('frontendReady', params);
yomitan.api.broadcastTab(message);
} else {
yomitan.api.sendMessageToFrame(targetFrameId, 'frontendReady', params);
yomitan.api.sendMessageToFrame(targetFrameId, message);
}
}

Expand All @@ -853,11 +844,11 @@ export class Frontend {
}
chrome.runtime.onMessage.removeListener(onMessage);
};
/** @type {import('extension').ChromeRuntimeOnMessageCallback} */
/** @type {import('extension').ChromeRuntimeOnMessageCallback<import('application').ApiMessageAny>} */
const onMessage = (message, _sender, sendResponse) => {
try {
const {action, params} = message;
if (action === 'frontendReady' && /** @type {import('frontend').FrontendReadyDetails} */ (params).frameId === frameId) {
const {action} = message;
if (action === 'frontendReady' && message.params.frameId === frameId) {
cleanup();
resolve();
sendResponse();
Expand All @@ -876,7 +867,7 @@ export class Frontend {
}

chrome.runtime.onMessage.addListener(onMessage);
yomitan.api.broadcastTab('Frontend.requestReadyBroadcast', {frameId: this._frameId});
yomitan.api.broadcastTab({action: 'frontendRequestReadyBroadcast', params: {frameId: this._frameId}});
});
}

Expand Down
Loading

0 comments on commit c2dffb1

Please sign in to comment.