Keep connection from devpanel to background alive

This commit is contained in:
Nathan Bierema 2024-08-10 15:50:14 -04:00
parent b164f492df
commit 8a332528a9
2 changed files with 8 additions and 1 deletions

View File

@ -644,7 +644,8 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
connections.panel[id] = port; connections.panel[id] = port;
monitorInstances(true, port.name); monitorInstances(true, port.name);
monitors++; monitors++;
listener = (msg: BackgroundAction) => { listener = (msg: BackgroundAction | 'heartbeat') => {
if (msg === 'heartbeat') return;
store.dispatch(msg); store.dispatch(msg);
}; };
port.onMessage.addListener(listener); port.onMessage.addListener(listener);

View File

@ -103,9 +103,15 @@ let splitMessage: SplitUpdateStateRequest<unknown, Action<string>>;
function init(id: number) { function init(id: number) {
renderNA(); renderNA();
bgConnection = chrome.runtime.connect({ bgConnection = chrome.runtime.connect({
name: id ? id.toString() : undefined, name: id ? id.toString() : undefined,
}); });
setInterval(() => {
bgConnection.postMessage('heartbeat');
}, 15000);
bgConnection.onMessage.addListener( bgConnection.onMessage.addListener(
<S, A extends Action<string>>( <S, A extends Action<string>>(
message: PanelMessageWithSplitAction<S, A>, message: PanelMessageWithSplitAction<S, A>,