diff --git a/source/background.js b/source/background.js index f524c77..c59c6c1 100644 --- a/source/background.js +++ b/source/background.js @@ -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 = ''; diff --git a/source/ghost-text.js b/source/ghost-text.js index 6b9e743..e377692 100644 --- a/source/ghost-text.js +++ b/source/ghost-text.js @@ -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);