mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-25 04:36:46 +00:00
Convert app loading message code to TypeScript
This commit is contained in:
@@ -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(
|
||||
|
||||
47
ts/setAppLoadingScreenMessage.ts
Normal file
47
ts/setAppLoadingScreenMessage.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2018-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { LocalizerType } from './types/Util';
|
||||
|
||||
const DISPLAY_THRESHOLD = 3000; // milliseconds
|
||||
const SELECTOR = '.app-loading-screen .message';
|
||||
|
||||
let timeout: null | ReturnType<typeof setTimeout>;
|
||||
let targetString: string;
|
||||
let didTimeout = false;
|
||||
|
||||
const clear = () => {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
};
|
||||
|
||||
export function setAppLoadingScreenMessage(
|
||||
loadingText: undefined | string,
|
||||
i18n: LocalizerType
|
||||
): () => void {
|
||||
const message = document.querySelector<HTMLElement>(SELECTOR);
|
||||
if (!message) {
|
||||
return clear;
|
||||
}
|
||||
|
||||
targetString = loadingText || i18n('optimizingApplication');
|
||||
|
||||
message.innerText = didTimeout ? targetString : i18n('loading');
|
||||
|
||||
if (timeout) {
|
||||
return clear;
|
||||
}
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
didTimeout = true;
|
||||
const innerMessage = document.querySelector<HTMLElement>(SELECTOR);
|
||||
if (!innerMessage) {
|
||||
return;
|
||||
}
|
||||
innerMessage.innerText = targetString;
|
||||
}, DISPLAY_THRESHOLD);
|
||||
|
||||
return clear;
|
||||
}
|
||||
1
ts/window.d.ts
vendored
1
ts/window.d.ts
vendored
@@ -383,7 +383,6 @@ declare global {
|
||||
WhatsNewLink: typeof WhatsNewLink;
|
||||
};
|
||||
OS: typeof OS;
|
||||
Views: WhatIsThis;
|
||||
State: {
|
||||
createStore: typeof createStore;
|
||||
Roots: {
|
||||
|
||||
Reference in New Issue
Block a user