Faster WebSocket reconnects

This commit is contained in:
Fedor Indutny 2021-06-09 15:28:54 -07:00 committed by GitHub
parent 3cac4a19e1
commit 17e6ec468e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 940 additions and 677 deletions

26
ts/main/powerChannel.ts Normal file
View file

@ -0,0 +1,26 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { powerMonitor } from 'electron';
export type InitializeOptions = {
send(event: string): void;
};
export class PowerChannel {
private static isInitialized = false;
static initialize({ send }: InitializeOptions): void {
if (PowerChannel.isInitialized) {
throw new Error('PowerChannel already initialized');
}
PowerChannel.isInitialized = true;
powerMonitor.on('suspend', () => {
send('power-channel:suspend');
});
powerMonitor.on('resume', () => {
send('power-channel:resume');
});
}
}