mirror of
https://github.com/fregante/GhostText.git
synced 2024-10-26 19:53:05 +03:00
Avoid auto-disconnect in Firefox (#324)
This commit is contained in:
parent
2bf8f12880
commit
c5658d03e4
@ -97,7 +97,6 @@ chrome.runtime.onConnect.addListener(handlePortListenerErrors(async port => {
|
||||
|
||||
console.log('will open socket');
|
||||
const socket = new WebSocket('ws://localhost:' + WebSocketPort);
|
||||
let interval; // eslint-disable-line prefer-const -- Ur rong
|
||||
await Promise.race([
|
||||
oneEvent(socket, 'open'),
|
||||
oneEvent(socket, 'error'),
|
||||
@ -105,7 +104,6 @@ chrome.runtime.onConnect.addListener(handlePortListenerErrors(async port => {
|
||||
|
||||
const onSocketClose = () => {
|
||||
port.postMessage({close: true});
|
||||
clearInterval(interval);
|
||||
};
|
||||
|
||||
socket.addEventListener('close', onSocketClose);
|
||||
@ -119,17 +117,18 @@ chrome.runtime.onConnect.addListener(handlePortListenerErrors(async port => {
|
||||
port.onDisconnect.addListener(() => {
|
||||
socket.removeEventListener('close', onSocketClose);
|
||||
socket.close();
|
||||
clearInterval(interval);
|
||||
});
|
||||
port.postMessage({ready: true});
|
||||
|
||||
interval = setInterval(() => {
|
||||
// Keep-alive for MV3 https://github.com/fregante/GhostText/issues/317
|
||||
port.postMessage({ping: true});
|
||||
console.log('ping');
|
||||
}, 5000);
|
||||
}));
|
||||
|
||||
// https://github.com/fregante/GhostText/pull/324
|
||||
chrome.runtime.onMessage.addListener(() => {
|
||||
// What is my purpose?
|
||||
// You pass the butter.
|
||||
// Oh my god.
|
||||
// Yeah, welcome to the club, pal.
|
||||
});
|
||||
|
||||
function handleMessages({code, count}, {tab}) {
|
||||
if (code === 'connection-count') {
|
||||
let text = '';
|
||||
|
@ -349,3 +349,10 @@ window.startGT = startGT;
|
||||
window.stopGT = stopGT;
|
||||
|
||||
setTimeout(startGT, 100);
|
||||
|
||||
// https://github.com/fregante/GhostText/pull/324
|
||||
window.gtInterval ??= setInterval(() => {
|
||||
chrome.runtime.sendMessage({
|
||||
code: 'Keep alive',
|
||||
});
|
||||
}, 5000);
|
||||
|
Loading…
Reference in New Issue
Block a user