Convert app loading message code to TypeScript

This commit is contained in:
Evan Hahn 2022-06-01 19:57:30 +00:00 committed by GitHub
parent d4bba46b2c
commit 53d4a31311
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 27 deletions

View file

@ -125,9 +125,6 @@ const { UUID } = require('../../ts/types/UUID');
const { Address } = require('../../ts/types/Address');
const { QualifiedAddress } = require('../../ts/types/QualifiedAddress');
// Views
const Initialization = require('./views/initialization');
// Processes / Services
const {
initializeGroupCredentialFetcher,
@ -404,10 +401,6 @@ exports.setup = (options = {}) => {
QualifiedAddress,
};
const Views = {
Initialization,
};
return {
Backbone,
Components,
@ -426,6 +419,5 @@ exports.setup = (options = {}) => {
Stickers,
Types,
Util,
Views,
};
};

View file

@ -39,6 +39,7 @@ import { assert, strictAssert } from './util/assert';
import { normalizeUuid } from './util/normalizeUuid';
import { filter } from './util/iterables';
import { isNotNil } from './util/isNotNil';
import { setAppLoadingScreenMessage } from './setAppLoadingScreenMessage';
import { IdleDetector } from './IdleDetector';
import { expiringMessagesDeletionService } from './services/expiringMessagesDeletion';
import { tapToViewMessagesDeletionService } from './services/tapToViewMessagesDeletionService';
@ -502,7 +503,6 @@ export async function startApp(): Promise<void> {
deleteAttachmentData,
doesAttachmentExist,
} = window.Signal.Migrations;
const { Views } = window.Signal;
log.info('background page reloaded');
log.info('environment:', window.getEnvironment());
@ -546,7 +546,10 @@ export async function startApp(): Promise<void> {
return accountManager;
};
const cancelInitializationMessage = Views.Initialization.setMessage();
const cancelInitializationMessage = setAppLoadingScreenMessage(
undefined,
window.i18n
);
const version = await window.Signal.Data.getItemById('version');
if (!version) {
@ -792,7 +795,10 @@ export async function startApp(): Promise<void> {
}
}
Views.Initialization.setMessage(window.i18n('optimizingApplication'));
setAppLoadingScreenMessage(
window.i18n('optimizingApplication'),
window.i18n
);
if (newVersion) {
// We've received reports that this update can take longer than two minutes, so we
@ -816,7 +822,7 @@ export async function startApp(): Promise<void> {
log.error('SQL failed to initialize', err && err.stack ? err.stack : err);
}
Views.Initialization.setMessage(window.i18n('loading'));
setAppLoadingScreenMessage(window.i18n('loading'), window.i18n);
let isMigrationWithIndexComplete = false;
log.info(

View file

@ -1,15 +1,13 @@
// Copyright 2018-2020 Signal Messenger, LLC
// Copyright 2018-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* eslint-env browser */
/* global i18n: false */
import type { LocalizerType } from './types/Util';
const DISPLAY_THRESHOLD = 3000; // milliseconds
const SELECTOR = '.app-loading-screen .message';
let timeout;
let targetString;
let timeout: null | ReturnType<typeof setTimeout>;
let targetString: string;
let didTimeout = false;
const clear = () => {
@ -19,8 +17,11 @@ const clear = () => {
}
};
const setMessage = loadingText => {
const message = document.querySelector(SELECTOR);
export function setAppLoadingScreenMessage(
loadingText: undefined | string,
i18n: LocalizerType
): () => void {
const message = document.querySelector<HTMLElement>(SELECTOR);
if (!message) {
return clear;
}
@ -35,7 +36,7 @@ const setMessage = loadingText => {
timeout = setTimeout(() => {
didTimeout = true;
const innerMessage = document.querySelector(SELECTOR);
const innerMessage = document.querySelector<HTMLElement>(SELECTOR);
if (!innerMessage) {
return;
}
@ -43,8 +44,4 @@ const setMessage = loadingText => {
}, DISPLAY_THRESHOLD);
return clear;
};
module.exports = {
setMessage,
};
}

1
ts/window.d.ts vendored
View file

@ -383,7 +383,6 @@ declare global {
WhatsNewLink: typeof WhatsNewLink;
};
OS: typeof OS;
Views: WhatIsThis;
State: {
createStore: typeof createStore;
Roots: {