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

View file

@ -39,6 +39,7 @@ import { assert, strictAssert } from './util/assert';
import { normalizeUuid } from './util/normalizeUuid'; import { normalizeUuid } from './util/normalizeUuid';
import { filter } from './util/iterables'; import { filter } from './util/iterables';
import { isNotNil } from './util/isNotNil'; import { isNotNil } from './util/isNotNil';
import { setAppLoadingScreenMessage } from './setAppLoadingScreenMessage';
import { IdleDetector } from './IdleDetector'; import { IdleDetector } from './IdleDetector';
import { expiringMessagesDeletionService } from './services/expiringMessagesDeletion'; import { expiringMessagesDeletionService } from './services/expiringMessagesDeletion';
import { tapToViewMessagesDeletionService } from './services/tapToViewMessagesDeletionService'; import { tapToViewMessagesDeletionService } from './services/tapToViewMessagesDeletionService';
@ -502,7 +503,6 @@ export async function startApp(): Promise<void> {
deleteAttachmentData, deleteAttachmentData,
doesAttachmentExist, doesAttachmentExist,
} = window.Signal.Migrations; } = window.Signal.Migrations;
const { Views } = window.Signal;
log.info('background page reloaded'); log.info('background page reloaded');
log.info('environment:', window.getEnvironment()); log.info('environment:', window.getEnvironment());
@ -546,7 +546,10 @@ export async function startApp(): Promise<void> {
return accountManager; return accountManager;
}; };
const cancelInitializationMessage = Views.Initialization.setMessage(); const cancelInitializationMessage = setAppLoadingScreenMessage(
undefined,
window.i18n
);
const version = await window.Signal.Data.getItemById('version'); const version = await window.Signal.Data.getItemById('version');
if (!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) { if (newVersion) {
// We've received reports that this update can take longer than two minutes, so we // 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); 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; let isMigrationWithIndexComplete = false;
log.info( 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 // SPDX-License-Identifier: AGPL-3.0-only
/* eslint-env browser */ import type { LocalizerType } from './types/Util';
/* global i18n: false */
const DISPLAY_THRESHOLD = 3000; // milliseconds const DISPLAY_THRESHOLD = 3000; // milliseconds
const SELECTOR = '.app-loading-screen .message'; const SELECTOR = '.app-loading-screen .message';
let timeout; let timeout: null | ReturnType<typeof setTimeout>;
let targetString; let targetString: string;
let didTimeout = false; let didTimeout = false;
const clear = () => { const clear = () => {
@ -19,8 +17,11 @@ const clear = () => {
} }
}; };
const setMessage = loadingText => { export function setAppLoadingScreenMessage(
const message = document.querySelector(SELECTOR); loadingText: undefined | string,
i18n: LocalizerType
): () => void {
const message = document.querySelector<HTMLElement>(SELECTOR);
if (!message) { if (!message) {
return clear; return clear;
} }
@ -35,7 +36,7 @@ const setMessage = loadingText => {
timeout = setTimeout(() => { timeout = setTimeout(() => {
didTimeout = true; didTimeout = true;
const innerMessage = document.querySelector(SELECTOR); const innerMessage = document.querySelector<HTMLElement>(SELECTOR);
if (!innerMessage) { if (!innerMessage) {
return; return;
} }
@ -43,8 +44,4 @@ const setMessage = loadingText => {
}, DISPLAY_THRESHOLD); }, DISPLAY_THRESHOLD);
return clear; return clear;
}; }
module.exports = {
setMessage,
};

1
ts/window.d.ts vendored
View file

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