From f4709037cb74c7296fd5c0688c742055a8ca3640 Mon Sep 17 00:00:00 2001 From: Federico Date: Sat, 10 Aug 2024 17:18:58 +0700 Subject: [PATCH 1/2] Keep event page alive --- source/background.js | 17 ++++++++--------- source/ghost-text.js | 7 +++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/source/background.js b/source/background.js index f524c77..52d6d0a 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/issues/317 +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..575ef39 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/issues/317 +window.gtInterval ??= setInterval(() => { + chrome.runtime.sendMessage({ + code: 'Keep alive', + }); +}, 5000); From 65b8bbd39918bb25767bfcac70a07587b8d74c95 Mon Sep 17 00:00:00 2001 From: Federico Date: Sat, 10 Aug 2024 17:26:58 +0700 Subject: [PATCH 2/2] Update explainer URL --- source/background.js | 2 +- source/ghost-text.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/background.js b/source/background.js index 52d6d0a..c59c6c1 100644 --- a/source/background.js +++ b/source/background.js @@ -121,7 +121,7 @@ chrome.runtime.onConnect.addListener(handlePortListenerErrors(async port => { port.postMessage({ready: true}); })); -// https://github.com/fregante/GhostText/issues/317 +// https://github.com/fregante/GhostText/pull/324 chrome.runtime.onMessage.addListener(() => { // What is my purpose? // You pass the butter. diff --git a/source/ghost-text.js b/source/ghost-text.js index 575ef39..e377692 100644 --- a/source/ghost-text.js +++ b/source/ghost-text.js @@ -350,7 +350,7 @@ window.stopGT = stopGT; setTimeout(startGT, 100); -// https://github.com/fregante/GhostText/issues/317 +// https://github.com/fregante/GhostText/pull/324 window.gtInterval ??= setInterval(() => { chrome.runtime.sendMessage({ code: 'Keep alive',