Skip to content

Commit

Permalink
Google docs fixes (#455)
Browse files Browse the repository at this point in the history
* Simplify GoogleDocsUtil deferred import

* Remove loadExtensionScripts
  • Loading branch information
toasted-nutbread authored Dec 27, 2023
1 parent ff412d2 commit 7cc2096
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 40 deletions.
16 changes: 2 additions & 14 deletions ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {GoogleDocsUtil} from '../accessibility/google-docs-util.js';
import {EventListenerCollection, invokeMessageHandler, log, promiseAnimationFrame} from '../core.js';
import {DocumentUtil} from '../dom/document-util.js';
import {TextSourceElement} from '../dom/text-source-element.js';
Expand Down Expand Up @@ -964,27 +963,16 @@ export class Frontend {
_prepareSiteSpecific() {
switch (location.hostname.toLowerCase()) {
case 'docs.google.com':
this._prepareGoogleDocsWrapper();
this._prepareGoogleDocs();
break;
}
}

/**
* @returns {Promise<void>}
*/
async _prepareGoogleDocsWrapper() {
if (typeof GoogleDocsUtil !== 'undefined') { return; }
await yomitan.api.loadExtensionScripts([
'/js/accessibility/google-docs-util.js'
]);
this._prepareGoogleDocs();
}

/**
* @returns {Promise<void>}
*/
async _prepareGoogleDocs() {
if (typeof GoogleDocsUtil === 'undefined') { return; }
const {GoogleDocsUtil} = await import('../accessibility/google-docs-util.js');
DocumentUtil.registerGetRangeFromPointHandler(GoogleDocsUtil.getRangeFromPoint.bind(GoogleDocsUtil));
}
}
12 changes: 0 additions & 12 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ export class Backend {
['textHasJapaneseCharacters', this._onApiTextHasJapaneseCharacters.bind(this)],
['getTermFrequencies', this._onApiGetTermFrequencies.bind(this)],
['findAnkiNotes', this._onApiFindAnkiNotes.bind(this)],
['loadExtensionScripts', this._onApiLoadExtensionScripts.bind(this)],
['openCrossFramePort', this._onApiOpenCrossFramePort.bind(this)]
]);
/* eslint-enable no-multi-spaces */
Expand Down Expand Up @@ -846,17 +845,6 @@ export class Backend {
return await this._anki.findNotes(query);
}

/** @type {import('api').ApiHandler<'loadExtensionScripts'>} */
async _onApiLoadExtensionScripts({files}, sender) {
if (!sender || !sender.tab) { throw new Error('Invalid sender'); }
const tabId = sender.tab.id;
if (typeof tabId !== 'number') { throw new Error('Sender has invalid tab ID'); }
const {frameId} = sender;
for (const file of files) {
await this._scriptManager.injectScript(file, tabId, frameId, false);
}
}

/** @type {import('api').ApiHandler<'openCrossFramePort'>} */
_onApiOpenCrossFramePort({targetTabId, targetFrameId}, sender) {
const sourceTabId = (sender && sender.tab ? sender.tab.id : null);
Expand Down
8 changes: 0 additions & 8 deletions ext/js/comm/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,6 @@ export class API {
return this._invoke('findAnkiNotes', {query});
}

/**
* @param {import('api').ApiParam<'loadExtensionScripts', 'files'>} files
* @returns {Promise<import('api').ApiReturn<'loadExtensionScripts'>>}
*/
loadExtensionScripts(files) {
return this._invoke('loadExtensionScripts', {files});
}

/**
* @param {import('api').ApiParam<'openCrossFramePort', 'targetTabId'>} targetTabId
* @param {import('api').ApiParam<'openCrossFramePort', 'targetFrameId'>} targetFrameId
Expand Down
6 changes: 0 additions & 6 deletions types/ext/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,6 @@ type ApiSurface = {
};
return: Anki.NoteId[];
};
loadExtensionScripts: {
params: {
files: string[];
};
return: void;
};
openCrossFramePort: {
params: {
targetTabId: number;
Expand Down

0 comments on commit 7cc2096

Please sign in to comment.