From 53d4a31311f996cfe55293eb2614b3ed7c16e63a Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Wed, 1 Jun 2022 19:57:30 +0000 Subject: [PATCH] Convert app loading message code to TypeScript --- js/modules/signal.js | 8 ------ ts/background.ts | 14 ++++++++--- .../setAppLoadingScreenMessage.ts | 25 ++++++++----------- ts/window.d.ts | 1 - 4 files changed, 21 insertions(+), 27 deletions(-) rename js/modules/views/initialization.js => ts/setAppLoadingScreenMessage.ts (60%) diff --git a/js/modules/signal.js b/js/modules/signal.js index b2e02900b..4d679abec 100644 --- a/js/modules/signal.js +++ b/js/modules/signal.js @@ -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, }; }; diff --git a/ts/background.ts b/ts/background.ts index 13b603ebc..87892f2b6 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -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 { 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 { 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 { } } - 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 { 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( diff --git a/js/modules/views/initialization.js b/ts/setAppLoadingScreenMessage.ts similarity index 60% rename from js/modules/views/initialization.js rename to ts/setAppLoadingScreenMessage.ts index e46d882bb..36aede445 100644 --- a/js/modules/views/initialization.js +++ b/ts/setAppLoadingScreenMessage.ts @@ -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; +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(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(SELECTOR); if (!innerMessage) { return; } @@ -43,8 +44,4 @@ const setMessage = loadingText => { }, DISPLAY_THRESHOLD); return clear; -}; - -module.exports = { - setMessage, -}; +} diff --git a/ts/window.d.ts b/ts/window.d.ts index e913c8ee1..5236e57d1 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -383,7 +383,6 @@ declare global { WhatsNewLink: typeof WhatsNewLink; }; OS: typeof OS; - Views: WhatIsThis; State: { createStore: typeof createStore; Roots: {