Skip to content

Commit

Permalink
Fix: only send data to extension if DevTools are open (#1735)
Browse files Browse the repository at this point in the history
* Fix: only send data to extension if DevTools are open

* Create odd-apples-argue.md
  • Loading branch information
Methuselah96 authored Aug 31, 2024
1 parent b3e8f20 commit abd03a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-apples-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'remotedev-redux-devtools-extension': patch
---

Fix: only send data to extension if DevTools are open
20 changes: 7 additions & 13 deletions extension/src/background/store/apiMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ const chunks: {
>;
} = {};
let monitors = 0;
let isMonitored = false;

const getId = (sender: chrome.runtime.MessageSender, name?: string) =>
sender.tab ? sender.tab.id! : name || sender.id!;
Expand All @@ -262,12 +263,7 @@ type MonitorAction<S, A extends Action<string>> =
// Chrome message limit is 64 MB, but we're using 32 MB to include other object's parts
const maxChromeMsgSize = 32 * 1024 * 1024;

// TODO Clean up args
function toMonitors<S, A extends Action<string>>(
action: MonitorAction<S, A>,
tabId?: string | number,
verbose?: boolean,
) {
function toMonitors<S, A extends Action<string>>(action: MonitorAction<S, A>) {
for (const port of [
...Object.values(connections.monitor),
...Object.values(connections.panel),
Expand Down Expand Up @@ -417,6 +413,7 @@ function toAllTabs(msg: TabMessage) {
}

function monitorInstances(shouldMonitor: boolean, id?: string) {
if (!id && isMonitored === shouldMonitor) return;
const action = {
type: shouldMonitor ? ('START' as const) : ('STOP' as const),
};
Expand All @@ -425,6 +422,7 @@ function monitorInstances(shouldMonitor: boolean, id?: string) {
} else {
toAllTabs(action);
}
isMonitored = shouldMonitor;
}

function getReducerError() {
Expand Down Expand Up @@ -499,7 +497,7 @@ function messaging<S, A extends Action<string>>(
}
if (request.type === 'ERROR') {
if (request.payload) {
toMonitors(request, tabId);
toMonitors(request);
return;
}
if (!request.message) return;
Expand Down Expand Up @@ -541,11 +539,7 @@ function messaging<S, A extends Action<string>>(
}
store.dispatch(action);

if (request.type === 'EXPORT') {
toMonitors(action, tabId, true);
} else {
toMonitors(action, tabId);
}
toMonitors(action);
}

function disconnect(
Expand Down Expand Up @@ -587,7 +581,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
chrome.action.enable(id);
chrome.action.setIcon({ tabId: id, path: 'img/logo/38x38.png' });
}
port.postMessage({ type: 'START' });
if (isMonitored) port.postMessage({ type: 'START' });

const state = store.getState();
if (state.instances.persisted) {
Expand Down

0 comments on commit abd03a7

Please sign in to comment.