@@ -249,6 +249,7 @@ const chunks: {
249249 > ;
250250} = { } ;
251251let monitors = 0 ;
252+ let isMonitored = false ;
252253
253254const getId = ( sender : chrome . runtime . MessageSender , name ?: string ) =>
254255 sender . tab ? sender . tab . id ! : name || sender . id ! ;
@@ -262,12 +263,7 @@ type MonitorAction<S, A extends Action<string>> =
262263// Chrome message limit is 64 MB, but we're using 32 MB to include other object's parts
263264const maxChromeMsgSize = 32 * 1024 * 1024 ;
264265
265- // TODO Clean up args
266- function toMonitors < S , A extends Action < string > > (
267- action : MonitorAction < S , A > ,
268- tabId ?: string | number ,
269- verbose ?: boolean ,
270- ) {
266+ function toMonitors < S , A extends Action < string > > ( action : MonitorAction < S , A > ) {
271267 for ( const port of [
272268 ...Object . values ( connections . monitor ) ,
273269 ...Object . values ( connections . panel ) ,
@@ -417,6 +413,7 @@ function toAllTabs(msg: TabMessage) {
417413}
418414
419415function monitorInstances ( shouldMonitor : boolean , id ?: string ) {
416+ if ( ! id && isMonitored === shouldMonitor ) return ;
420417 const action = {
421418 type : shouldMonitor ? ( 'START' as const ) : ( 'STOP' as const ) ,
422419 } ;
@@ -425,6 +422,7 @@ function monitorInstances(shouldMonitor: boolean, id?: string) {
425422 } else {
426423 toAllTabs ( action ) ;
427424 }
425+ isMonitored = shouldMonitor ;
428426}
429427
430428function getReducerError ( ) {
@@ -499,7 +497,7 @@ function messaging<S, A extends Action<string>>(
499497 }
500498 if ( request . type === 'ERROR' ) {
501499 if ( request . payload ) {
502- toMonitors ( request , tabId ) ;
500+ toMonitors ( request ) ;
503501 return ;
504502 }
505503 if ( ! request . message ) return ;
@@ -541,11 +539,7 @@ function messaging<S, A extends Action<string>>(
541539 }
542540 store . dispatch ( action ) ;
543541
544- if ( request . type === 'EXPORT' ) {
545- toMonitors ( action , tabId , true ) ;
546- } else {
547- toMonitors ( action , tabId ) ;
548- }
542+ toMonitors ( action ) ;
549543}
550544
551545function disconnect (
@@ -587,7 +581,7 @@ function onConnect<S, A extends Action<string>>(port: chrome.runtime.Port) {
587581 chrome . action . enable ( id ) ;
588582 chrome . action . setIcon ( { tabId : id , path : 'img/logo/38x38.png' } ) ;
589583 }
590- port . postMessage ( { type : 'START' } ) ;
584+ if ( isMonitored ) port . postMessage ( { type : 'START' } ) ;
591585
592586 const state = store . getState ( ) ;
593587 if ( state . instances . persisted ) {
0 commit comments