2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2018-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-03-22 15:52:52 +00:00
|
|
|
/* eslint-env browser */
|
|
|
|
|
|
|
|
/* global i18n: false */
|
|
|
|
|
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
|
|
|
|
2018-08-02 01:34:50 +00:00
|
|
|
let timeout;
|
|
|
|
let targetString;
|
|
|
|
let didTimeout = false;
|
|
|
|
|
|
|
|
const clear = () => {
|
|
|
|
if (timeout) {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const setMessage = loadingText => {
|
|
|
|
const message = document.querySelector(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;
|
|
|
|
const innerMessage = document.querySelector(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;
|
2018-03-22 15:52:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
setMessage,
|
|
|
|
};
|