1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #18313 from Snuffleupagus/l10n-destroy

Try to shutdown Fluent "more" when closing the viewer during testing
This commit is contained in:
Tim van der Meij 2024-06-22 19:45:24 +02:00 committed by GitHub
commit c18a987f4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 4 deletions

View file

@ -2111,16 +2111,15 @@ const PDFViewerApplication = {
* @ignore
*/
async testingClose() {
this.l10n?.pause();
this.findBar?.close();
this.unbindEvents();
this.unbindWindowEvents();
this._globalAbortController?.abort();
this._globalAbortController = null;
await this.close();
this.findBar?.close();
await Promise.all([this.l10n?.destroy(), this.close()]);
},
_accumulateTicks(ticks, prop) {

View file

@ -23,6 +23,8 @@
class L10n {
#dir;
#elements = new Set();
#lang;
#l10n;
@ -69,6 +71,7 @@ class L10n {
/** @inheritdoc */
async translate(element) {
this.#elements.add(element);
try {
this.#l10n.connectRoot(element);
await this.#l10n.translateRoots();
@ -77,6 +80,22 @@ class L10n {
}
}
/** @inheritdoc */
async destroy() {
for (const element of this.#elements) {
this.#l10n.disconnectRoot(element);
}
this.#elements.clear();
this.#l10n.pauseObserving();
// Since `disconnectRoot`/`pauseObserving` can still trigger asynchronous
// operations, without any way to actually cancel them, attempt to
// workaround timing issues when closing the integration-tests.
await new Promise(resolve => {
window.requestAnimationFrame(resolve);
});
}
/** @inheritdoc */
pause() {
this.#l10n.pauseObserving();