2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-06-01 19:57:30 +00:00
|
|
|
import type { LocalizerType } from './types/Util';
|
2018-03-22 15:52:52 +00:00
|
|
|
|
2018-08-02 01:34:50 +00:00
|
|
|
const DISPLAY_THRESHOLD = 3000; // milliseconds
|
|
|
|
const SELECTOR = '.app-loading-screen .message';
|
2018-03-22 15:52:52 +00:00
|
|
|
|
2022-06-01 19:57:30 +00:00
|
|
|
let timeout: null | ReturnType<typeof setTimeout>;
|
|
|
|
let targetString: string;
|
2018-08-02 01:34:50 +00:00
|
|
|
let didTimeout = false;
|
|
|
|
|
|
|
|
const clear = () => {
|
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-01 19:57:30 +00:00
|
|
|
export function setAppLoadingScreenMessage(
|
|
|
|
loadingText: undefined | string,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): () => void {
|
|
|
|
const message = document.querySelector<HTMLElement>(SELECTOR);
|
2018-03-22 15:52:52 +00:00
|
|
|
if (!message) {
|
2018-08-02 01:34:50 +00:00
|
|
|
return clear;
|
|
|
|
}
|
|
|
|
|
|
|
|
targetString = loadingText || i18n('optimizingApplication');
|
|
|
|
|
|
|
|
message.innerText = didTimeout ? targetString : i18n('loading');
|
|
|
|
|
|
|
|
if (timeout) {
|
|
|
|
return clear;
|
2018-03-22 15:52:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 01:34:50 +00:00
|
|
|
timeout = setTimeout(() => {
|
|
|
|
didTimeout = true;
|
2022-06-01 19:57:30 +00:00
|
|
|
const innerMessage = document.querySelector<HTMLElement>(SELECTOR);
|
2018-03-22 15:52:52 +00:00
|
|
|
if (!innerMessage) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-02 01:34:50 +00:00
|
|
|
innerMessage.innerText = targetString;
|
|
|
|
}, DISPLAY_THRESHOLD);
|
2018-03-22 15:52:52 +00:00
|
|
|
|
2018-08-02 01:34:50 +00:00
|
|
|
return clear;
|
2022-06-01 19:57:30 +00:00
|
|
|
}
|