background/connect: Prevent concurrent calls to connect
This commit is contained in:
parent
1d1fccd96f
commit
cd599f92c8
1 changed files with 322 additions and 307 deletions
|
@ -1716,7 +1716,15 @@ type WhatIsThis = typeof window.WhatIsThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
let connectCount = 0;
|
let connectCount = 0;
|
||||||
|
let connecting = false;
|
||||||
async function connect(firstRun?: boolean) {
|
async function connect(firstRun?: boolean) {
|
||||||
|
if (connecting) {
|
||||||
|
window.log.warn('connect already running', { connectCount });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
connecting = true;
|
||||||
|
|
||||||
window.log.info('connect', { firstRun, connectCount });
|
window.log.info('connect', { firstRun, connectCount });
|
||||||
|
|
||||||
if (reconnectTimer) {
|
if (reconnectTimer) {
|
||||||
|
@ -1764,8 +1772,8 @@ type WhatIsThis = typeof window.WhatIsThis;
|
||||||
|
|
||||||
if (connectCount === 0) {
|
if (connectCount === 0) {
|
||||||
try {
|
try {
|
||||||
// Force a re-fetch before we process our queue. We may want to turn on something
|
// Force a re-fetch before we process our queue. We may want to turn on
|
||||||
// which changes how we process incoming messages!
|
// something which changes how we process incoming messages!
|
||||||
await window.Signal.RemoteConfig.refreshRemoteConfig();
|
await window.Signal.RemoteConfig.refreshRemoteConfig();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
window.log.error(
|
window.log.error(
|
||||||
|
@ -1840,14 +1848,15 @@ type WhatIsThis = typeof window.WhatIsThis;
|
||||||
|
|
||||||
preMessageReceiverStatus = null;
|
preMessageReceiverStatus = null;
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-inner-declarations
|
||||||
function addQueuedEventListener(name: WhatIsThis, handler: WhatIsThis) {
|
function addQueuedEventListener(name: WhatIsThis, handler: WhatIsThis) {
|
||||||
messageReceiver.addEventListener(name, (...args: Array<WhatIsThis>) =>
|
messageReceiver.addEventListener(name, (...args: Array<WhatIsThis>) =>
|
||||||
eventHandlerQueue.add(async () => {
|
eventHandlerQueue.add(async () => {
|
||||||
try {
|
try {
|
||||||
await handler(...args);
|
await handler(...args);
|
||||||
} finally {
|
} finally {
|
||||||
// message/sent: Message.handleDataMessage has its own queue and will trigger
|
// message/sent: Message.handleDataMessage has its own queue and will
|
||||||
// this event itself when complete.
|
// trigger this event itself when complete.
|
||||||
// error: Error processing (below) also has its own queue and self-trigger.
|
// error: Error processing (below) also has its own queue and self-trigger.
|
||||||
if (name !== 'message' && name !== 'sent' && name !== 'error') {
|
if (name !== 'message' && name !== 'sent' && name !== 'error') {
|
||||||
window.Whisper.events.trigger('incrementProgress');
|
window.Whisper.events.trigger('incrementProgress');
|
||||||
|
@ -1872,7 +1881,10 @@ type WhatIsThis = typeof window.WhatIsThis;
|
||||||
addQueuedEventListener('typing', onTyping);
|
addQueuedEventListener('typing', onTyping);
|
||||||
addQueuedEventListener('sticker-pack', onStickerPack);
|
addQueuedEventListener('sticker-pack', onStickerPack);
|
||||||
addQueuedEventListener('viewSync', onViewSync);
|
addQueuedEventListener('viewSync', onViewSync);
|
||||||
addQueuedEventListener('messageRequestResponse', onMessageRequestResponse);
|
addQueuedEventListener(
|
||||||
|
'messageRequestResponse',
|
||||||
|
onMessageRequestResponse
|
||||||
|
);
|
||||||
addQueuedEventListener('profileKeyUpdate', onProfileKeyUpdate);
|
addQueuedEventListener('profileKeyUpdate', onProfileKeyUpdate);
|
||||||
addQueuedEventListener('fetchLatest', onFetchLatestSync);
|
addQueuedEventListener('fetchLatest', onFetchLatestSync);
|
||||||
addQueuedEventListener('keys', onKeysSync);
|
addQueuedEventListener('keys', onKeysSync);
|
||||||
|
@ -2043,6 +2055,9 @@ type WhatIsThis = typeof window.WhatIsThis;
|
||||||
window.storage.onready(async () => {
|
window.storage.onready(async () => {
|
||||||
idleDetector.start();
|
idleDetector.start();
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
connecting = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onChangeTheme() {
|
function onChangeTheme() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue